Fixed: Hide some more irrelevant paths from System->Disk Space such as /boot.

This commit is contained in:
Taloth Saldono 2017-08-09 21:38:18 +02:00
parent caf7a8c69e
commit c659ba1c10
4 changed files with 40 additions and 18 deletions

View File

@ -51,7 +51,7 @@ namespace NzbDrone.Common.Disk
{
get
{
if (VolumeLabel.IsNullOrWhiteSpace())
if (VolumeLabel.IsNullOrWhiteSpace() || VolumeLabel.StartsWith("UUID=") || Name == VolumeLabel)
{
return Name;
}

View File

@ -130,5 +130,25 @@ namespace NzbDrone.Core.Test.DiskSpace
Mocker.GetMock<IDiskProvider>()
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Never());
}
[TestCase("/boot")]
[TestCase("/var/lib/rancher")]
[TestCase("/var/lib/kubelet")]
[TestCase("/var/lib/docker")]
[TestCase("/some/place/docker/aufs")]
public void should_not_check_diskspace_for_irrelevant_mounts(string path)
{
var mount = new Mock<IMount>();
mount.SetupGet(v => v.RootDirectory).Returns(path);
mount.SetupGet(v => v.DriveType).Returns(System.IO.DriveType.Fixed);
Mocker.GetMock<IDiskProvider>()
.Setup(v => v.GetMounts())
.Returns(new List<IMount> { mount.Object });
var freeSpace = Subject.GetFreeSpace();
freeSpace.Should().BeEmpty();
}
}
}

View File

@ -1,7 +1,8 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
@ -22,6 +23,8 @@ namespace NzbDrone.Core.DiskSpace
private readonly IDiskProvider _diskProvider;
private readonly Logger _logger;
private static readonly Regex _regexSpecialDrive = new Regex("^/var/lib/(docker|rancher|kubelet)$|^/boot$|docker(/var)?/aufs", RegexOptions.Compiled);
public DiskSpaceService(ISeriesService seriesService, IConfigService configService, IDiskProvider diskProvider, Logger logger)
{
_seriesService = seriesService;
@ -32,37 +35,36 @@ namespace NzbDrone.Core.DiskSpace
public List<DiskSpace> GetFreeSpace()
{
var diskSpace = new List<DiskSpace>();
diskSpace.AddRange(GetSeriesFreeSpace());
diskSpace.AddRange(GetDroneFactoryFreeSpace());
diskSpace.AddRange(GetFixedDisksFreeSpace());
var rootPaths = new List<string>();
rootPaths.AddRange(GetSeriesRootPaths());
rootPaths.AddRange(GetDroneFactoryRootPaths());
rootPaths.AddRange(GetFixedDisksRootPaths());
return diskSpace.DistinctBy(d => d.Path).ToList();
return GetDiskSpace(rootPaths.Distinct()).ToList();
}
private IEnumerable<DiskSpace> GetSeriesFreeSpace()
private IEnumerable<string> GetSeriesRootPaths()
{
var seriesRootPaths = _seriesService.GetAllSeries()
return _seriesService.GetAllSeries()
.Where(s => _diskProvider.FolderExists(s.Path))
.Select(s => _diskProvider.GetPathRoot(s.Path))
.Distinct();
return GetDiskSpace(seriesRootPaths);
}
private IEnumerable<DiskSpace> GetDroneFactoryFreeSpace()
private IEnumerable<string> GetDroneFactoryRootPaths()
{
if (_configService.DownloadedEpisodesFolder.IsNotNullOrWhiteSpace() && _diskProvider.FolderExists(_configService.DownloadedEpisodesFolder))
{
return GetDiskSpace(new[] { _diskProvider.GetPathRoot(_configService.DownloadedEpisodesFolder) });
yield return _configService.DownloadedEpisodesFolder;
}
return new List<DiskSpace>();
}
private IEnumerable<DiskSpace> GetFixedDisksFreeSpace()
private IEnumerable<string> GetFixedDisksRootPaths()
{
return GetDiskSpace(_diskProvider.GetMounts().Where(d => d.DriveType == DriveType.Fixed).Select(d => d.RootDirectory), true);
return _diskProvider.GetMounts()
.Where(d => d.DriveType == DriveType.Fixed)
.Where(d => !_regexSpecialDrive.IsMatch(d.RootDirectory))
.Select(d => d.RootDirectory);
}
private IEnumerable<DiskSpace> GetDiskSpace(IEnumerable<string> paths, bool suppressWarnings = false)

View File

@ -45,7 +45,7 @@ namespace NzbDrone.Mono.Disk
{
get
{
if (VolumeLabel.IsNullOrWhiteSpace() || VolumeLabel.StartsWith("UUID="))
if (VolumeLabel.IsNullOrWhiteSpace() || VolumeLabel.StartsWith("UUID=") || Name == VolumeLabel)
{
return Name;
}