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

Commit 1764a71

Browse files
committed
Merge pull request #2308 from stephentoub/minor_path_fixups
Two minor path-related changes
2 parents 7a2b3bf + d18f1a3 commit 1764a71

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

src/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,10 @@
2424
</ItemGroup>
2525
<!-- Windows -->
2626
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
27-
<Compile Include="$(CommonPath)\System\IO\PathInternal.Windows.cs">
28-
<Link>Common\System\IO\PathInternal.Windows.cs</Link>
29-
</Compile>
3027
<Compile Include="$(CommonPath)\System\IO\PathInternal.CaseInsensitive.cs">
3128
<Link>Common\System\IO\PathInternal.CaseInsensitive.cs</Link>
3229
</Compile>
3330
</ItemGroup>
34-
<!-- Unix -->
35-
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
36-
<Compile Include="$(CommonPath)\System\IO\PathInternal.Unix.cs">
37-
<Link>Common\System\IO\PathInternal.Unix.cs</Link>
38-
</Compile>
39-
</ItemGroup>
4031
<!-- FreeBSD -->
4132
<ItemGroup Condition="'$(TargetsFreeBSD)' == 'true'">
4233
<Compile Include="$(CommonPath)\System\IO\PathInternal.CaseSensitive.cs">

src/System.Runtime/tests/System/IO/PathTooLongException.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ public static void PathTooLongException_From_Path()
3838
// This test case ensures that the PathTooLongException defined in System.IO.Primitives is the same that
3939
// is thrown by Path. The S.IO.FS.P implementation forwards to the core assembly to ensure this is true.
4040

41-
string subPath = "subdir\\";
42-
const int MAX_PATH = 260;
43-
44-
// Create a relative path that is longer than maxpath.
45-
StringBuilder path = new StringBuilder();
46-
while (path.Length <= MAX_PATH)
41+
// Build up a path until GetFullPath throws, and verify that the right exception type
42+
// emerges from it and related APIs.
43+
var sb = new StringBuilder("directoryNameHere" + Path.DirectorySeparatorChar);
44+
string path = null;
45+
Assert.Throws<PathTooLongException>(new Action(() =>
4746
{
48-
path.Append(subPath);
49-
}
50-
51-
// Not available in N: Assert.Throws<PathTooLongException>(() => Path.GetFullPath(path.ToString()));
52-
Assert.Throws<PathTooLongException>(() => Path.GetPathRoot(path.ToString()));
53-
Assert.Throws<PathTooLongException>(() => Path.GetDirectoryName(path.ToString()));
47+
while (true)
48+
{
49+
path = sb.ToString();
50+
Path.GetPathRoot(path); // will eventually throw when path is too long
51+
sb.Append(path); // double the number of directories for the next time
52+
}
53+
}));
54+
Assert.Throws<PathTooLongException>(() => Path.GetFullPath(path));
55+
Assert.Throws<PathTooLongException>(() => Path.GetDirectoryName(path));
5456
}
5557
}

0 commit comments

Comments
 (0)