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
The deep search says which folders it could not look into
Țugui Dragoș51e8e1b49fd5
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swiftindex b017b970..305d94d0 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift@@ -91,9 +91,10 @@ public struct LeftoverScanner: Sendable {var cutShortLocations: [SearchLocation] = []for (location, result) in results {switch result {- case .found(let leftovers, let cutShort):+ case .found(let leftovers, let cutShort, let unreadable):found.append((location, leftovers))if let cutShort { cutShortLocations.append(cutShort) }+ unreadableLocations += unreadablecase .unreadable(let location):unreadableLocations.append(location)}@@ -135,8 +136,9 @@ public struct LeftoverScanner: Sendable {}private enum LocationResult: Sendable {- /// `cutShort` is the location itself when the search inside its folders hit the limit.- case found([Leftover], cutShort: SearchLocation?)+ /// `cutShort` is the location itself when the search inside its folders hit the limit, and `unreadable` the+ /// folders inside it that search could not look into.+ case found([Leftover], cutShort: SearchLocation?, unreadable: [SearchLocation])case unreadable(SearchLocation)}@@ -169,7 +171,7 @@ public struct LeftoverScanner: Sendable {entries = try FileManager.default.contentsOfDirectory(atPath: location.url.path(percentEncoded: false)).sorted()ScanCount.current?.add(entries.count)} catch CocoaError.fileReadNoSuchFile {- return .found([], cutShort: nil)+ return .found([], cutShort: nil, unreadable: [])} catch {return .unreadable(location)}@@ -198,7 +200,10 @@ public struct LeftoverScanner: Sendable {in: nobodysFolders, kind: location.kind, matcher: matcher, home: home, measure: measure, refuses: refuses,limit: nestedFolderLimit)- return .found(leftovers + inside.found, cutShort: inside.wasCutShort ? location : nil)+ return .found(+ leftovers + inside.found, cutShort: inside.wasCutShort ? location : nil,+ unreadable: inside.unreadable.map { SearchLocation(kind: location.kind, url: $0) }+ )}/// Looks up to two levels inside the folders not taken as the app's. Only a match strong enough to name the@@ -211,18 +216,29 @@ public struct LeftoverScanner: Sendable {measure: Measure,refuses: Refuses,limit: Int- ) async -> (found: [Leftover], wasCutShort: Bool) {+ ) async -> (found: [Leftover], wasCutShort: Bool, unreadable: [URL]) {var found: [Leftover] = []+ var unreadable: [URL] = []var pending = foldersvar visited = 0for depth in 0..<nestedDepth {var deeper: [(url: URL, isAnotherApps: Bool)] = []for (folder, isAnotherApps) in pending {- guard !Task.isCancelled else { return (found, false) }- guard visited < limit else { return (found, true) }+ guard !Task.isCancelled else { return (found, false, unreadable) }+ guard visited < limit else { return (found, true, unreadable) }visited += 1- guard let names = try? FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false)).sorted() else { continue }+ let names: [String]+ do {+ names = try FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false))+ .sorted()+ } catch CocoaError.fileReadNoSuchFile {+ continue+ } catch {+ // It may hold the app's files, so it is said rather than passed over as empty.+ unreadable.append(folder)+ continue+ }ScanCount.current?.add(names.count)let parent = ParentAccess(folder)@@ -240,7 +256,7 @@ public struct LeftoverScanner: Sendable {}pending = deeper}- return (found, false)+ return (found, false, unreadable)}/// Builds a leftover: measures it and decides whether to hold it back. The scan, cask paths, and installerdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swiftindex c56723ee..df0b0550 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift@@ -344,6 +344,21 @@ struct LeftoverScannerTests {#expect(scan.unreadableLocations.map(\.kind) == [.logs])}+ /// A vendor's folder the deep search cannot look into may hold the app's files, so the scan says it could not+ /// read it rather than passing over it as if it held nothing.+ @Test(.permissionsHold) func reportsAFolderTheDeepSearchCannotLookInto() async throws {+ let directory = try TemporaryDirectory()+ try directory.file("home/Library/Application Support/Vendor/Tunewell/state.db")+ try directory.setPermissions(0o000, of: "home/Library/Application Support/Vendor")+ defer { try? directory.setPermissions(0o755, of: "home/Library/Application Support/Vendor") }++ let scanner = LeftoverScanner(environment: environment(in: directory))+ let scan = await scanner.scan(tunewell, installedApps: [tunewell])++ #expect(scan.unreadableLocations.map(\.url.lastPathComponent) == ["Vendor"])+ #expect(scan.unreadableLocations.map(\.kind) == [.applicationSupport])+ }+@Test(.permissionsHold) func flagsItemsInReadOnlyLocationsAsRequiringPrivileges() async throws {let directory = try TemporaryDirectory()try directory.file("root/Library/LaunchDaemons/net.example.client.helper.plist")