Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Don't recurse without end over a chosen folder whose link leads nowhere

Țugui Dragoș2607792fea06
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift
index 0be4ddbe..f92dbfb4 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppFolders.swift
@@ -99,10 +99,13 @@ public struct AppFolders: Sendable {
}
static func refusal(of folder: URL, home: URL, isInTheCloud: (URL) -> Bool) -> Refusal? {
- // A link is read as where it leads, so that is what it is judged as too.
- if folder.isSymbolicLink,
- let refusal = refusal(of: PathPattern.canonical(folder), home: home, isInTheCloud: isInTheCloud) {
- return refusal
+ // A link is read as where it leads, so that is what it is judged as too. `canonical` gives back a link it can't
+ // follow, as to a disk that isn't connected, which is judged as itself.
+ if folder.isSymbolicLink {
+ let place = PathPattern.canonical(folder)
+ if !place.isSymbolicLink, let refusal = refusal(of: place, home: home, isInTheCloud: isInTheCloud) {
+ return refusal
+ }
}
let path = folded(folder)
let library = folded(home) + "/library"
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift
index 3e973584..8ea22e5e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppFoldersTests.swift
@@ -20,6 +20,8 @@ struct AppFoldersTests {
#expect(AppFolders.refusal(of: try link("one", to: "home/Applications"), home: home) == .alreadyLookedIn)
#expect(AppFolders.refusal(of: try link("two", to: "home/.Trash/Old"), home: home) == .inATrash)
#expect(AppFolders.refusal(of: try link("three", to: "elsewhere"), home: home) == nil)
+ #expect(AppFolders.refusal(of: try link("nowhere", to: "/Volumes/org-example-not-connected/Apps"), home: home) == nil)
+ #expect(AppFolders.refusal(of: try link("round", to: "round"), home: home) == nil)
}
/// A folder chosen for apps is looked through three levels deep. The whole disk, the home folder or a folder