diff --git a/Sources/Files.swift b/Sources/Files.swift index dc1f238..ae60dc4 100644 --- a/Sources/Files.swift +++ b/Sources/Files.swift @@ -317,7 +317,8 @@ public class FileSystem { */ @discardableResult public func createFolder(at path: String) throws -> Folder { do { - try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil) + let absolutePath = fileManager.absolutePath(for: path) + try fileManager.createDirectory(atPath: absolutePath, withIntermediateDirectories: true, attributes: nil) return try Folder(path: path, using: fileManager) } catch { throw Folder.Error.creatingFolderFailed diff --git a/Tests/FilesTests/FilesTests.swift b/Tests/FilesTests/FilesTests.swift index 5ce0db9..cec286a 100644 --- a/Tests/FilesTests/FilesTests.swift +++ b/Tests/FilesTests/FilesTests.swift @@ -136,10 +136,13 @@ class FilesTests: XCTestCase { func testReadingFileWithTildePath() { performTest { - try FileSystem().homeFolder.createFile(named: "file") - let file = try File(path: "~/file") + try FileSystem().homeFolder.createFile(named: ".filestest") + let file = try File(path: "~/.filestest") try XCTAssertEqual(file.read(), Data()) - XCTAssertEqual(file.path, FileSystem().homeFolder.path + "file") + XCTAssertEqual(file.path, FileSystem().homeFolder.path + ".filestest") + + // Cleanup since we're performing a test in the actual home folder + try file.delete() } } @@ -408,6 +411,17 @@ class FilesTests: XCTestCase { } } + func testCreatingFolderWithTildePathFromFileSystem() { + performTest { + let fileSystem = FileSystem() + try fileSystem.createFolder(at: "~/.filestest") + let createdFolder = try fileSystem.homeFolder.subfolder(named: ".filestest") + + // Cleanup since we're performing a test in the actual home folder + try createdFolder.delete() + } + } + func testCreateFileIfNeeded() { performTest { let fileA = try folder.createFileIfNeeded(withName: "file", contents: "Hello".data(using: .utf8)!)