Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Swiftly/Install.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct Install: SwiftlyCommand {

for bin in swiftlyBinDirContents {
do {
let linkTarget = try await fs.readlink(atPath: swiftlyBinDir / bin)
let linkTarget = try await fs.readlink(atPath: swiftlyBinDir / bin, follow: false)
if linkTarget == proxyTo {
existingProxies.append(bin)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftly/SelfUninstall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct SelfUninstall: SwiftlyCommand {
let fullPath = swiftlyBin / entry
guard try await fs.exists(atPath: fullPath) else { continue }
if try await fs.isSymLink(atPath: fullPath) {
let dest = try await fs.readlink(atPath: fullPath)
let dest = try await fs.readlink(atPath: fullPath, follow: false)
if dest == swiftlyBinary {
if verbose {
await ctx.print("Removing symlink: \(fullPath) -> \(dest)")
Expand Down
4 changes: 2 additions & 2 deletions Sources/Swiftly/Unlink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct Unlink: SwiftlyCommand {
let swiftlyBinDirContents = (try? await fs.ls(atPath: swiftlyBinDir)) ?? [String]()
var proxies = [String]()
for file in swiftlyBinDirContents {
let linkTarget = try? await fs.readlink(atPath: swiftlyBinDir / file)
let linkTarget = try? await fs.readlink(atPath: swiftlyBinDir / file, follow: true)
if linkTarget == proxyTo {
proxies.append(file)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ extension SwiftlyCommand {
}

let potentialProxyPath = swiftlyBinDir / file
if let linkTarget = try? await fs.readlink(atPath: potentialProxyPath), linkTarget == proxyTo {
if let linkTarget = try? await fs.readlink(atPath: potentialProxyPath, follow: true), linkTarget == proxyTo {
return true
}
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/Swiftly/Use.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ struct Use: SwiftlyCommand {

var config = try await Config.load(ctx)

try await validateLinked(ctx)
// Only validate linked state if we're not printing the location
if !self.printLocation {
try await validateLinked(ctx)
}

// This is the bare use command where we print the selected toolchain version (or the path to it)
guard let toolchain = self.toolchain else {
Expand Down
9 changes: 7 additions & 2 deletions Sources/SwiftlyCore/FileManager+FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ public enum FileSystem {
try FileManager.default.contentsOfDir(atPath: atPath)
}

public static func readlink(atPath: FilePath) async throws -> FilePath {
try FileManager.default.destinationOfSymbolicLink(atPath: atPath)
public static func readlink(atPath: FilePath, follow: Bool) async throws -> FilePath {
let path = try FileManager.default.destinationOfSymbolicLink(atPath: atPath)
if follow {
return FilePath(URL(fileURLWithPath: path.string).resolvingSymlinksInPath().path)
} else {
return path
}
}

public static func isSymLink(atPath: FilePath) async throws -> Bool {
Expand Down