From 84edc2c91e587c1d70d224dcb47e204e4a63a67c Mon Sep 17 00:00:00 2001 From: verhoek <30193551+verhoek@users.noreply.github.com> Date: Wed, 31 Oct 2018 13:08:14 +0100 Subject: [PATCH] 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. --- Duplicati/Library/IO/SystemIOWindows.cs | 45 ++++++++++++++++++- .../Library/Snapshots/NoSnapshotWindows.cs | 4 -- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Duplicati/Library/IO/SystemIOWindows.cs b/Duplicati/Library/IO/SystemIOWindows.cs index cb0ad4636..d6b0c8a61 100644 --- a/Duplicati/Library/IO/SystemIOWindows.cs +++ b/Duplicati/Library/IO/SystemIOWindows.cs @@ -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 diff --git a/Duplicati/Library/Snapshots/NoSnapshotWindows.cs b/Duplicati/Library/Snapshots/NoSnapshotWindows.cs index 70db555bd..85c0ab819 100644 --- a/Duplicati/Library/Snapshots/NoSnapshotWindows.cs +++ b/Duplicati/Library/Snapshots/NoSnapshotWindows.cs @@ -109,10 +109,6 @@ namespace Duplicati.Library.Snapshots /// The folder to examinate 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++)