Skip to content

Commit 24b78ce

Browse files
committed
Fix incorrect assumption regarding path being always tmp
1 parent 7894095 commit 24b78ce

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Sources/swift-sh/OptionGroups/BuildAndRunOptions.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ final class BuildAndRunOptions : ParsableArguments {
4141
) :
4242
ScriptSource(content: scriptPathOrContent, fileManager: fm, logger: logger)
4343
)
44-
let scriptPath = try scriptSource.scriptPath?.0 ?! InternalError(message: "scriptPath is nil")
45-
guard scriptSource.scriptPath?.isTmp == true else {throw InternalError(message: "scriptPath is not tmp")}
4644
let cleanup = {
47-
/* Notes:
48-
* We should probably also register a sigaction to remove the temporary file in case of a terminating signal.
49-
* Or we could remove the file just after launching swift with it (to be tested). */
50-
let p = scriptPath.string
51-
do {try fm.removeItem(atPath: p)}
52-
catch {logger.warning("Failed removing temporary file.", metadata: ["file-path": "\(p)", "error": "\(error)"])}
45+
if let scriptPath = scriptSource.scriptPath, scriptPath.isTmp {
46+
/* Notes:
47+
* We should probably also register a sigaction to remove the temporary file in case of a terminating signal.
48+
* Or we could remove the file just after launching swift with it (to be tested). */
49+
let p = scriptPath.0.string
50+
do {try fm.removeItem(atPath: p)}
51+
catch {logger.warning("Failed removings temporary file.", metadata: ["file-path": "\(p)", "error": "\(error)"])}
52+
}
5353
}
5454

5555
let scriptPathForSwift: String

0 commit comments

Comments
 (0)