Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Never offer what is inside an app's document whose app is gone
Țugui Dragoș6d456ee64f4b
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swiftindex 6f2c3b2f..75632eea 100644--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift@@ -117,6 +117,28 @@ public struct DuplicateFinder: Sendable {ProtectedData.extensions.contains(url.pathExtension.lowercased())}+ /// Whether `url` is a document its app keeps as a package. Launch Services knows one as a package only while its+ /// app is installed, so these are named here, each from its maker, and a file inside one is never offered alone.+ static func isAnAppsDocument(_ url: URL) -> Bool {+ appDocuments.contains(url.pathExtension.lowercased())+ }++ private static let appDocuments: Set<String> = [+ // Logic Pro, "a package or a project folder": support.apple.com/guide/logicpro/lgcpce128e82+ "logicx",+ // MainStage, "concert package": support.apple.com/101568+ "mainstage",+ // Scrivener, "packages of files": scrivener.tenderapp.com/help/kb/macos/password-protecting-your-work+ "scriv",+ // DEVONthink, "databases are packages": its help, Repairing a defective database+ "dtbase2",+ // Capture One, "a .cocatalog package": support.captureone.com/hc/en-us/articles/11019291187997+ "cocatalog",+ // Lightroom Classic's preview caches beside a catalog:+ // helpx.adobe.com/lightroom-classic/desktop/kb/preference-file-and-other-file-locations.html+ "lrdata",+ ]+/// Finds folders whose whole contents are identical, then identical files. Files are compared by size, then/// by their first and last bytes, then by a SHA-256 of the whole file.@concurrent@@ -282,13 +304,14 @@ public struct DuplicateFinder: Sendable {}guard let values = try? url.resourceValues(forKeys: keys) else { return }if values.isDirectory == true {- // The enumerator does not treat a library as a package when its app is not installed, so- // libraries are skipped here: the guard would refuse every copy inside one. A folder- // already offered whole covers everything inside it, so its files are not offered again.+ // The enumerator does not treat a library or an app's document as a package when its app is+ // not installed, so they are skipped here: the guard would refuse every copy inside a library,+ // and a file taken from a document breaks it. A folder already offered whole covers+ // everything inside it, so its files are not offered again.if url.lastPathComponent == "node_modules" || excludedFolders.contains(Self.path(of: url))|| spokenFor.contains(Self.path(of: url))|| exclusions.excludes(url) || Self.isRepository(url) || Self.isAUserLibrary(url)- || isDataless(url) {+ || Self.isAnAppsDocument(url) || isDataless(url) {enumerator.skipDescendants()}returndiff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swiftindex 633f0797..b5a66e43 100644--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/FolderDuplicates.swift@@ -230,6 +230,7 @@ struct FolderDuplicates: Sendable {name: entry.lastPathComponent,identity: FileIdentity(info),isNeverOffered: isNeverOffered || Self.isHidden(entry, info) || entry.isAPackage+ || DuplicateFinder.isAnAppsDocument(entry))case S_IFREG:guard info.st_flags & UInt32(SF_DATALESS) == 0, !entry.isInTheCloud else { return .leftOut }diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackDuplicateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackDuplicateTests.swiftindex 55758c15..20e54ace 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackDuplicateTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackDuplicateTests.swift@@ -175,6 +175,28 @@ struct AttackDuplicateTests {#expect(result.failures.map(\.reason) == [.guarded(.protectedLocation)], "and the removal is refused")}+ @Test func neverOffersWhatIsInsideAnAppsDocumentWhoseAppIsGone() async throws {+ let contents = Data((0..<4_000).map { _ in UInt8.random(in: 0...255) })+ let one = try TemporaryDirectory()+ try one.file("home/Music/Song.logicx/Media/take.wav", contents: contents)+ try one.file("home/Desktop/take.wav", contents: contents)+ let many = try TemporaryDirectory()+ let documents = [+ "Song.logicx", "Gig.mainstage", "Novel.scriv", "Notes.dtBase2", "Shoot.cocatalog", "Catalog Previews.lrdata",+ ]+ for document in documents {+ try many.file("home/Music/\(document)/Media/take.wav", contents: contents)+ }++ let file = try await DuplicateFinder(homeDirectory: one.url.appending(path: "home"))+ .scan(.everySize(in: [one.url.appending(path: "home")]))+ let folders = try await DuplicateFinder(homeDirectory: many.url.appending(path: "home"))+ .scan(.everySize(in: [many.url.appending(path: "home")]))++ #expect(file.groups.isEmpty, "ATTACK SUCCEEDED: a file inside an app's document was offered")+ #expect(folders.groups.isEmpty && folders.folderGroups.isEmpty, "ATTACK SUCCEEDED: inside a document was offered")+ }+/// A media library whose app is not installed is a plain folder to the enumerator. A file inside one must not/// be offered, because the guard refuses to move it. The library is of a kind no app on this Mac registers as/// a package: an installed app's package would be skipped whole, and the test would never reach Peel's rule.diff --git a/SAFETY.md b/SAFETY.mdindex 005471e7..59f7e56f 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -469,7 +469,8 @@ In Duplicates, one copy of every group always stays, and a file that changed sinstarted ends, Duplicates selects every copy but the first of each group, the one it suggests keeping: check which copystays before you move the others. Nothing inside a repository, a project, `node_modules`, a photo or music library, anapp, or another package is ever offered, nor a hidden file or folder, such as a tool's settings in `~/.config`: they-only count toward the folder around them. Copies that differ in their Finder tags, their Finder comment, or their+only count toward the folder around them, a document its app keeps as a package among them, such as a Logic Pro or+Scrivener project, even once the app is gone. Copies that differ in their Finder tags, their Finder comment, or theirresource fork are not duplicates, since moving one would take that away, and a folder kept only in the cloud is neverlooked into. A copy in a folder that syncs to your other devices, iCloud Drive or one a sync app keeps in step, islisted and never selected or moved: its row reads Stays, and a group whose every copy syncs is listed under Synced to