Skip to content

Commit 332afc8

Browse files
authored
TSCBasic: special case a few leading character cases for Path (#324)
The UNIX implementation special cases `/` and `~` which SPM depends on. Handle the invalid file system character `~` specially on Windows as well. As we are now getting closer to normalized path spellings, we need to add a special case for the leading path separator character. On UNIX, this signifies the root of the singular unified file system view. However, Windows presents a forest to the user with 26 roots. Consequently, a path headed by the path separator is a relative path rather than an absolute path. However, we treat the root-relative path as an invalid relative path for the time being as the representation is not flexible enough to account for this model.
1 parent f771460 commit 332afc8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,9 @@ private struct UNIXPath: Path {
760760
defer { fsr.deallocate() }
761761

762762
let realpath: String = String(cString: fsr)
763-
if UNIXPath.isAbsolutePath(realpath) {
763+
// Treat a relative path as an invalid relative path...
764+
if UNIXPath.isAbsolutePath(realpath) ||
765+
realpath.first == "~" || realpath.first == "\\" {
764766
throw PathValidationError.invalidRelativePath(path)
765767
}
766768
self.init(normalizingRelativePath: path)
@@ -895,7 +897,7 @@ extension PathValidationError: CustomStringConvertible {
895897
case .invalidAbsolutePath(let path):
896898
return "invalid absolute path '\(path)'"
897899
case .invalidRelativePath(let path):
898-
return "invalid relative path '\(path)'; relative path should not begin with '/' or '~'"
900+
return "invalid relative path '\(path)'; relative path should not begin with '\(AbsolutePath.root.pathString)' or '~'"
899901
}
900902
}
901903
}

0 commit comments

Comments
 (0)