Skip to content

Commit d27ed7d

Browse files
committed
Throw an error if a URL's reported path is not absolute
1 parent 1d66c4f commit d27ed7d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Sources/SWBBuildService/BuildService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,20 @@ open class BuildService: Service, @unchecked Sendable {
9090
let fs = SWBUtil.localFS
9191
var binariesToCheck = [Path]()
9292
// Check our own bundle's executable.
93-
if let executablePath = try Bundle.main.executableURL?.filePath {
93+
if let executablePath = try? Bundle.main.executableURL?.filePath {
9494
if fs.exists(executablePath) {
9595
binariesToCheck.append(executablePath)
9696
}
9797
}
9898
// Check all the binaries of frameworks in the Frameworks folder.
9999
// Note that this does not recurse into the frameworks for other items nested inside them. We also presently don't check the PlugIns folder.
100-
if let frameworksPath = try Bundle.main.privateFrameworksURL?.filePath {
100+
if let frameworksPath = try? Bundle.main.privateFrameworksURL?.filePath {
101101
do {
102102
for subpath in try fs.listdir(frameworksPath) {
103103
let frameworkPath = frameworksPath.join(subpath)
104104
// Load a bundle at this path. This means we'll skip things which aren't bundles, such as the Swift standard libraries.
105105
if let bundle = Bundle(path: frameworkPath.str) {
106-
if let unresolvedExecutablePath = try bundle.executableURL?.filePath {
106+
if let unresolvedExecutablePath = try? bundle.executableURL?.filePath {
107107
let executablePath = try fs.realpath(unresolvedExecutablePath)
108108
if fs.exists(executablePath) {
109109
binariesToCheck.append(executablePath)

Sources/SWBUtil/URL.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ extension URL {
2828
throw FileURLError.notRepresentable(self)
2929
}
3030
let fp = Path(String(cString: cString))
31-
precondition(fp.isAbsolute, "path '\(fp.str)' is not absolute")
31+
guard fp.isAbsolute else {
32+
throw FileURLError.pathNotAbsolute(self)
33+
}
3234
return fp
3335
}
3436
}
@@ -37,4 +39,5 @@ extension URL {
3739

3840
fileprivate enum FileURLError: Error {
3941
case notRepresentable(URL)
42+
case pathNotAbsolute(URL)
4043
}

0 commit comments

Comments
 (0)