Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Remove the folder an app's updater downloads into with the app

Țugui Dragoș6bd762538004
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index ae2ddc48..2c210253 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -178036,6 +178036,112 @@
}
}
},
+ "Where the app’s updater keeps its downloads" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Místo, kde aktualizátor aplikace uchovává stažené soubory"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Wo der Updater der App seine Downloads aufbewahrt"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La carpeta donde el actualizador de la app guarda sus descargas"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Emplacement où le programme de mise à jour de l’app conserve ses téléchargements"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dove il programma di aggiornamento dell’app conserva i suoi download"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "アプリのアップデータがダウンロードしたものを保管する場所"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "앱의 업데이터가 다운로드한 항목을 보관하는 위치"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Waar de updater van de app zijn downloads bewaart"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Miejsce, w którym oprogramowanie uaktualniające aplikacji przechowuje pobrane pliki"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Onde o atualizador do app guarda os downloads"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Locul unde programul de actualizare al aplicației își păstrează descărcările"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Здесь программа обновления приложения хранит свои загрузки"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Där appens uppdaterare sparar sina hämtningar"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Uygulamanın güncelleyicisinin indirdiklerini tuttuğu yer"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Тут засіб оновлення програми зберігає свої викачані файли"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "App的更新程序保留其下载内容的位置"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "App的更新程式存放其下載項目的位置"
+ }
+ }
+ }
+ },
"While Peel Runs" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 63b4c81f..82d4a4ff 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -275,6 +275,7 @@ extension MatchReason {
case .leadsIntoItsHomebrewReceipt: "leads into the Homebrew receipt"
case .homebrewCask: "Homebrew cask"
case .managedByTheApp: "managed by the app"
+ case .updaterDownloads: "where its updater keeps its downloads"
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index 52778fee..32c2c02b 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -26,6 +26,8 @@ public enum MatchReason: String, Sendable, Hashable {
/// What an area the app manages keeps in the home folder, such as the simulators Xcode makes
/// (`SpaceInventory.Definition.managedBy`).
case managedByTheApp
+ /// The folder the app's own settings name for what its updater downloads (`InstalledApp.updaterFolder`).
+ case updaterDownloads
}
public enum MatchConfidence: Int, Sendable, Hashable, Comparable {
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
index 514e6ecc..a638ac51 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverMatcher.swift
@@ -46,6 +46,23 @@ struct LeftoverMatcher: Sendable {
)
}
+ /// This app's claim on the folder electron-updater keeps its downloads in, which the app's own settings name:
+ /// `url` directly in one of its places under `home` (`ElectronUpdater.places`), whatever the app is called. It is
+ /// shared only with an app naming the same folder.
+ func updatersFolder(at url: URL, home: String) -> LeftoverMatch? {
+ guard let folder = target.updaterFolder, url.lastPathComponent.lowercased() == folder else { return nil }
+ let parent = PathComponents.of(url.deletingLastPathComponent().path(percentEncoded: false))
+ let home = PathComponents.of(home)
+ guard ElectronUpdater.places.contains(where: { parent == home + PathComponents.of($0) }) else { return nil }
+ let naming = others.filter { $0.updaterFolder == folder }
+ return LeftoverMatch(
+ reason: .updaterDownloads,
+ confidence: .certain,
+ sharedWith: Set(naming.filter { !$0.isACopy(of: target) }.map(\.reference)).sorted(),
+ otherCopies: naming.filter { $0.isACopy(of: target) }.map(\.url)
+ )
+ }
+
/// This app's claim on the item called `fileName` in a location of `kind`, found at `url` when the caller knows it.
func match(fileName: String, kind: SearchLocation.Kind, at url: URL? = nil) -> LeftoverMatch? {
let key = Self.key(from: fileName, kind: kind)
@@ -257,7 +274,7 @@ extension LeftoverMatcher {
family = switch reason {
case .bundleIdentifier, .embeddedBundleIdentifier, .applicationGroup, .bundleIdentifierPrefix,
.launchdJob, .linksToTheApp, .nativeMessagingHost, .installerReceipt, .homebrewReceipt,
- .leadsIntoItsHomebrewReceipt, .managedByTheApp:
+ .leadsIntoItsHomebrewReceipt, .managedByTheApp, .updaterDownloads:
.identifier
case .name, .namePrefix, .homebrewCask: .name
case .teamIdentifier, .vendorPrefix: .maker
@@ -280,7 +297,7 @@ extension LeftoverMatcher {
// A job's or a manifest's program, or a link's target, lies inside the app's bundle, which no other app
// can share.
case .launchdJob, .linksToTheApp, .nativeMessagingHost, .leadsIntoItsHomebrewReceipt: 8
- case .bundleIdentifier, .installerReceipt, .homebrewReceipt, .managedByTheApp: 7
+ case .bundleIdentifier, .installerReceipt, .homebrewReceipt, .managedByTheApp, .updaterDownloads: 7
case .embeddedBundleIdentifier, .applicationGroup: 6
case .bundleIdentifierPrefix: 5
case .name: 4
@@ -316,6 +333,7 @@ extension LeftoverMatcher {
let ownFolderNames: Set<String>
let isApplesOwn: Bool
let isASafariWebApp: Bool
+ let updaterFolder: String?
init(_ app: InstalledApp) {
url = app.url
@@ -340,6 +358,9 @@ extension LeftoverMatcher {
ownFolderNames = app.ownFolderNames
isApplesOwn = app.isSystemProtected || teamPrefix == Self.appleTeam
isASafariWebApp = app.isASafariWebApp
+ // Only the name electron-builder writes, the app's and `-updater`: the settings are whoever built the
+ // app's, and any other name could be a folder other programs share.
+ updaterFolder = app.updaterFolder.map { $0.lowercased() }.flatMap { $0.hasSuffix("-updater") ? $0 : nil }
}
/// Whether this is another copy of `other`: the same app, known by its identifier, somewhere else.
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index 49a9af6a..0e878cd9 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -222,7 +222,7 @@ public struct LeftoverScanner: Sendable {
guard !Task.isCancelled else { break }
let url = location.url.appending(path: name)
let path = url.path(percentEncoded: false)
- if let match = claim(name, at: url, kind: location.kind, matcher: matcher, bundle: bundle),
+ if let match = claim(name, at: url, kind: location.kind, matcher: matcher, bundle: bundle, home: home),
!isSharedWithTheWholeMac(url, home: home) {
guard !refuses(path, home), !exclusions.excludes(url), !FileAccess.cannotBeRemoved(url) else {
continue
@@ -265,7 +265,8 @@ public struct LeftoverScanner: Sendable {
let path = url.path(percentEncoded: false)
// A browser's manifest is whoever's program it runs, whatever it is called.
let match = url.deletingLastPathComponent().lastPathComponent.lowercased() == "nativemessaginghosts"
- ? runsSomethingInside(bundle, manifest: url) : Self.match(name, at: url, kind: kind, matcher: matcher)
+ ? runsSomethingInside(bundle, manifest: url)
+ : Self.match(name, at: url, kind: kind, matcher: matcher, home: home)
if let match, match.confidence >= .likely,
!isSharedWithTheWholeMac(url, home: home) {
guard !refuses(path, home), !exclusions.excludes(url) else { return .pass }
@@ -408,12 +409,13 @@ public struct LeftoverScanner: Sendable {
at url: URL,
kind: SearchLocation.Kind,
matcher: LeftoverMatcher,
- bundle: String
+ bundle: String,
+ home: String
) -> LeftoverMatch? {
guard !kind.isForLinks else { return leadsInside(bundle, link: url) }
guard kind != .nativeMessagingHosts else { return runsSomethingInside(bundle, manifest: url) }
guard let inside = runsSomethingInside(bundle, job: url, kind: kind) else {
- return match(name, at: url, kind: kind, matcher: matcher)
+ return match(name, at: url, kind: kind, matcher: matcher, home: home)
}
let byName = matcher.match(fileName: name, kind: kind, at: url)
return byName?.confidence == .certain ? byName : inside
@@ -426,10 +428,12 @@ public struct LeftoverScanner: Sendable {
_ name: String,
at url: URL,
kind: SearchLocation.Kind,
- matcher: LeftoverMatcher
+ matcher: LeftoverMatcher,
+ home: String
) -> LeftoverMatch? {
// A system extension macOS activated is its own to remove: it uninstalls one with the app it came in.
guard url.pathExtension.lowercased() != "systemextension" else { return nil }
+ if let updaters = matcher.updatersFolder(at: url, home: home) { return updaters }
let byName = DeclaredIdentifier.nameSaysNothing(of: url, kind: kind)
? nil : matcher.match(fileName: name, kind: kind, at: url)
guard byName == nil || DeclaredIdentifier.outranksTheName(of: url, kind: kind) else { return byName }
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift b/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift
index 315bb62f..18c0d68c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/ElectronUpdater.swift
@@ -4,6 +4,8 @@ enum ElectronUpdater {
/// Where electron-updater kept an app's downloads before version 6, relative to the home folder. Since then they
/// are in `~/Library/Caches` (`AppAdapter.ts`).
static let formerPlace = "Library/Application Support/Caches"
+ /// Both places, relative to the home folder.
+ static let places = ["Library/Caches", formerPlace]
/// The app's electron-updater settings, `Resources/app-update.yml` in `contents`, or nil when it has none. A real
/// one is a few lines, so anything over 64 KB, or anything that is not a regular file, is ignored.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index d1fd5ea4..ddb1f737 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -125,6 +125,57 @@ struct LeftoverScannerTests {
/// Another copy of an app that macOS knows outside the Applications folders uses the same files. Every Mac has one
/// of the character palette in its input methods folder, so a copy of it in Applications shares its settings, and
/// that copy is counted once when the list of apps holds it too.
+ /// electron-updater keeps an app's downloads in the folder the app's own settings name, in `~/Library/Caches` or
+ /// its former place in Application Support, whatever the app is called. Only electron-builder's own shape of
+ /// name claims a folder, and only in those two places.
+ @Test func findsTheFolderTheAppsUpdaterKeepsItsDownloadsIn() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Caches/tide2-updater/update.zip", bytes: 4096)
+ try directory.file("home/Library/Application Support/Caches/tide2-updater/pending/update-info.json", bytes: 64)
+ try directory.file("home/Library/Logs/tide2-updater/main.log", bytes: 64)
+ try directory.file("home/Library/Caches/Shared/data", bytes: 64)
+ let tide = InstalledApp(
+ url: URL(filePath: "/Applications/Tide Studio.app"), bundleIdentifier: "org.example.tidestudio",
+ name: "Tide Studio", updaterFolder: "tide2-updater"
+ )
+ let other = InstalledApp(
+ url: URL(filePath: "/Applications/Kelp.app"), bundleIdentifier: "org.example.kelp", name: "Kelp",
+ updaterFolder: "Shared"
+ )
+
+ let scanner = LeftoverScanner(environment: environment(in: directory))
+ let found = await scanner.scan(tide, installedApps: [tide, other]).leftovers
+ .filter { $0.match.reason == .updaterDownloads }
+ let kelps = await scanner.scan(other, installedApps: [tide, other]).leftovers
+
+ #expect(Set(found.map { $0.url.deletingLastPathComponent().lastPathComponent }) == ["Caches"])
+ #expect(found.count == 2)
+ #expect(found.allSatisfy { $0.match.confidence == .certain && $0.match.isRecommended })
+ #expect(!kelps.contains { $0.url.lastPathComponent == "Shared" })
+ }
+
+ /// Another copy of the app names the same folder, so the folder stays with it.
+ @Test func anUpdaterFolderAnotherCopyNamesStaysWithIt() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Caches/tide2-updater/update.zip", bytes: 4096)
+ let tide = InstalledApp(
+ url: URL(filePath: "/Applications/Tide Studio.app"), bundleIdentifier: "org.example.tidestudio",
+ name: "Tide Studio", updaterFolder: "tide2-updater"
+ )
+ let copy = InstalledApp(
+ url: URL(filePath: "/Users/x/Applications/Tide Studio.app"), bundleIdentifier: "org.example.tidestudio",
+ name: "Tide Studio", updaterFolder: "tide2-updater"
+ )
+
+ let scanner = LeftoverScanner(environment: environment(in: directory))
+ let scan = await scanner.scan(tide, installedApps: [tide, copy])
+ let folder = try #require(scan.leftovers.first { $0.url.lastPathComponent == "tide2-updater" })
+
+ #expect(folder.match.reason == .updaterDownloads)
+ #expect(folder.match.otherCopies == [copy.url])
+ #expect(!folder.match.isRecommended)
+ }
+
/// A preference file whose bytes are not a property list holds settings nobody can read, so its row says so. A
/// file that reads as one does not.
@Test func marksAPreferenceFileThatIsNoPropertyList() async throws {
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index e2ced89f..49fd3ce5 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -20,6 +20,7 @@ extension MatchReason {
case .leadsIntoItsHomebrewReceipt: "Leads into the app’s Homebrew receipt"
case .homebrewCask: "Listed by the Homebrew cask"
case .managedByTheApp: "Managed by the app"
+ case .updaterDownloads: "Where the app’s updater keeps its downloads"
}
}
}
diff --git a/SAFETY.md b/SAFETY.md
index 0cdd2025..c5786d40 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -257,6 +257,10 @@ Only matches Peel is `certain` or `likely` about, and only when nothing else ins
- **A plug-in goes by what it declares.** Its name says what it does rather than who made it, so a plug-in called
like the app is selected only when the identifier it declares is the app's or its maker's: another maker's plug-in
with the app's name is never selected.
+- **What the app's updater downloaded goes with it.** electron-updater, which many Electron apps ship, keeps an app's
+ downloads in the folder the app's own settings name, the app's name and `-updater`, in `~/Library/Caches` or, before
+ electron-updater 6, in `~/Library/Application Support/Caches`. That folder is the app's whatever the app is called,
+ and shared only with another app, or another copy of it, that names the same folder.
- **A system extension is left to macOS**, which removes it only when the app that uses it goes to the Trash in
Finder, so the copy macOS installed is never listed with the app.
- **An app that stays keeps its files.** Nothing at all is selected for an app that would stay: one macOS keeps, one