From f9f0b6e9906ae023a62659501350dd43403e5efc Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Sun, 25 May 2025 09:08:05 -0400 Subject: [PATCH 1/5] Traverse any swiftly symlinks before copy or moving the binary to install it --- Sources/SwiftlyCore/Platform.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index c20f6d18..69472bb5 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -377,6 +377,15 @@ extension Platform { return } + // Traverse a symbolic link to the real swiftly + if let linkDest = try? FileManager.default.destinationOfSymbolicLink(atPath: cmdAbsolute) { + if linkDest.hasPrefix("/") { + cmdAbsolute = FilePath(linkDest) + } else { + cmdAbsolute = cmdAbsolute / linkDest + } + } + // Proceed to installation only if we're in the user home directory, or a non-system location. let userHome = fs.home From 3311e6019db672b170662905d0b6e85ff156d46c Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Sun, 25 May 2025 09:35:00 -0400 Subject: [PATCH 2/5] Fix typing issues --- Sources/SwiftlyCore/Platform.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 69472bb5..2295ddff 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -373,19 +373,21 @@ extension Platform { // We couldn't find ourselves in the usual places. Assume that no installation is necessary // since we were most likely invoked at SWIFTLY_BIN_DIR already. - guard let cmdAbsolute else { + guard var cmdAbsolute else { return } // Traverse a symbolic link to the real swiftly if let linkDest = try? FileManager.default.destinationOfSymbolicLink(atPath: cmdAbsolute) { - if linkDest.hasPrefix("/") { - cmdAbsolute = FilePath(linkDest) + if linkDest.isAbsolute { + cmdAbsolute = linkDest } else { - cmdAbsolute = cmdAbsolute / linkDest + cmdAbsolute = (cmdAbsolute / linkDest.string).lexicallyNormalized() } } + guard case let cmdAbsolute else { fatalError() } + // Proceed to installation only if we're in the user home directory, or a non-system location. let userHome = fs.home From 49b6a7c7c0749ac34343041b325bfdd8788415f9 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Sun, 25 May 2025 19:26:26 -0400 Subject: [PATCH 3/5] Fix guard statement --- Sources/SwiftlyCore/Platform.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 2295ddff..316b4a77 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -386,7 +386,7 @@ extension Platform { } } - guard case let cmdAbsolute else { fatalError() } + guard case let cmdAbsolute = cmdAbsolute else { fatalError() } // Proceed to installation only if we're in the user home directory, or a non-system location. let userHome = fs.home From a1f77a070103245945350661279fd2c2f5b415f2 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Mon, 26 May 2025 08:08:42 -0400 Subject: [PATCH 4/5] Prefer instead to leave symlinked swiftly alone --- Sources/SwiftlyCore/Platform.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 316b4a77..9f9438fc 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -377,13 +377,9 @@ extension Platform { return } - // Traverse a symbolic link to the real swiftly - if let linkDest = try? FileManager.default.destinationOfSymbolicLink(atPath: cmdAbsolute) { - if linkDest.isAbsolute { - cmdAbsolute = linkDest - } else { - cmdAbsolute = (cmdAbsolute / linkDest.string).lexicallyNormalized() - } + // If swiftly is symlinked then we leave it where it is, such as in a homebrew installation. + if let _ = try? FileManager.default.destinationOfSymbolicLink(atPath: cmdAbsolute) { + return } guard case let cmdAbsolute = cmdAbsolute else { fatalError() } From d5709396e556c12debd05212fbbd2fd00c10a2d0 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Mon, 26 May 2025 09:30:34 -0400 Subject: [PATCH 5/5] Simplify the code --- Sources/SwiftlyCore/Platform.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 9f9438fc..9ab2ad4d 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -373,7 +373,7 @@ extension Platform { // We couldn't find ourselves in the usual places. Assume that no installation is necessary // since we were most likely invoked at SWIFTLY_BIN_DIR already. - guard var cmdAbsolute else { + guard let cmdAbsolute else { return } @@ -382,8 +382,6 @@ extension Platform { return } - guard case let cmdAbsolute = cmdAbsolute else { fatalError() } - // Proceed to installation only if we're in the user home directory, or a non-system location. let userHome = fs.home