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
Hold back a cache something wrote to in the last 15 minutes
Țugui Dragoș91f9b054ba8d
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex a0ecd1cf..c41a5e49 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -89517,6 +89517,112 @@}}},+ "Not selected: something wrote to this in the last 15 minutes, so a program may still be using it." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nevybráno: do této mezipaměti za posledních 15 minut něco zapsalo, takže ji nějaký program možná ještě používá."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nicht ausgewählt: In dieses Objekt wurde innerhalb der letzten 15 Minuten geschrieben, daher wird es möglicherweise noch von einem Programm verwendet."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Sin seleccionar: algo ha escrito aquí en los últimos 15 minutos, así que puede que un programa aún lo esté usando."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Non sélectionné : quelque chose a écrit dans ce cache au cours des 15 dernières minutes, un programme l’utilise donc peut-être encore."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Non selezionato: qualcosa ci ha scritto dentro negli ultimi 15 minuti, quindi un programma potrebbe ancora usarlo."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未選択: 過去15分以内に書き込みがあったため、ほかのプログラムがこれをまだ使用中の可能性があります。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "선택되지 않음: 지난 15분 사이에 무언가가 이 캐시에 기록했으므로, 어떤 프로그램이 아직 이 캐시를 사용하고 있을 수 있습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Niet geselecteerd: hier is in de afgelopen 15 minuten iets in geschreven, dus een programma gebruikt het misschien nog."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nie zaznaczono: w ciągu ostatnich 15 minut coś zapisało dane w tej pamięci podręcznej, więc jakiś program może z niej jeszcze korzystać."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Não selecionado: algo gravou neste item nos últimos 15 minutos, então um programa pode ainda estar usando-o."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Neselectat: ceva a scris în această memorie tampon în ultimele 15 minute, așa că un program o poate utiliza încă."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не выбрано: за последние 15 минут в этот кэш что-то записывалось, поэтому, возможно, какая-то программа еще использует его."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Inte markerad: något har skrivit till den här cachen under de senaste 15 minuterna, så ett program kanske fortfarande använder den."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seçilmedi: bu önbelleğe son 15 dakika içinde bir şey yazıldı, bu nedenle bir program onu hâlâ kullanıyor olabilir."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не вибрано: щось записувало в цей кеш за останні 15 хвилин, тож, можливо, якась програма ще ним користується."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未选择:此缓存在过去15分钟内被写入过,因此某个程序可能仍在使用它。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未選取:此項目在過去15分鐘內有資料寫入,因此某個程式可能仍在使用它。"+ }+ }+ }+ },"Not selected: the app is running and may install this update when it quits." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swiftindex 01975db4..63b4c81f 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift@@ -346,6 +346,7 @@ extension HoldBack {case .inTheCloud: "in iCloud Drive, so moving it removes it from every device"case .openInAProgram: "open in a program right now, which may still be downloading it"case .changedRecently: "changed in the last day, so it may still be downloading"+ case .writtenRecently: "written to in the last 15 minutes, so a program may still be using it"case .keptByAnApp: "in an app's folder in Application Support, and the app may still need it"case .appIsRunning: "its app is running and may install this update when it quits"case .mayBeTheOnlyCopy: "outside Downloads and no installed app's installer, so it may be yours, not a download"diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swiftindex 8adccbcf..52778fee 100644--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift@@ -114,6 +114,8 @@ public enum HoldBack: String, Sendable, Hashable {case openInAProgram/// A download that changed within the last day, which may still be going.case changedRecently+ /// A cache something wrote to in the last few minutes, which a program may still be using.+ case writtenRecently/// An installer package in a folder an app keeps in Application Support, which the app may still need.case keptByAnApp/// An update whose app is running, which may install it when it quits.diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swiftindex d392931e..c118c394 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift@@ -96,6 +96,8 @@ public enum SpaceRemoval {let beyond: HoldBack? = needsAnAdministrator && reach.isBeyond(child) ? .beyondTheHelper : nilheldBack[child] = beyond ?? item.heldBack?? (systemCaches.keeps(child) ? .keptByMacOS : HoldBack.seen(in: contents))+ ?? (item.holdsBackRecentWrites && wasWrittenRecently(child, contents: contents)+ ? .writtenRecently : nil)}return Plan(removable: children.removable,@@ -106,6 +108,17 @@ public enum SpaceRemoval {)}+ /// How long a cache counts as in use after something wrote to it.+ static let stillInUse: TimeInterval = 15 * 60++ /// True when `child` or anything inside it was written within `stillInUse`. A walk dates what is inside, and the+ /// folder's own date moves when an entry is added or removed.+ private static func wasWrittenRecently(_ child: URL, contents: FolderContents?) -> Bool {+ let own = (try? child.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate+ guard let written = [own, contents?.newestChange].compactMap(\.self).max() else { return false }+ return Date.now.timeIntervalSince(written) < stillInUse+ }+@concurrentpublic static func sizesLeftToDeveloper(in plan: Plan) async -> [URL: Int64] {await sizesLeftToDeveloper(in: plan, measure: LeftoverScanner.walk)diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swiftindex 962948ef..97e75405 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift@@ -31,6 +31,9 @@ public struct SpaceItem: Sendable, Hashable, Identifiable {/// True when what macOS keeps in its folders for its own services is neither measured nor offered: there they run/// as other accounts, whose open files Peel cannot see, or keep caches not even Full Disk Access can read.public var leavesMacOSsOwn = false+ /// True when a child something wrote to in the last few minutes is held back (`SpaceRemoval.stillInUse`): Peel+ /// knows an open app's caches only by the app's names, and a program may write under a name of its own.+ public var holdsBackRecentWrites = false/// The folders of `urls` where macOS files reports into folders of its own, so only their files are offered.public var onlyFilesIn: [URL] = []/// The commands that free an area Peel leaves alone, as its tool's documentation gives them. Peel shows them to@@ -122,6 +125,7 @@ public enum SpaceInventory {var isTheUserCacheFolder = falsevar heldBack: HoldBack?var leavesMacOSsOwn = false+ var holdsBackRecentWrites = falsevar onlyFilesIn: [String] = []var commands: [Command] = []var managedBy: ManagingApps?@@ -329,7 +333,8 @@ public enum SpaceInventory {id: "caches",category: .library,paths: ["Library/Caches"],- handling: .trash+ handling: .trash,+ holdsBackRecentWrites: true),// macOS empties this folder only in a safe boot (`man confstr`). Apps' helpers keep caches in it, and so do// macOS's own services, some of them where not even Full Disk Access reaches.@@ -339,7 +344,8 @@ public enum SpaceInventory {paths: [],handling: .trash,isTheUserCacheFolder: true,- leavesMacOSsOwn: true+ leavesMacOSsOwn: true,+ holdsBackRecentWrites: true),Definition(id: "container-caches",@@ -553,6 +559,7 @@ public enum SpaceInventory {handling: definition.handling,heldBack: definition.heldBack,leavesMacOSsOwn: definition.leavesMacOSsOwn,+ holdsBackRecentWrites: definition.holdsBackRecentWrites,onlyFilesIn: definition.onlyFilesIn(home: home, root: root),commands: definition.commands.filter { $0.isKnown(simctlRuntimeHelp: help) }.map(\.line),managingAppIsMissing: definition.managedBy.map { !$0.oneIsOnThisMac } ?? falsediff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swiftindex d8fe20c7..47d63be2 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift@@ -158,6 +158,36 @@ struct SpaceRemovalTests {#expect(names(Array(logged.suggested)) == ["com.apple.example"])}+ @Test func holdsBackACacheWrittenInTheLastMinutesInTheCacheAreasOnly() async throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let userCache = directory.url.appending(path: "C", directoryHint: .isDirectory)+ let anHourAgo = Date.now.addingTimeInterval(-3600)+ for folder in ["home/Library/Caches", "C", "home/Library/Logs"] {+ try directory.file("\(folder)/org.example.busy/data.db")+ let idle = try directory.file("\(folder)/org.example.idle/data.db")+ for url in [idle, idle.deletingLastPathComponent()] {+ try FileManager.default.setAttributes(+ [.modificationDate: anHourAgo], ofItemAtPath: url.path(percentEncoded: false)+ )+ }+ }+ var environment = environment(directory)+ environment.userCacheDirectory = userCache+ let report = await SpaceInventory.scan(+ home: home, root: directory.url.appending(path: "root"), userCache: userCache, minimumSize: 1,+ measure: FileSize.measure+ )++ for id in ["caches", "user-caches", "logs"] {+ let area = try #require(report.items.first { $0.id == id })+ let plan = await SpaceRemoval.plan(for: area, environment: environment, running: [:])+ let busy = try #require(plan.removable.first { $0.lastPathComponent == "org.example.busy" })+ #expect(plan.heldBack[busy] == (id == "logs" ? nil : .writtenRecently), "\(id)")+ #expect(plan.suggested.contains { $0.lastPathComponent == "org.example.idle" }, "\(id)")+ }+ }+@Test func leavesICloudsOwnStateInTheCachesAlone() async throws {let directory = try TemporaryDirectory()let state = ["CloudKit", "com.apple.bird", "com.apple.FileProviderDaemon.AppStoreService"]diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swiftindex 75b78f83..e2ced89f 100644--- a/Peel/Views/Presentation.swift+++ b/Peel/Views/Presentation.swift@@ -314,6 +314,8 @@ extension HoldBack {"Not selected: a program has this open right now, and may still be downloading it."case .changedRecently:"Not selected: this changed in the last day, so it may still be downloading."+ case .writtenRecently:+ "Not selected: something wrote to this in the last 15 minutes, so a program may still be using it."case .keptByAnApp:"Not selected: this is in a folder an app keeps in Application Support, and the app may still need it."case .appIsRunning:diff --git a/SAFETY.md b/SAFETY.mdindex 4a0890c8..0cdd2025 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -296,6 +296,9 @@ Never selected for you, even when found:boxes a tool keeps for you to install again, and an editor's saved state for a project that no longer exists.- A cache macOS keeps for its own services in `~/Library/Caches` (Spotlight's, the fonts') or in the container of one ofApple's apps.+- A cache in `~/Library/Caches`, or in the folder macOS gives your account for caches, that something wrote to in+ the last 15 minutes: Peel knows an open app's caches only by the app's names, and a program may still be using+ one under a name of its own.- `/Users/Shared`: it belongs to every account, not just yours.- A project you worked on this week, and a download that changed in the last day, which may still be going.- A folder with a repository, a wallet, a signing key, or a password database (KeePass's `.kdbx`, KeePassXC's `.keyx`)