mirror of
https://github.com/lidarr/Lidarr
synced 2025-03-12 23:13:44 +00:00
Fixed: Copy linux permission mask when moving folder to recycle bin folder
fixes #3161
This commit is contained in:
parent
38a590798b
commit
bd71e71386
7 changed files with 69 additions and 1 deletions
|
@ -989,6 +989,9 @@ namespace NzbDrone.Common.Test.DiskTests
|
|||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetFileInfos(It.IsAny<string>(), It.IsAny<SearchOption>()))
|
||||
.Returns(new List<IFileInfo>());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.CopyPermissions(It.IsAny<string>(), It.IsAny<string>(), false));
|
||||
}
|
||||
|
||||
private void WithRealDiskProvider()
|
||||
|
@ -1045,6 +1048,9 @@ namespace NzbDrone.Common.Test.DiskTests
|
|||
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)
|
||||
|
|
|
@ -39,6 +39,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;
|
||||
|
|
|
@ -12,6 +12,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,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()
|
||||
|
|
|
@ -57,7 +57,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…
Add table
Reference in a new issue