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.

An installer holding something excluded is left out

Țugui Dragoș141d32d49c9c
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
index b187ca9d..062283bc 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
@@ -118,7 +118,7 @@ public enum Installers {
let isArchive = suffix == "zip"
let isIncomplete = incompleteDownloadExtensions.contains(suffix)
guard isInstaller || isArchive || isIncomplete || firmwareExtensions.contains(suffix),
- !exclusions.excludes(url), !Task.isCancelled
+ !exclusions.excludes(url), !exclusions.holds(url), !Task.isCancelled
else { continue }
let (size, seen) = await measured(url, by: measure)
guard isWorthARow(size, minimumSize) else { continue }
@@ -349,7 +349,7 @@ public enum Installers {
for url in files(in: folder.url)
where url.pathExtension.lowercased() == "app" && url.lastPathComponent.hasPrefix("Install macOS") {
guard !Task.isCancelled else { return items }
- guard !exclusions.excludes(url) else { continue }
+ guard !exclusions.excludes(url), !exclusions.holds(url) else { continue }
let (size, seen) = await measured(url, by: measure)
guard isWorthARow(size, minimumSize) else { continue }
let version = AppInspector.infoDictionary(in: url.appending(path: "Contents", directoryHint: .isDirectory))?["CFBundleShortVersionString"] as? String
@@ -378,7 +378,7 @@ public enum Installers {
for folder in folders {
for url in files(in: folder) where firmwareExtensions.contains(url.pathExtension.lowercased()) {
guard !Task.isCancelled else { return items }
- guard !exclusions.excludes(url) else { continue }
+ guard !exclusions.excludes(url), !exclusions.holds(url) else { continue }
let (size, heldBack) = await measured(url, by: measure)
guard isWorthARow(size, minimumSize) else { continue }
items.append(firmware(at: url, size: size, heldBack: heldBack))
@@ -420,7 +420,7 @@ public enum Installers {
var items: [InstallerItem] = []
for (url, identifier) in found {
guard !Task.isCancelled else { return items }
- guard !exclusions.excludes(url) else { continue }
+ guard !exclusions.excludes(url), !exclusions.holds(url) else { continue }
let (size, seen) = await measured(url, by: measure)
guard isWorthARow(size, minimumSize) else { continue }
let isRunning = !NSRunningApplication.runningApplications(withBundleIdentifier: identifier).isEmpty
@@ -466,7 +466,7 @@ public enum Installers {
}
continue
}
- guard !exclusions.excludes(url) else { continue }
+ guard !exclusions.excludes(url), !exclusions.holds(url) else { continue }
let (size, seen) = await measured(url, by: measure)
guard isWorthARow(size, minimumSize) else { continue }
let place = Folder(url: folder, isSharedWithEveryone: false)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
index 5ef0f470..d050c12e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
@@ -202,6 +202,25 @@ struct InstallersTests {
#expect(scan.items.map(\.name) == ["Tool-2.dmg"])
}
+ /// An installer that is a folder, with something the person excluded inside, is left out like any excluded
+ /// item: the guard would refuse to move it anyway.
+ @Test func leavesOutAnInstallerHoldingSomethingExcluded() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("Applications/Install macOS Tahoe.app/Contents/MacOS/app", bytes: 400_000)
+ let kept = try directory.file("Applications/Install macOS Tahoe.app/Contents/Resources/notes.txt", bytes: 16)
+ try directory.file("Downloads/Tool.pkg/Contents/Archive.pax.gz", bytes: 400_000)
+ let alsoKept = try directory.file("Downloads/Tool.pkg/Contents/Resources/license.txt", bytes: 16)
+ try directory.file("Downloads/Other-2.dmg", bytes: 400_000)
+
+ let exclusions = Exclusions(paths: [kept, alsoKept])
+ let scan = await Installers.scan(
+ installedApps: [], home: directory.url, root: directory.url, exclusions: exclusions, minimumSize: 100_000,
+ measure: LeftoverScanner.walk
+ )
+
+ #expect(scan.items.map(\.name) == ["Other-2.dmg"])
+ }
+
@Test func anInstallerInICloudDriveIsLeftForThePersonToChoose() async throws {
let directory = try TemporaryDirectory()
try directory.file("Documents/Tool-2.dmg", bytes: 400_000)