Skip to content
Merged
Changes from 2 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
13 changes: 12 additions & 1 deletion Sources/SwiftlyCore/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is must simpler now; this can be changed back to let and the guard case let cmdAbsolute = cmdAbsolute else { fatalError() } can be removed completely

return
}

// Traverse a symbolic link to the real swiftly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An addition to the comment here explaining why this block might be hit would help; its unclear how swiftly would get in to this situation just from the code.

if let linkDest = try? FileManager.default.destinationOfSymbolicLink(atPath: cmdAbsolute) {
if linkDest.isAbsolute {
cmdAbsolute = linkDest
} else {
cmdAbsolute = (cmdAbsolute / linkDest.string).lexicallyNormalized()
}
}

guard case let cmdAbsolute else { fatalError() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this guard looks redundant, as the code does not allow for cmdAbsolute to be optional after guard var cmdAbsolute

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to tighten the var into a let. Perhaps there is a better way to lock the variable down?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has changed into a different approach and loses this guard statement.


// Proceed to installation only if we're in the user home directory, or a non-system location.
let userHome = fs.home

Expand Down
Loading