Skip to content

Commit 8468065

Browse files
committed
Fix symlink resolution
1 parent ee778d9 commit 8468065

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Sources/Commands/SwiftScriptTool.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import ArgumentParser
1212
import Basics
13+
import Foundation
1314
import PackageModel
1415
import ScriptingCore
1516
import TSCBasic
@@ -311,20 +312,25 @@ extension SwiftScriptTool {
311312
let cacheDir = try localFileSystem.getOrCreateSwiftScriptCacheDirectory()
312313
let scripts = try localFileSystem.getDirectoryContents(cacheDir)
313314
// Walk through the cache and find origin script paths.
314-
let resolved = try scripts.compactMap { script -> (String, AbsolutePath)? in
315+
let resolved = try scripts.compactMap { script -> (String, String)? in
315316
let sourceDir = cacheDir.appending(components: script, "Sources")
316317
guard localFileSystem.isDirectory(sourceDir),
317318
let name = try localFileSystem.getDirectoryContents(sourceDir).first,
318-
case let realpath = resolveSymlinks(sourceDir.appending(components: name, "main.swift")) else {
319+
case let path = sourceDir.appending(components: name, "main.swift"),
320+
let destination = try? FileManager.default.destinationOfSymbolicLink(atPath: path.pathString) else {
319321
return nil
320322
}
321-
return (script, realpath)
323+
if localFileSystem.exists(path, followSymlink: true) {
324+
return (script, destination)
325+
} else {
326+
return (script, "\(destination) (removed)")
327+
}
322328
}
323329
// Print the resolved cache info.
324330
print("\(scripts.count) script\(scripts.count > 1 ? "s" : "") cached at \(cacheDir)")
325331
guard let maxLength = resolved.map(\.0.count).max() else { return }
326-
resolved.forEach { (name, path) in
327-
print(name + String(repeating: " ", count: maxLength - name.count + 2) + path.pathString)
332+
resolved.forEach { (name, desc) in
333+
print(name + String(repeating: " ", count: maxLength - name.count + 2) + desc)
328334
}
329335
}
330336
}

0 commit comments

Comments
 (0)