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
Tell Peel's Time Machine mark from the one a tool put
Țugui Dragoș2d781b245243
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex a10fcccb..c8473d44 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -491,7 +491,7 @@ where a Homebrew install takes them from.| `~/Library/Caches/com.tuguidragos.Peel/Cache.db`, `fsCachedData/`, `~/Library/HTTPStorages/com.tuguidragos.Peel/`, `~/Library/HTTPStorages/com.tuguidragos.Peel.binarycookies` | What macOS's networking keeps for Sparkle's requests: a cache of their answers, what servers said about reaching them again, and a store of cookies that stays empty, since Peel accepts none (`PeelUpdater`). || `/private/var/db/com.tuguidragos.Peel.Helper/` | The helper's ledger of what it moved. || Peel's preferences | Settings, the day Peel was installed, what each tool found the last time it looked, the last answer of each update check, when Sparkle last looked for a new Peel, the Mac's model name (read once, under its model identifier), what Peel last learned of App Management, and what the tweaks, Terminal, and Git held before Peel changed them, so turning a setting off puts that back. |-| Outside Peel's own files | `~/.hushlogin` from the Terminal page; the Dock's two lists of icons (`persistent-apps` and `recent-apps`, through `DockTiles`); the settings Tweaks changes; Terminal's profiles and options; Git's settings; the Time Machine mark on each folder Build Artifacts leaves out of backups; and the background items disabled on the Background Items page, which launchd keeps disabled across restarts. |+| Outside Peel's own files | `~/.hushlogin` from the Terminal page; the Dock's two lists of icons (`persistent-apps` and `recent-apps`, through `DockTiles`); the settings Tweaks changes; Terminal's profiles and options; Git's settings; the Time Machine mark on each folder Build Artifacts leaves out of backups, with an attribute beside it that says Peel put it; and the background items disabled on the Background Items page, which launchd keeps disabled across restarts. |Remove Peel, in Settings, takes all of Peel's own files to the Trash but `Terminal/`, the settings zsh and ssh readthrough the user's own lines (`SelfRemoval`), gathered first into one folder named Peel so the Trash shows one item,diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swiftindex 441cca6e..4be7ef20 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift@@ -83,24 +83,28 @@ public enum ProjectArtifacts {/// no build makes again (`.terraform` keeps the chosen workspace and the backend's settings), and never one/// held back, whose hold back says a build does not make all of it again.public let markable: [URL]- /// The folders carrying Peel's own mark, which turning the switch off takes away.+ /// The folders carrying a mark that is Peel's to take away when the switch goes off: one it could have put, so+ /// the switch can put it back, or one it says it put.public let marked: [URL]- /// The folders whose own mark is another's: Peel never marks a folder with a generic name, so a mark on one is- /// its tool's, as Cargo marks `target`, or the person's. The switch neither shows it nor takes it away.+ /// The folders whose own mark is another's: on what Peel never marks a mark is its tool's, as Cargo marks+ /// `target` and Poetry each environment, or the person's. The switch neither shows it nor takes it away.public let markedByOthers: [URL]private let shown: [URL]private let excluded: Set<URL>/// `excludedFromAbove`: what Time Machine leaves out through a folder above or a rule of its own, not Peel's.- public init(_ artifacts: [ProjectArtifact], excluded: Set<URL>, excludedFromAbove: Set<URL>) {+ public init(+ _ artifacts: [ProjectArtifact], excluded: Set<URL>, excludedFromAbove: Set<URL>, markedByPeel: Set<URL> = []+ ) {let considered = artifacts.filter { !$0.hasGenericName && !$0.isEnvironment && $0.heldBack == nil }.map(\.url)let markedItself = { (artifact: ProjectArtifact) inexcluded.contains(artifact.url) && !excludedFromAbove.contains(artifact.url)}markable = considered.filter { !excludedFromAbove.contains($0) }- marked = artifacts.filter { markedItself($0) && !$0.hasGenericName }.map(\.url)- markedByOthers = artifacts.filter { markedItself($0) && $0.hasGenericName }.map(\.url)+ let isPeels = { (url: URL) in considered.contains(url) || markedByPeel.contains(url) }+ marked = artifacts.filter { markedItself($0) && isPeels($0.url) }.map(\.url)+ markedByOthers = artifacts.filter { markedItself($0) && !isPeels($0.url) }.map(\.url)shown = considered + marked.filter { !considered.contains($0) }self.excluded = excluded}diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/TimeMachineExclusion.swift b/Packages/PeelCore/Sources/PeelCore/Developer/TimeMachineExclusion.swiftindex 9a6a422c..874cbbdd 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/TimeMachineExclusion.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/TimeMachineExclusion.swift@@ -8,13 +8,19 @@ internal import CoreServices/// It uses `CSBackupSetItemExcluded`, Apple's API for this, rather than `tmutil addexclusion`, which is slow/// and fails in a process that macOS hasn't given Full Disk Access.public enum TimeMachineExclusion {+ /// Written beside the mark Peel puts, since the mark itself says nothing of who put it.+ private static let ownMark = "com.tuguidragos.Peel.backupMark"+/// Whether Time Machine backs up a folder, and if not, where the exclusion comes from. Per `BackupCore.h`,/// `CSBackupIsItemExcluded` answers true "if the item or any of its ancestors are excluded" and says/// whether the exclusion is by path. Only a mark on the folder itself can be taken off from here.public enum Standing: Sendable, Hashable {case included- /// The mark is on this folder, so Peel can take it off again.+ /// The mark is on this folder, and nothing says who put it: a tool, as Poetry marks each environment it makes+ /// and Xcode its DerivedData, the person, or a version of Peel that didn't say.case excludedItself+ /// The mark is on this folder, and Peel put it.+ case markedByPeel/// A folder above it is excluded, or the exclusion is on the path rather than on this folder.case excludedFromAbove}@@ -26,7 +32,8 @@ public enum TimeMachineExclusion {guard !byPath.boolValue, !CSBackupIsItemExcluded(url.deletingLastPathComponent() as CFURL, nil) else {return .excludedFromAbove}- return .excludedItself+ return getxattr(url.path(percentEncoded: false), ownMark, nil, 0, 0, XATTR_NOFOLLOW) >= 0+ ? .markedByPeel : .excludedItself}public static func isExcluded(_ url: URL) -> Bool {@@ -47,6 +54,15 @@ public enum TimeMachineExclusion {/// Sets or clears the mark on each folder and returns the folders that could not be changed. A folder/// that refuses the mark, such as one owned by root, does not stop the others.public static func setExcluded(_ isExcluded: Bool, _ urls: [URL]) -> Set<URL> {- Set(urls.filter { CSBackupSetItemExcluded($0 as CFURL, isExcluded, false) != noErr })+ Set(urls.filter { url in+ guard CSBackupSetItemExcluded(url as CFURL, isExcluded, false) == noErr else { return true }+ let path = url.path(percentEncoded: false)+ if isExcluded {+ _ = setxattr(path, ownMark, "1", 1, 0, XATTR_NOFOLLOW)+ } else {+ _ = removexattr(path, ownMark, XATTR_NOFOLLOW)+ }+ return false+ })}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swiftindex 13db0139..c5a508a9 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift@@ -129,17 +129,30 @@ struct ProjectArtifactsTests {let venv = artifact(".venv", isEnvironment: true)let target = artifact("target", isGeneric: true)let artifacts = [modules, venv, target]- func marks(excluded: Set<URL>, excludedFromAbove: Set<URL> = [], of list: [ProjectArtifact] = artifacts)- -> ProjectArtifacts.BackupMarks {- ProjectArtifacts.BackupMarks(list, excluded: excluded, excludedFromAbove: excludedFromAbove)+ func marks(+ excluded: Set<URL>, excludedFromAbove: Set<URL> = [], markedByPeel: Set<URL> = [],+ of list: [ProjectArtifact] = artifacts+ ) -> ProjectArtifacts.BackupMarks {+ ProjectArtifacts.BackupMarks(+ list, excluded: excluded, excludedFromAbove: excludedFromAbove, markedByPeel: markedByPeel+ )}#expect(!marks(excluded: []).isOn)#expect(marks(excluded: []).folders(turning: true) == [modules.url])#expect(marks(excluded: [modules.url]).isOn, "a project with an environment read off once marked")#expect(marks(excluded: [modules.url]).folders(turning: false) == [modules.url])- #expect(Set(marks(excluded: [modules.url, venv.url]).folders(turning: false)) == [modules.url, venv.url])- #expect(marks(excluded: [venv.url], of: [venv]).isOn && marks(excluded: [venv.url], of: [venv]).canChange)+ #expect(marks(excluded: [modules.url, venv.url]).folders(turning: false) == [modules.url])+ let poetry = marks(excluded: [venv.url], of: [venv])+ #expect(!poetry.isOn && !poetry.canChange, "a tool's mark on an environment isn't Peel's to take off")+ #expect(poetry.markedByOthers == [venv.url])+ #expect(poetry.folders(turning: false).isEmpty)+ var held = modules+ held.heldBack = .notMeasured+ let xcode = marks(excluded: [held.url], of: [held])+ #expect(!xcode.isOn && !xcode.canChange && xcode.markedByOthers == [held.url])+ let own = marks(excluded: [held.url], markedByPeel: [held.url], of: [held])+ #expect(own.isOn && own.canChange && own.folders(turning: false) == [held.url] && own.markedByOthers.isEmpty)#expect(marks(excluded: [modules.url], excludedFromAbove: [modules.url], of: [modules]).isOn)#expect(!marks(excluded: [modules.url], excludedFromAbove: [modules.url], of: [modules]).canChange)}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TimeMachineExclusionTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TimeMachineExclusionTests.swiftindex 834105ab..c164b8c9 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/TimeMachineExclusionTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/TimeMachineExclusionTests.swift@@ -33,7 +33,7 @@ struct TimeMachineExclusionTests {#expect(!TimeMachineExclusion.isExcluded(modules))#expect(TimeMachineExclusion.setExcluded(true, [modules, build]).isEmpty, "a folder refused the mark")#expect(try await settles([modules, build], as: [modules, build]), "\(state(of: [modules, build]))")- #expect(TimeMachineExclusion.standing(of: modules) == .excludedItself)+ #expect(TimeMachineExclusion.standing(of: modules) == .markedByPeel)#expect(TimeMachineExclusion.setExcluded(false, [modules]).isEmpty)#expect(try await settles([modules, build], as: [build]), "\(state(of: [modules, build]))")@@ -44,6 +44,26 @@ struct TimeMachineExclusionTests {#expect(try await settles([modules, build], as: []), "\(state(of: [modules, build]))")}+ @Test func knowsTheMarkPeelPutFromATools() async throws {+ let directory = try TemporaryDirectory()+ let modules = try directory.directory("app/node_modules")+ let venv = try directory.directory("app/.venv")+ // What Poetry writes on each environment it makes.+ let mark = try PropertyListSerialization.data(fromPropertyList: "com.apple.backupd", format: .binary, options: 0)+ let name = "com.apple.metadata:com_apple_backup_excludeItem"+ let path = venv.path(percentEncoded: false)+ #expect(mark.withUnsafeBytes { setxattr(path, name, $0.baseAddress, $0.count, 0, 0) } == 0)++ #expect(TimeMachineExclusion.setExcluded(true, [modules]).isEmpty)+ #expect(try await settles([modules, venv], as: [modules, venv]), "\(state(of: [modules, venv]))")+ #expect(TimeMachineExclusion.standing(of: venv) == .excludedItself)+ #expect(TimeMachineExclusion.standing(of: modules) == .markedByPeel)++ #expect(TimeMachineExclusion.setExcluded(false, [modules]).isEmpty)+ #expect(try await settles([modules, venv], as: [venv]), "\(state(of: [modules, venv]))")+ #expect(TimeMachineExclusion.standing(of: modules) == .included)+ }+@Test func answersWithoutComplainingForAnEmptyListOrAMissingFolder() throws {let directory = try TemporaryDirectory()let missing = directory.url.appending(path: "nothing-here")diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swiftindex 8dbb0879..a0a2f281 100644--- a/Peel/Model/ProjectLibrary.swift+++ b/Peel/Model/ProjectLibrary.swift@@ -28,6 +28,7 @@ final class ProjectLibrary {private(set) var folders: [URL]/// Which artifacts Time Machine is already leaving out.private(set) var excludedFromBackups: Set<URL> = []+ private var markedByPeel: Set<URL> = []/// Artifacts excluded from backups by a folder above them or by a path rule. The exclusion is not their/// own, so it cannot be removed from here.private(set) var excludedFromAbove: Set<URL> = []@@ -105,6 +106,7 @@ final class ProjectLibrary {groups = resultexcludedFromBackups = Set(standings.filter { $0.value != .included }.keys)excludedFromAbove = Set(standings.filter { $0.value == .excludedFromAbove }.keys)+ markedByPeel = Set(standings.filter { $0.value == .markedByPeel }.keys)selectedURLs.formIntersection(Set(artifacts.map(\.url)))if let selection, !result.contains(where: { $0.project == selection }) {self.selection = nil@@ -156,7 +158,8 @@ final class ProjectLibrary {private func backupMarks(_ group: ProjectGroup) -> ProjectArtifacts.BackupMarks {ProjectArtifacts.BackupMarks(- group.artifacts, excluded: excludedFromBackups, excludedFromAbove: excludedFromAbove+ group.artifacts, excluded: excludedFromBackups, excludedFromAbove: excludedFromAbove,+ markedByPeel: markedByPeel)}@@ -186,8 +189,10 @@ final class ProjectLibrary {let changed = Set(urls).subtracting(failed)if isExcluded {excludedFromBackups.formUnion(changed)+ markedByPeel.formUnion(changed)} else {excludedFromBackups.subtract(changed)+ markedByPeel.subtract(changed)}}diff --git a/SAFETY.md b/SAFETY.mdindex 8372915d..29b5233a 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -265,7 +265,7 @@ Some of what Peel does is not a move to the Trash. Each is here with how it is u| Homebrew upgrades a package, updates itself and its taps, or repairs its taps' links (Upgrade, Upgrade All, Update, Repair Taps) | Not through History: an upgrade replaces the version that was installed, and the earlier versions of a formula stay until you clean up || An app that would not quit is force quit, only when you choose it | Can't be undone: what the app had not saved is lost || Remove Downloads frees this Mac's copy of a file in iCloud Drive | The file stays in iCloud and downloads again when you open it |-| Build Artifacts leaves a project's build folders out of Time Machine, when you ask it to | The same checkbox takes the mark off |+| Build Artifacts leaves a project's build folders out of Time Machine, when you ask it to | The same checkbox takes the mark off, and leaves alone a mark a tool put on what Peel never marks || A background item is stopped, started, disabled, or enabled | The same buttons in Background Items; a disabled item stays disabled after a restart until you enable it || A background job a deleted app left loaded is removed (`launchctl bootout`), on macOS 27 | Nothing to bring back: its app, and what the job ran, are gone || A tweak changes a setting of macOS, and the Dock, Finder, Control Center, or the window manager restarts to read it (`killall`, which for Finder stops anything it is copying) | Turning the tweak off puts back what was there before, or leaves it to macOS. Turn All Off puts back only what Peel changed, and leaves what you set yourself as it is |