Skip to content

Commit c4530a2

Browse files
committed
2 parents 9d57ccf + f5f3647 commit c4530a2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Sources/Basic/FileSystem.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ public class InMemoryFileSystem: FileSystem {
386386
}
387387

388388
public func createDirectory(_ path: AbsolutePath, recursive: Bool) throws {
389+
// Ignore if client passes root.
390+
guard !path.isRoot else {
391+
return
392+
}
389393
// Get the parent directory node.
390394
let parentPath = path.parentDirectory
391395
guard let parent = try getNode(parentPath) else {

Tests/Basic/FileSystemTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ class FileSystemTests: XCTestCase {
174174

175175
func testInMemoryCreateDirectory() {
176176
let fs = InMemoryFileSystem()
177+
// Make sure root entry isn't created.
178+
try! fs.createDirectory(AbsolutePath("/"), recursive: true)
179+
let rootContents = try! fs.getDirectoryContents(.root)
180+
XCTAssertEqual(rootContents, [])
181+
177182
let subdir = AbsolutePath("/new-dir/subdir")
178183
try! fs.createDirectory(subdir, recursive: true)
179184
XCTAssert(fs.isDirectory(subdir))

0 commit comments

Comments
 (0)