Skip to content

Commit b8ef4ce

Browse files
authored
(122106445) Exclude some paths from automount standardization
* (122106445) Exclude some paths from automount standardization * Fix linux build failure
1 parent b931b6d commit b8ef4ce

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Sources/FoundationEssentials/String/String+Path.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,14 @@ extension String {
292292
result = components.enumerated().filter { $0 == 0 || !$1.isEmpty }.map(\.1).joined(separator: "/")
293293

294294
// Automounted paths need to be stripped for various flavors of paths
295+
let exclusionList = ["/Applications", "/Library", "/System", "/Users", "/Volumes", "/bin", "/cores", "/dev", "/opt", "/private", "/sbin", "/usr"]
295296
for path in ["/private/var/automount", "/var/automount", "/private"] {
296297
if result.starts(with: "\(path)/") {
297298
let newPath = String(result.dropFirst(path.count))
298-
if FileManager.default.fileExists(atPath: newPath) {
299+
let isExcluded = exclusionList.contains {
300+
newPath == $0 || newPath.starts(with: "\($0)/")
301+
}
302+
if !isExcluded && FileManager.default.fileExists(atPath: newPath) {
299303
result = newPath
300304
}
301305
break

Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,4 +551,19 @@ final class FileManagerTests : XCTestCase {
551551
#endif
552552
}
553553
}
554+
555+
func testStandardizingPathAutomount() throws {
556+
#if canImport(Darwin)
557+
let tests = [
558+
"/private/System" : "/private/System",
559+
"/private/tmp" : "/tmp",
560+
"/private/System/foo" : "/private/System/foo"
561+
]
562+
for (input, expected) in tests {
563+
XCTAssertEqual(input.standardizingPath, expected, "Standardizing the path '\(input)' did not produce the expected result")
564+
}
565+
#else
566+
throw XCTSkip("This test is not applicable to this platform")
567+
#endif
568+
}
554569
}

0 commit comments

Comments
 (0)