|
10 | 10 |
|
11 | 11 | import ArgumentParser |
12 | 12 | import Basics |
| 13 | +import Foundation |
13 | 14 | import PackageModel |
14 | 15 | import ScriptingCore |
15 | 16 | import TSCBasic |
@@ -310,21 +311,27 @@ extension SwiftScriptTool { |
310 | 311 | func run() throws { |
311 | 312 | let cacheDir = try localFileSystem.getOrCreateSwiftScriptCacheDirectory() |
312 | 313 | let scripts = try localFileSystem.getDirectoryContents(cacheDir) |
313 | | - // Walk through the cache and find origin script paths. |
314 | | - let resolved = try scripts.compactMap { script -> (String, AbsolutePath)? in |
| 314 | + // Walk through the cache and find original script paths. |
| 315 | + let resolved = try scripts.compactMap { script -> (String, String)? in |
315 | 316 | let sourceDir = cacheDir.appending(components: script, "Sources") |
316 | 317 | guard localFileSystem.isDirectory(sourceDir), |
317 | 318 | 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 { |
319 | 321 | return nil |
320 | 322 | } |
321 | | - return (script, realpath) |
| 323 | + // Check if the original script still exists. |
| 324 | + if localFileSystem.exists(path, followSymlink: true) { |
| 325 | + return (script, destination) |
| 326 | + } else { |
| 327 | + return (script, "\(destination) (removed)") |
| 328 | + } |
322 | 329 | } |
323 | 330 | // Print the resolved cache info. |
324 | 331 | print("\(scripts.count) script\(scripts.count > 1 ? "s" : "") cached at \(cacheDir)") |
325 | 332 | 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) |
| 333 | + resolved.forEach { (name, desc) in |
| 334 | + print(name + String(repeating: " ", count: maxLength - name.count + 2) + desc) |
328 | 335 | } |
329 | 336 | } |
330 | 337 | } |
|
0 commit comments