2015-02-04 00:10:16 +00:00
|
|
|
|
using System;
|
2017-11-24 15:52:11 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using FluentAssertions;
|
2015-02-04 00:10:16 +00:00
|
|
|
|
using Mono.Unix;
|
2015-01-21 19:59:03 +00:00
|
|
|
|
using NUnit.Framework;
|
2014-12-16 07:28:55 +00:00
|
|
|
|
using NzbDrone.Common.Test.DiskTests;
|
2016-08-12 03:30:18 +00:00
|
|
|
|
using NzbDrone.Mono.Disk;
|
2014-01-06 06:20:08 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Mono.Test.DiskProviderTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2014-05-04 14:33:25 +00:00
|
|
|
|
[Platform("Mono")]
|
2014-01-06 06:20:08 +00:00
|
|
|
|
public class DiskProviderFixture : DiskProviderFixtureBase<DiskProvider>
|
|
|
|
|
{
|
|
|
|
|
public DiskProviderFixture()
|
|
|
|
|
{
|
2014-03-14 10:15:30 +00:00
|
|
|
|
MonoOnly();
|
2014-01-06 06:20:08 +00:00
|
|
|
|
}
|
2015-01-21 19:59:03 +00:00
|
|
|
|
|
|
|
|
|
protected override void SetWritePermissions(string path, bool writable)
|
|
|
|
|
{
|
2015-02-04 00:10:16 +00:00
|
|
|
|
if (Environment.UserName == "root")
|
|
|
|
|
{
|
|
|
|
|
Assert.Inconclusive("Need non-root user to test write permissions.");
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 19:59:03 +00:00
|
|
|
|
// Remove Write permissions, we're still owner so we can clean it up, but we'll have to do that explicitly.
|
|
|
|
|
|
|
|
|
|
var entry = UnixFileSystemInfo.GetFileSystemEntry(path);
|
|
|
|
|
|
|
|
|
|
if (writable)
|
|
|
|
|
{
|
|
|
|
|
entry.FileAccessPermissions |= FileAccessPermissions.UserWrite | FileAccessPermissions.GroupWrite | FileAccessPermissions.OtherWrite;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
entry.FileAccessPermissions &= ~(FileAccessPermissions.UserWrite | FileAccessPermissions.GroupWrite | FileAccessPermissions.OtherWrite);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-24 15:52:11 +00:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_move_symlink()
|
|
|
|
|
{
|
|
|
|
|
var tempFolder = GetTempFilePath();
|
|
|
|
|
Directory.CreateDirectory(tempFolder);
|
|
|
|
|
|
|
|
|
|
var file = Path.Combine(tempFolder, "target.txt");
|
|
|
|
|
var source = Path.Combine(tempFolder, "symlink_source.txt");
|
|
|
|
|
var destination = Path.Combine(tempFolder, "symlink_destination.txt");
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(file, "Some content");
|
|
|
|
|
|
|
|
|
|
new UnixSymbolicLinkInfo(source).CreateSymbolicLinkTo(file);
|
|
|
|
|
|
|
|
|
|
Subject.MoveFile(source, destination);
|
|
|
|
|
|
|
|
|
|
File.Exists(file).Should().BeTrue();
|
|
|
|
|
File.Exists(source).Should().BeFalse();
|
|
|
|
|
File.Exists(destination).Should().BeTrue();
|
|
|
|
|
UnixFileSystemInfo.GetFileSystemEntry(destination).IsSymbolicLink.Should().BeTrue();
|
|
|
|
|
|
|
|
|
|
File.ReadAllText(destination).Should().Be("Some content");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_copy_symlink()
|
|
|
|
|
{
|
|
|
|
|
var tempFolder = GetTempFilePath();
|
|
|
|
|
Directory.CreateDirectory(tempFolder);
|
|
|
|
|
|
|
|
|
|
var file = Path.Combine(tempFolder, "target.txt");
|
|
|
|
|
var source = Path.Combine(tempFolder, "symlink_source.txt");
|
|
|
|
|
var destination = Path.Combine(tempFolder, "symlink_destination.txt");
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(file, "Some content");
|
|
|
|
|
|
|
|
|
|
new UnixSymbolicLinkInfo(source).CreateSymbolicLinkTo(file);
|
|
|
|
|
|
|
|
|
|
Subject.CopyFile(source, destination);
|
|
|
|
|
|
|
|
|
|
File.Exists(file).Should().BeTrue();
|
|
|
|
|
File.Exists(source).Should().BeTrue();
|
|
|
|
|
File.Exists(destination).Should().BeTrue();
|
|
|
|
|
UnixFileSystemInfo.GetFileSystemEntry(source).IsSymbolicLink.Should().BeTrue();
|
|
|
|
|
UnixFileSystemInfo.GetFileSystemEntry(destination).IsSymbolicLink.Should().BeTrue();
|
|
|
|
|
|
|
|
|
|
File.ReadAllText(source).Should().Be("Some content");
|
|
|
|
|
File.ReadAllText(destination).Should().Be("Some content");
|
|
|
|
|
}
|
2014-01-06 06:20:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|