Skip to content

Commit 2d4eebb

Browse files
committed
update uses of FileManager.default() on Linux to align with Darwin version
this PR should be merged with swiftlang/swift-corelibs-foundation#484
1 parent 493e2de commit 2d4eebb

File tree

4 files changed

+0
-28
lines changed

4 files changed

+0
-28
lines changed

Sources/Basic/PathShims.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,12 @@ public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
8585

8686
/// Creates a new, empty directory at `path`. If needed, any non-existent ancestor paths are also created. If there is already a directory at `path`, this function does nothing (in particular, this is not considered to be an error).
8787
public func makeDirectories(_ path: AbsolutePath) throws {
88-
#if os(Linux)
89-
try FileManager.default().createDirectory(atPath: path.asString, withIntermediateDirectories: true, attributes: [:])
90-
#else
9188
try FileManager.default.createDirectory(atPath: path.asString, withIntermediateDirectories: true, attributes: [:])
92-
#endif
9389
}
9490

9591
/// Recursively deletes the file system entity at `path`. If there is no file system entity at `path`, this function does nothing (in particular, this is not considered to be an error).
9692
public func removeFileTree(_ path: AbsolutePath) throws {
97-
#if os(Linux)
98-
try FileManager.default().removeItem(atPath: path.asString)
99-
#else
10093
try FileManager.default.removeItem(atPath: path.asString)
101-
#endif
10294
}
10395

10496
/// Creates a symbolic link at `path` whose content points to `dest`. If `relative` is true, the symlink contents will be a relative path, otherwise it will be absolute.
@@ -121,11 +113,7 @@ public func unlink(_ path: AbsolutePath) throws {
121113
/// The current working directory of the process (same as returned by POSIX' `getcwd()` function or Foundation's `currentDirectoryPath` method).
122114
/// FIXME: This should probably go onto `FileSystem`, under the assumption that each file system has its own notion of the `current` working directory.
123115
public var currentWorkingDirectory: AbsolutePath {
124-
#if os(Linux)
125-
let cwdStr = FileManager.default().currentDirectoryPath
126-
#else
127116
let cwdStr = FileManager.default.currentDirectoryPath
128-
#endif
129117
return AbsolutePath(cwdStr)
130118
}
131119

@@ -257,11 +245,7 @@ public func fopen(_ path: AbsolutePath, mode: FopenMode = .read) throws -> FileH
257245
switch mode {
258246
case .read: handle = FileHandle(forReadingAtPath: path.asString)
259247
case .write:
260-
#if os(Linux)
261-
let success = FileManager.default().createFile(atPath: path.asString, contents: nil)
262-
#else
263248
let success = FileManager.default.createFile(atPath: path.asString, contents: nil)
264-
#endif
265249
guard success else {
266250
throw FileAccessError.couldNotCreateFile(path: path.asString)
267251
}

Sources/Basic/TemporaryFile.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,7 @@ public final class TemporaryDirectory {
196196
/// Remove the temporary file before deallocating.
197197
deinit {
198198
if removeTreeOnDeinit {
199-
#if os(Linux)
200-
let _ = try? FileManager.default().removeItem(atPath: path.asString)
201-
#else
202199
let _ = try? FileManager.default.removeItem(atPath: path.asString)
203-
#endif
204200
} else {
205201
rmdir(path.asString)
206202
}

Sources/swiftpm-xctest-helper/main.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ extension String {
9696
func normalizedPath() -> String {
9797
var path = self
9898
if !(path as NSString).isAbsolutePath {
99-
#if os(Linux)
100-
path = FileManager.default().currentDirectoryPath + "/" + path
101-
#else
10299
path = FileManager.default.currentDirectoryPath + "/" + path
103-
#endif
104100
}
105101
return (path as NSString).standardizingPath
106102
}

Tests/BasicTests/TemporaryFileTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ class TemporaryFileTests: XCTestCase {
8585
}
8686
XCTAssertTrue(localFileSystem.isDirectory(path))
8787
// Cleanup.
88-
#if os(Linux)
89-
try FileManager.default().removeItem(atPath: path.asString)
90-
#else
9188
try FileManager.default.removeItem(atPath: path.asString)
92-
#endif
9389
XCTAssertFalse(localFileSystem.isDirectory(path))
9490

9591
// Test temp directory is removed when its not empty and removeTreeOnDeinit is enabled.

0 commit comments

Comments
 (0)