We hide IsPathTooLong from higher levels.

Respect the apparent previous approach to first try to fall back on System.IO
in case a path is too long or starts with a long UNC.
This commit is contained in:
verhoek
2018-10-31 13:08:14 +01:00
parent 0aa62975b7
commit 84edc2c91e
2 changed files with 43 additions and 6 deletions
+43 -2
View File
@@ -33,7 +33,7 @@ namespace Duplicati.Library.IO
private const string PATHPREFIX_SERVER = @"\\";
private static readonly string DIRSEP = System.IO.Path.DirectorySeparatorChar.ToString();
public static bool IsPathTooLong(string path)
private static bool IsPathTooLong(string path)
{
if (path.StartsWith(UNCPREFIX, StringComparison.Ordinal) || path.StartsWith(UNCPREFIX_SERVER, StringComparison.Ordinal) || path.Length > 260)
return true;
@@ -631,32 +631,73 @@ namespace Duplicati.Library.IO
}
public string GetPathRoot(string path)
{
{
if (!IsPathTooLong(path))
{
try { return Path.GetPathRoot(path); }
catch (System.IO.PathTooLongException) { }
catch (System.ArgumentException) { }
}
return AlphaFS.Path.GetPathRoot(path);
}
public string[] GetDirectories(string path)
{
if (!IsPathTooLong(path))
{
try { return Directory.GetDirectories(path); }
catch (System.IO.PathTooLongException) { }
catch (System.ArgumentException) { }
}
return AlphaFS.Directory.GetDirectories(path);
}
public string[] GetFiles(string path)
{
if (!IsPathTooLong(path))
{
try { return Directory.GetFiles(path); }
catch (System.IO.PathTooLongException) { }
catch (System.ArgumentException) { }
}
return AlphaFS.Directory.GetFiles(path);
}
public string[] GetFiles(string path, string searchPattern)
{
if (!IsPathTooLong(path))
{
try { return Directory.GetFiles(path, searchPattern); }
catch (System.IO.PathTooLongException) { }
catch (System.ArgumentException) { }
}
return AlphaFS.Directory.GetFiles(path, searchPattern);
}
public DateTime GetCreationTimeUtc(string path)
{
if (!IsPathTooLong(path))
{
try { return Directory.GetCreationTimeUtc(path); }
catch (System.IO.PathTooLongException) { }
catch (System.ArgumentException) { }
}
return AlphaFS.File.GetCreationTimeUtc(path);
}
public DateTime GetLastWriteTimeUtc(string path)
{
if (!IsPathTooLong(path))
{
try { return Directory.GetLastWriteTimeUtc(path); }
catch (System.IO.PathTooLongException) { }
catch (System.ArgumentException) { }
}
return AlphaFS.File.GetLastWriteTimeUtc(path);
}
#endregion
@@ -109,10 +109,6 @@ namespace Duplicati.Library.Snapshots
/// <param name='localFolderPath'>The folder to examinate</param>
protected override string[] ListFolders (string localFolderPath)
{
if (!SystemIOWindows.IsPathTooLong(localFolderPath))
try { return base.ListFolders(localFolderPath); }
catch (System.IO.PathTooLongException) { }
string[] tmp = SystemIO.IO_WIN.GetDirectories(SystemIOWindows.PrefixWithUNC(localFolderPath));
string[] res = new string[tmp.Length];
for (int i = 0; i < tmp.Length; i++)