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
Let the Time Machine switch of a project turn off again
Țugui Dragoș889002994216
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swiftindex 0418d9c1..0787fe1a 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift@@ -60,11 +60,30 @@ public enum ProjectArtifacts {return artifacts.compactMap(\.lastActivity).max().map { .at($0) } ?? .none}- /// The artifacts to leave out of Time Machine: never one with a generic name, since the mark travels with the- /// folder, even into a copy of it (`man tmutil`), and never an environment, which holds what no build makes- /// again (`.terraform` keeps the chosen workspace and the backend's settings).- public static func markableForBackups(_ artifacts: [ProjectArtifact], excludedFromAbove: Set<URL>) -> [URL] {- artifacts.filter { !$0.hasGenericName && !$0.isEnvironment && !excludedFromAbove.contains($0.url) }.map(\.url)+ public struct BackupMarks: Sendable, Equatable {+ /// What turning the Time Machine switch on leaves out of backups: never a folder with a generic name, since the+ /// mark travels with the folder, even into a copy of it (`man tmutil`), and never an environment, which holds+ /// what no build makes again (`.terraform` keeps the chosen workspace and the backend's settings).+ public let markable: [URL]+ /// The folders carrying Peel's own mark, which turning the switch off takes away.+ public let marked: [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>) {+ let considered = artifacts.filter { !$0.hasGenericName && !$0.isEnvironment }.map(\.url)+ markable = considered.filter { !excludedFromAbove.contains($0) }+ marked = artifacts.map(\.url).filter { excluded.contains($0) && !excludedFromAbove.contains($0) }+ shown = considered + marked.filter { !considered.contains($0) }+ self.excluded = excluded+ }++ /// On while everything the switch is about is left out of backups, what Peel marked before included.+ public var isOn: Bool { !shown.isEmpty && shown.allSatisfy(excluded.contains) }+ public var canChange: Bool { !markable.isEmpty || !marked.isEmpty }++ public func folders(turning isOn: Bool) -> [URL] { isOn ? markable : marked }}struct Definition: Sendable {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swiftindex b79a863a..4a29f1d1 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift@@ -81,12 +81,41 @@ struct ProjectArtifactsTests {let pods = artifact("Pods", isGeneric: false)let terraform = artifact(".terraform", isGeneric: false, isEnvironment: true)- #expect(ProjectArtifacts.markableForBackups([target], excludedFromAbove: []).isEmpty)- #expect(ProjectArtifacts.markableForBackups([terraform], excludedFromAbove: []).isEmpty, "no build makes it")- #expect(- ProjectArtifacts.markableForBackups([target, modules, pods], excludedFromAbove: [pods.url]) == [modules.url]- )- #expect(ProjectArtifacts.markableForBackups([modules], excludedFromAbove: [modules.url]).isEmpty)+ func markable(_ artifacts: [ProjectArtifact], excludedFromAbove: Set<URL> = []) -> [URL] {+ ProjectArtifacts.BackupMarks(artifacts, excluded: excludedFromAbove, excludedFromAbove: excludedFromAbove)+ .markable+ }++ #expect(markable([target]).isEmpty)+ #expect(markable([terraform]).isEmpty, "no build makes it")+ #expect(markable([target, modules, pods], excludedFromAbove: [pods.url]) == [modules.url])+ #expect(markable([modules], excludedFromAbove: [modules.url]).isEmpty)+ }++ @Test func theBackupSwitchShowsAndTakesOffWhatPeelMarked() {+ func artifact(_ name: String, isGeneric: Bool = false, isEnvironment: Bool = false) -> ProjectArtifact {+ ProjectArtifact(+ url: URL(filePath: "/Users/x/Code/App/\(name)"), project: URL(filePath: "/Users/x/Code/App"), name: name,+ tool: "tool", size: 10, lastActivity: nil, hasGenericName: isGeneric, isEnvironment: isEnvironment+ )+ }+ let modules = artifact("node_modules")+ 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)+ }++ #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], excludedFromAbove: [modules.url], of: [modules]).isOn)+ #expect(!marks(excluded: [modules.url], excludedFromAbove: [modules.url], of: [modules]).canChange)}@Test func saysWhenAProjectLastChangedOnlyWhenItKnows() {diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swiftindex 98092bd5..9808a14f 100644--- a/Peel/Model/ProjectLibrary.swift+++ b/Peel/Model/ProjectLibrary.swift@@ -121,11 +121,14 @@ final class ProjectLibrary {await refresh()}- /// True when every artifact the checkbox acts on is excluded from backups. Artifacts with a generic name- /// are never excluded by it, so they are not counted.+ private func backupMarks(_ group: ProjectGroup) -> ProjectArtifacts.BackupMarks {+ ProjectArtifacts.BackupMarks(+ group.artifacts, excluded: excludedFromBackups, excludedFromAbove: excludedFromAbove+ )+ }+func isExcludedFromBackups(_ group: ProjectGroup) -> Bool {- let marked = group.artifacts.filter { !$0.hasGenericName }- return !marked.isEmpty && marked.allSatisfy { excludedFromBackups.contains($0.url) }+ backupMarks(group).isOn}/// The group's folders that would not take the mark the last time Peel set it.@@ -133,15 +136,14 @@ final class ProjectLibrary {group.artifacts.map(\.url).filter(backupMarkFailures.contains)}- /// False when no artifact of the group can take the mark, so the checkbox has nothing to change.func canMarkForBackups(_ group: ProjectGroup) -> Bool {- !ProjectArtifacts.markableForBackups(group.artifacts, excludedFromAbove: excludedFromAbove).isEmpty+ backupMarks(group).canChange}/// Excludes the group's artifacts from Time Machine backups, or includes them again, so a backup holds the/// project and not what a build can make again.func setExcludedFromBackups(_ isExcluded: Bool, in group: ProjectGroup) {- let urls = ProjectArtifacts.markableForBackups(group.artifacts, excludedFromAbove: excludedFromAbove)+ let urls = backupMarks(group).folders(turning: isExcluded)let failed = TimeMachineExclusion.setExcluded(isExcluded, urls)backupMarkFailures = backupMarkFailures.subtracting(urls).union(failed)let changed = Set(urls).subtracting(failed)