parent
6bb649bac5
commit
6698ca400c
|
@ -418,7 +418,12 @@ namespace NzbDrone.Common.Disk
|
||||||
return new FileStream(path, FileMode.Create);
|
return new FileStream(path, FileMode.Create);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<IMount> GetMounts()
|
public List<IMount> GetMounts()
|
||||||
|
{
|
||||||
|
return GetAllMounts().Where(d => !IsSpecialMount(d)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual List<IMount> GetAllMounts()
|
||||||
{
|
{
|
||||||
return GetDriveInfoMounts().Where(d => d.DriveType == DriveType.Fixed || d.DriveType == DriveType.Network || d.DriveType == DriveType.Removable)
|
return GetDriveInfoMounts().Where(d => d.DriveType == DriveType.Fixed || d.DriveType == DriveType.Network || d.DriveType == DriveType.Removable)
|
||||||
.Select(d => new DriveInfoMount(d))
|
.Select(d => new DriveInfoMount(d))
|
||||||
|
@ -426,11 +431,16 @@ namespace NzbDrone.Common.Disk
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual bool IsSpecialMount(IMount mount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual IMount GetMount(string path)
|
public virtual IMount GetMount(string path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mounts = GetMounts();
|
var mounts = GetAllMounts();
|
||||||
|
|
||||||
return mounts.Where(drive => drive.RootDirectory.PathEquals(path) ||
|
return mounts.Where(drive => drive.RootDirectory.PathEquals(path) ||
|
||||||
drive.RootDirectory.IsParentPath(path))
|
drive.RootDirectory.IsParentPath(path))
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Mono.Unix;
|
using Mono.Unix;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Test.DiskTests;
|
using NzbDrone.Common.Test.DiskTests;
|
||||||
using NzbDrone.Mono.Disk;
|
using NzbDrone.Mono.Disk;
|
||||||
|
|
||||||
|
@ -87,5 +90,37 @@ namespace NzbDrone.Mono.Test.DiskProviderTests
|
||||||
File.ReadAllText(source).Should().Be("Some content");
|
File.ReadAllText(source).Should().Be("Some content");
|
||||||
File.ReadAllText(destination).Should().Be("Some content");
|
File.ReadAllText(destination).Should().Be("Some content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GivenSpecialMount(string rootDir)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IProcMountProvider>()
|
||||||
|
.Setup(v => v.GetMounts())
|
||||||
|
.Returns(new List<IMount> {
|
||||||
|
new ProcMount(DriveType.Fixed, rootDir, rootDir, "myfs", new MountOptions(new Dictionary<string, string>()))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("/snap/blaat")]
|
||||||
|
[TestCase("/var/lib/docker/zfs-storage-mount")]
|
||||||
|
public void should_ignore_special_mounts(string rootDir)
|
||||||
|
{
|
||||||
|
GivenSpecialMount(rootDir);
|
||||||
|
|
||||||
|
var mounts = Subject.GetMounts();
|
||||||
|
|
||||||
|
mounts.Select(d => d.RootDirectory).Should().NotContain(rootDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase("/snap/blaat")]
|
||||||
|
[TestCase("/var/lib/docker/zfs-storage-moun")]
|
||||||
|
public void should_return_special_mount_when_queried(string rootDir)
|
||||||
|
{
|
||||||
|
GivenSpecialMount(rootDir);
|
||||||
|
|
||||||
|
var mount = Subject.GetMount(Path.Combine(rootDir, "dir/somefile.mkv"));
|
||||||
|
|
||||||
|
mount.Should().NotBeNull();
|
||||||
|
mount.RootDirectory.Should().Be(rootDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ namespace NzbDrone.Mono.Disk
|
||||||
SetOwner(path, user, group);
|
SetOwner(path, user, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<IMount> GetMounts()
|
protected override List<IMount> GetAllMounts()
|
||||||
{
|
{
|
||||||
return _procMountProvider.GetMounts()
|
return _procMountProvider.GetMounts()
|
||||||
.Concat(GetDriveInfoMounts()
|
.Concat(GetDriveInfoMounts()
|
||||||
|
@ -87,6 +87,25 @@ namespace NzbDrone.Mono.Disk
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool IsSpecialMount(IMount mount)
|
||||||
|
{
|
||||||
|
var root = mount.RootDirectory;
|
||||||
|
|
||||||
|
if (root.StartsWith("/var/lib/"))
|
||||||
|
{
|
||||||
|
// Could be /var/lib/docker when docker uses zfs. Very unlikely that a useful mount is located in /var/lib.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.StartsWith("/snap/"))
|
||||||
|
{
|
||||||
|
// Mount point for snap packages
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public override long? GetTotalSize(string path)
|
public override long? GetTotalSize(string path)
|
||||||
{
|
{
|
||||||
Ensure.That(path, () => path).IsValidPath();
|
Ensure.That(path, () => path).IsValidPath();
|
||||||
|
|
|
@ -111,18 +111,6 @@ namespace NzbDrone.Mono.Disk
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mount.StartsWith("/var/lib/"))
|
|
||||||
{
|
|
||||||
// Could be /var/lib/docker when docker uses zfs. Very unlikely that a useful mount is located in /var/lib.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mount.StartsWith("/snap/"))
|
|
||||||
{
|
|
||||||
// Mount point for snap packages
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var driveType = FindDriveType.Find(type);
|
var driveType = FindDriveType.Find(type);
|
||||||
|
|
||||||
if (name.StartsWith("/dev/") || GetFileSystems().GetValueOrDefault(type, false))
|
if (name.StartsWith("/dev/") || GetFileSystems().GetValueOrDefault(type, false))
|
||||||
|
|
Loading…
Reference in New Issue