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

Commit 5de40bf

Browse files
committed
Fix UnixFileSystem.MaxDirectoryName to be MaxPath
UnixFileSystem's override of MaxDirectoryName was assuming the property meant the maximum size of the file name of a directory, i.e. the component length, not the full path length of everything from the beginning of the root. As a result, checks against MaxDirectoryName, such as in CreateDirectory, were failing incorrectly with longer path lengths. The fix is just to return MaxPath from MaxDirectoryName; there's no difference on Unix. I also added a test to cover this case, included a previously excluded test, and deleted a faulty test.
1 parent d6d8a09 commit 5de40bf

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/System.IO.FileSystem/src/System/IO/UnixFileSystem.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7-
using System.Runtime.CompilerServices;
87
using System.Runtime.InteropServices;
98
using System.Threading;
109

@@ -15,7 +14,7 @@ internal sealed partial class UnixFileSystem : FileSystem
1514
{
1615
public override int MaxPath { get { return Interop.libc.MaxPath; } }
1716

18-
public override int MaxDirectoryPath { get { return Interop.libc.MaxName; } }
17+
public override int MaxDirectoryPath { get { return Interop.libc.MaxPath; } }
1918

2019
public override FileStreamBase Open(string fullPath, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, FileStream parent)
2120
{

src/System.IO.FileSystem/tests/Directory/CreateDirectory.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ public void DirectoryLongerThanMaxDirectoryAsPath_ThrowsPathTooLongException()
233233

234234
[Fact]
235235
[PlatformSpecific(PlatformID.AnyUnix)]
236-
[ActiveIssue(645)]
237236
public void UnixPathLongerThan256_Allowed()
238237
{
239238
DirectoryInfo testDir = Create(GetTestFilePath());
@@ -245,11 +244,14 @@ public void UnixPathLongerThan256_Allowed()
245244

246245
[Fact]
247246
[PlatformSpecific(PlatformID.AnyUnix)]
248-
public void UnixPathLongerThan256_Throws()
247+
public void UnixPathWithDeeplyNestedDirectories()
249248
{
250-
DirectoryInfo testDir = Create(GetTestFilePath());
251-
PathInfo path = IOServices.GetPath(testDir.FullName, 257, IOInputs.MaxComponent);
252-
Assert.Throws<PathTooLongException>(() => Create(path.FullPath));
249+
DirectoryInfo parent = Create(GetTestFilePath());
250+
for (int i = 1; i <= 100; i++) // 100 == arbitrarily large number of directories
251+
{
252+
parent = Create(Path.Combine(parent.FullName, "dir" + i));
253+
Assert.True(Directory.Exists(parent.FullName));
254+
}
253255
}
254256

255257
[Fact]

0 commit comments

Comments
 (0)