mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 02:22:31 +01:00
Replace octal characters from mounts in /proc/mounts
Fixed: Replace octal characters in mount points Closes #1295
This commit is contained in:
parent
e4e3770e54
commit
ff3fc8de2e
@ -0,0 +1,18 @@
|
|||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Test.ExtensionTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class FromOctalStringFixture
|
||||||
|
{
|
||||||
|
[TestCase("\\040", " ")]
|
||||||
|
[TestCase("\\043", "#")]
|
||||||
|
[TestCase("\\101", "A")]
|
||||||
|
public void should_convert_octal_character_string_to_ascii_string(string octalString, string expected)
|
||||||
|
{
|
||||||
|
octalString.FromOctalString().Should().Be(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -79,6 +79,7 @@
|
|||||||
<Compile Include="EnvironmentProviderTest.cs" />
|
<Compile Include="EnvironmentProviderTest.cs" />
|
||||||
<Compile Include="EnvironmentTests\EnvironmentProviderTest.cs" />
|
<Compile Include="EnvironmentTests\EnvironmentProviderTest.cs" />
|
||||||
<Compile Include="EnvironmentTests\StartupArgumentsFixture.cs" />
|
<Compile Include="EnvironmentTests\StartupArgumentsFixture.cs" />
|
||||||
|
<Compile Include="ExtensionTests\FromOctalStringFixture.cs" />
|
||||||
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
|
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
|
||||||
<Compile Include="Http\HttpClientFixture.cs" />
|
<Compile Include="Http\HttpClientFixture.cs" />
|
||||||
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace NzbDrone.Common.Disk
|
namespace NzbDrone.Common.Disk
|
||||||
{
|
{
|
||||||
|
@ -105,5 +105,17 @@ public static string ToHexString(this byte[] input)
|
|||||||
{
|
{
|
||||||
return string.Concat(Array.ConvertAll(input, x => x.ToString("X2")));
|
return string.Concat(Array.ConvertAll(input, x => x.ToString("X2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string FromOctalString(this string octalValue)
|
||||||
|
{
|
||||||
|
octalValue = octalValue.TrimStart('\\');
|
||||||
|
|
||||||
|
var first = int.Parse(octalValue.Substring(0, 1));
|
||||||
|
var second = int.Parse(octalValue.Substring(1, 1));
|
||||||
|
var third = int.Parse(octalValue.Substring(2, 1));
|
||||||
|
var byteResult = (byte)((first << 6) | (second << 3) | (third));
|
||||||
|
|
||||||
|
return Encoding.ASCII.GetString(new [] { byteResult });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -62,6 +62,10 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\Libraries\Mono.Posix.dll</HintPath>
|
<HintPath>..\Libraries\Mono.Posix.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
<Reference Include="nunit.framework, Version=3.2.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.3.2.0\lib\net40\nunit.framework.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="FluentAssertions" version="4.2.1" targetFramework="net40" />
|
<package id="FluentAssertions" version="4.2.1" targetFramework="net40" />
|
||||||
|
<package id="Moq" version="4.0.10827" targetFramework="net40" />
|
||||||
<package id="NUnit" version="3.2.0" targetFramework="net40" />
|
<package id="NUnit" version="3.2.0" targetFramework="net40" />
|
||||||
</packages>
|
</packages>
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Mono.Unix;
|
using Mono.Unix;
|
||||||
@ -83,7 +84,7 @@ public override void SetPermissions(string path, string mask, string user, strin
|
|||||||
SetOwner(path, user, group);
|
SetOwner(path, user, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override System.Collections.Generic.List<IMount> GetMounts()
|
public override List<IMount> GetMounts()
|
||||||
{
|
{
|
||||||
return base.GetMounts()
|
return base.GetMounts()
|
||||||
.Concat(_procMountProvider.GetMounts())
|
.Concat(_procMountProvider.GetMounts())
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
@ -17,6 +18,10 @@ public class ProcMountProvider : IProcMountProvider
|
|||||||
{
|
{
|
||||||
private static string[] _fixedTypes = new [] { "ext3", "ext2", "ext4", "vfat", "fuseblk", "xfs", "jfs", "msdos", "ntfs", "minix", "hfs", "hfsplus", "qnx4", "ufs", "btrfs" };
|
private static string[] _fixedTypes = new [] { "ext3", "ext2", "ext4", "vfat", "fuseblk", "xfs", "jfs", "msdos", "ntfs", "minix", "hfs", "hfsplus", "qnx4", "ufs", "btrfs" };
|
||||||
private static string[] _networkDriveTypes = new [] { "cifs", "nfs", "nfs4", "nfsd", "sshfs" };
|
private static string[] _networkDriveTypes = new [] { "cifs", "nfs", "nfs4", "nfsd", "sshfs" };
|
||||||
|
private static readonly Regex OctalRegex = new Regex(@"\\\d{3}", RegexOptions.Compiled);
|
||||||
|
|
||||||
|
private const string PROC_MOUNTS_FILENAME = @"/proc/mounts";
|
||||||
|
private const string PROC_FILESYSTEMS_FILENAME = @"/proc/filesystems";
|
||||||
|
|
||||||
private static Dictionary<string, bool> _fileSystems;
|
private static Dictionary<string, bool> _fileSystems;
|
||||||
|
|
||||||
@ -31,16 +36,16 @@ public List<IMount> GetMounts()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(@"/proc/mounts"))
|
if (File.Exists(PROC_MOUNTS_FILENAME))
|
||||||
{
|
{
|
||||||
var lines = File.ReadAllLines(@"/proc/mounts");
|
var lines = File.ReadAllLines(PROC_MOUNTS_FILENAME);
|
||||||
|
|
||||||
return lines.Select(ParseLine).OfType<IMount>().ToList();
|
return lines.Select(ParseLine).OfType<IMount>().ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Debug(ex, "Failed to retrieve mounts from /proc/mounts");
|
_logger.Debug(ex, "Failed to retrieve mounts from {0}", PROC_MOUNTS_FILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new List<IMount>();
|
return new List<IMount>();
|
||||||
@ -53,9 +58,9 @@ private Dictionary<string, bool> GetFileSystems()
|
|||||||
var result = new Dictionary<string, bool>();
|
var result = new Dictionary<string, bool>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(@"/proc/filesystems"))
|
if (File.Exists(PROC_FILESYSTEMS_FILENAME))
|
||||||
{
|
{
|
||||||
var lines = File.ReadAllLines(@"/proc/filesystems");
|
var lines = File.ReadAllLines(PROC_FILESYSTEMS_FILENAME);
|
||||||
|
|
||||||
foreach (var line in lines)
|
foreach (var line in lines)
|
||||||
{
|
{
|
||||||
@ -67,7 +72,7 @@ private Dictionary<string, bool> GetFileSystems()
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Debug(ex, "Failed to get filesystem types from /proc/filesystems, using default set.");
|
_logger.Debug(ex, "Failed to get filesystem types from {0}, using default set.", PROC_FILESYSTEMS_FILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.Empty())
|
if (result.Empty())
|
||||||
@ -86,11 +91,11 @@ private Dictionary<string, bool> GetFileSystems()
|
|||||||
|
|
||||||
private IMount ParseLine(string line)
|
private IMount ParseLine(string line)
|
||||||
{
|
{
|
||||||
var split = line.Split(' ');
|
var split = line.Split(' ').Select(ExpandEscapes).ToArray();
|
||||||
|
|
||||||
if (split.Length != 6)
|
if (split.Length != 6)
|
||||||
{
|
{
|
||||||
_logger.Debug("Unable to parser /proc/mount line: {0}", line);
|
_logger.Debug("Unable to parse {0} line: {1}", PROC_MOUNTS_FILENAME, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
var name = split[0];
|
var name = split[0];
|
||||||
@ -132,5 +137,10 @@ private Dictionary<string, string> ParseOptions(string options)
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ExpandEscapes(string mount)
|
||||||
|
{
|
||||||
|
return OctalRegex.Replace(mount, match => match.Captures[0].Value.FromOctalString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user