mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-17 15:02:34 +02:00
Fixed: Copy linux permission mask when moving to recycle bin
Co-Authored-By: taloth <taloth@users.noreply.github.com>
This commit is contained in:
parent
22062931fe
commit
37d004d78d
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -1046,6 +1046,9 @@ private void WithEmulatedDiskProvider()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetFileInfos(It.IsAny<string>()))
|
||||
.Returns(new List<FileInfo>());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.CopyPermissions(It.IsAny<string>(), It.IsAny<string>(), false));
|
||||
}
|
||||
|
||||
private void WithRealDiskProvider()
|
||||
@ -1105,6 +1108,9 @@ private void WithRealDiskProvider()
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.OpenReadStream(It.IsAny<string>()))
|
||||
.Returns<string>(s => new FileStream(s, FileMode.Open, FileAccess.Read));
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.CopyPermissions(It.IsAny<string>(), It.IsAny<string>(), false));
|
||||
}
|
||||
|
||||
private void WithMockMount(string root)
|
||||
|
@ -32,6 +32,7 @@ public static StringComparison PathStringComparison
|
||||
public abstract long? GetAvailableSpace(string path);
|
||||
public abstract void InheritFolderPermissions(string filename);
|
||||
public abstract void SetPermissions(string path, string mask, string user, string group);
|
||||
public abstract void CopyPermissions(string sourcePath, string targetPath, bool includeOwner);
|
||||
public abstract long? GetTotalSize(string path);
|
||||
|
||||
public DateTime FolderGetCreationTime(string path)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -75,6 +75,8 @@ public TransferMode TransferFolder(string sourcePath, string targetPath, Transfe
|
||||
if (!_diskProvider.FolderExists(targetPath))
|
||||
{
|
||||
_diskProvider.CreateFolder(targetPath);
|
||||
|
||||
_diskProvider.CopyPermissions(sourcePath, targetPath);
|
||||
}
|
||||
|
||||
var result = mode;
|
||||
|
@ -11,6 +11,7 @@ public interface IDiskProvider
|
||||
long? GetAvailableSpace(string path);
|
||||
void InheritFolderPermissions(string filename);
|
||||
void SetPermissions(string path, string mask, string user, string group);
|
||||
void CopyPermissions(string sourcePath, string targetPath, bool includeOwner = false);
|
||||
long? GetTotalSize(string path);
|
||||
DateTime FolderGetCreationTime(string path);
|
||||
DateTime FolderGetLastWrite(string path);
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Mono.Unix;
|
||||
using Mono.Unix.Native;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
@ -127,5 +128,34 @@ public void should_return_special_mount_when_queried(string rootDir)
|
||||
mount.Should().NotBeNull();
|
||||
mount.RootDirectory.Should().Be(rootDir);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_copy_folder_permissions()
|
||||
{
|
||||
var src = GetTempFilePath();
|
||||
var dst = GetTempFilePath();
|
||||
|
||||
Directory.CreateDirectory(src);
|
||||
|
||||
// Toggle one of the permission flags
|
||||
Syscall.stat(src, out var origStat);
|
||||
Syscall.chmod(src, origStat.st_mode ^ FilePermissions.S_IWGRP);
|
||||
|
||||
// Verify test setup
|
||||
Syscall.stat(src, out var srcStat);
|
||||
srcStat.st_mode.Should().NotBe(origStat.st_mode);
|
||||
|
||||
Subject.CreateFolder(dst);
|
||||
|
||||
// Verify test setup
|
||||
Syscall.stat(dst, out var dstStat);
|
||||
dstStat.st_mode.Should().Be(origStat.st_mode);
|
||||
|
||||
Subject.CopyPermissions(src, dst, false);
|
||||
|
||||
// Verify CopyPermissions
|
||||
Syscall.stat(dst, out dstStat);
|
||||
dstStat.st_mode.Should().Be(srcStat.st_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,29 @@ public override void SetPermissions(string path, string mask, string user, strin
|
||||
SetOwner(path, user, group);
|
||||
}
|
||||
|
||||
public override void CopyPermissions(string sourcePath, string targetPath, bool includeOwner)
|
||||
{
|
||||
try
|
||||
{
|
||||
Syscall.stat(sourcePath, out var srcStat);
|
||||
Syscall.stat(targetPath, out var tgtStat);
|
||||
|
||||
if (srcStat.st_mode != tgtStat.st_mode)
|
||||
{
|
||||
Syscall.chmod(targetPath, srcStat.st_mode);
|
||||
}
|
||||
|
||||
if (includeOwner && (srcStat.st_uid != tgtStat.st_uid || srcStat.st_gid != tgtStat.st_gid))
|
||||
{
|
||||
Syscall.chown(targetPath, srcStat.st_uid, srcStat.st_gid);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Debug(ex, "Failed to copy permissions from {0} to {1}", sourcePath, targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
protected override List<IMount> GetAllMounts()
|
||||
{
|
||||
return _procMountProvider.GetMounts()
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using NLog;
|
||||
@ -51,6 +51,10 @@ public override void SetPermissions(string path, string mask, string user, strin
|
||||
{
|
||||
}
|
||||
|
||||
public override void CopyPermissions(string sourcePath, string targetPath, bool includeOwner)
|
||||
{
|
||||
}
|
||||
|
||||
public override long? GetTotalSize(string path)
|
||||
{
|
||||
Ensure.That(path, () => path).IsValidPath();
|
||||
|
Loading…
Reference in New Issue
Block a user