File tree Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Expand file tree Collapse file tree 2 files changed +9
-0
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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) )
You can’t perform that action at this time.
0 commit comments