Fixed: Copy linux permission mask when moving folder to recycle bin folder
fixes #3161
This commit is contained in:
parent
5a092a83cd
commit
e724e8db60
|
@ -32,6 +32,7 @@ namespace NzbDrone.Common.Disk
|
|||
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)
|
||||
|
|
|
@ -76,6 +76,8 @@ namespace NzbDrone.Common.Disk
|
|||
if (!_diskProvider.FolderExists(targetPath))
|
||||
{
|
||||
_diskProvider.CreateFolder(targetPath);
|
||||
|
||||
_diskProvider.CopyPermissions(sourcePath, targetPath);
|
||||
}
|
||||
|
||||
var result = mode;
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace NzbDrone.Common.Disk
|
|||
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.IO;
|
|||
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 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,29 @@ namespace NzbDrone.Mono.Disk
|
|||
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()
|
||||
|
|
|
@ -46,7 +46,12 @@ namespace NzbDrone.Windows.Disk
|
|||
|
||||
public override void SetPermissions(string path, string mask, string user, string group)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void CopyPermissions(string sourcePath, string targetPath, bool includeOwner)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override long? GetTotalSize(string path)
|
||||
|
|
Loading…
Reference in New Issue