Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 10a6570

Browse files
stephentoubJeremyKuhne
authored andcommitted
Fix handling of root on Unix in directory error handling (#20049)
1 parent d32da03 commit 10a6570

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/System.IO.FileSystem/src/System/IO/PathHelpers.Unix.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@ internal static void CheckSearchPattern(string searchPattern)
2727
}
2828
}
2929
}
30+
31+
internal static string TrimEndingDirectorySeparator(string path) =>
32+
path.Length > 1 && PathInternal.IsDirectorySeparator(path[path.Length - 1]) ? // exclude root "/"
33+
path.Substring(0, path.Length - 1) :
34+
path;
3035
}
3136
}

src/System.IO.FileSystem/src/System/IO/PathHelpers.Windows.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,10 @@ internal static string GetFullSearchString(string fullPath, string searchPattern
118118

119119
return tempStr;
120120
}
121+
122+
internal static string TrimEndingDirectorySeparator(string path) =>
123+
EndsInDirectorySeparator(path) ?
124+
path.Substring(0, path.Length - 1) :
125+
path;
121126
}
122127
}

src/System.IO.FileSystem/src/System/IO/PathHelpers.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,5 @@ internal static bool EndsInDirectorySeparator(String path)
3838
{
3939
return path.Length > 0 && PathInternal.IsDirectorySeparator(path[path.Length - 1]);
4040
}
41-
42-
internal static string TrimEndingDirectorySeparator(string path)
43-
{
44-
return EndsInDirectorySeparator(path) ?
45-
path.Substring(0, path.Length - 1) :
46-
path;
47-
}
4841
}
4942
}

0 commit comments

Comments
 (0)