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.

Keep a code editor's unsaved files and local history unselected

Țugui Dragoșcecf90d2001a
diff --git a/GUIDE.md b/GUIDE.md
index 82493146..8b8b8c47 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -23,8 +23,8 @@ and how to get it, [SAFETY.md](SAFETY.md) what it protects, [PRIVACY.md](PRIVACY
- **What may exist nowhere else is left to you.** A folder holding a crypto wallet, a signing key, a password
database, or a repository is shown with its reason and not selected, and so is a place where an app keeps what
may exist only on this Mac, such as local mail, message history, sign-in codes, VPN connections, a torrent client's
- list of torrents, a game's saves, a database, an app's own backups, or the sign-in a tool saved when you logged in.
- Uninstalling Xcode lists the simulators it made the same way.
+ list of torrents, a game's saves, a database, a code editor's unsaved files and local history, an app's own backups,
+ or the sign-in a tool saved when you logged in. Uninstalling Xcode lists the simulators it made the same way.
- **Shared or guessed, never selected.** A file another installed app also uses is shown but never selected, and a
folder holding another installed app's own data, such as Xcode's in `~/Library/Developer`, can't be selected at
all, and neither can anything that syncs to your other devices, an app's container holding your documents, or a
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/ProductFolders.swift b/Packages/PeelCore/Sources/PeelCore/Apps/ProductFolders.swift
index 248aa1b0..e234f3e6 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/ProductFolders.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/ProductFolders.swift
@@ -57,6 +57,8 @@ enum ProductFolders {
let names = PathComponents.of(folder.path)
let named = switch names.count {
case 4: jetBrainsFolders(in: ["productVendor": names[2], "dataDirectoryName": names[3]])
+ case 3 where names[0] == "Library" && names[1] == "Application Support" && isOneName(names[2]):
+ [vsCodeData(named: names[2])]
case 1: vsCodeFolders(in: ["dataFolderName": names[0], "sharedDataFolderName": names[0]])
default: [ProductFolder]()
}
@@ -82,14 +84,26 @@ enum ProductFolders {
}
/// A code editor built on VS Code keeps its extensions in `~/<dataFolderName>`, beside the `argv.json` it writes
- /// there, and what its windows share in `~/<sharedDataFolderName>/sharedStorage`. Each folder is taken only while
- /// it holds what VS Code writes there.
+ /// there, what its windows share in `~/<sharedDataFolderName>/sharedStorage`, and the rest in
+ /// `Application Support/<nameShort>`, with unsaved files in `Backups` and local history in `User/History`. Each
+ /// folder is taken only while it holds what VS Code writes there.
static func vsCodeFolders(in product: [String: Any]?) -> [ProductFolder] {
- [("dataFolderName", "argv.json"), ("sharedDataFolderName", "sharedStorage")].compactMap { key, proof in
+ let keys = [("dataFolderName", "argv.json"), ("sharedDataFolderName", "sharedStorage")]
+ let home: [ProductFolder] = keys.compactMap { key, proof in
guard let name = product?[key] as? String, name.hasPrefix("."), isOneName(String(name.dropFirst()))
else { return nil }
return ProductFolder(path: name, proof: proof)
}
+ guard product?["dataFolderName"] is String, let name = product?["nameShort"] as? String, isOneName(name)
+ else { return home }
+ return home + [vsCodeData(named: name)]
+ }
+
+ private static func vsCodeData(named name: String) -> ProductFolder {
+ ProductFolder(
+ path: "Library/Application Support/\(name)", proof: "User/globalStorage/storage.json",
+ work: ["Backups", "User/History"]
+ )
}
/// One plain name: not hidden, and nothing but letters, digits, spaces, `-`, `_` and `.`.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift
index bf694190..a5cccc5a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppResetTests.swift
@@ -20,6 +20,29 @@ struct AppResetTests {
)
}
+ @Test func offersACodeEditorsDataFolderOnlyWhileNoUnsavedFileOrLocalHistoryIsInside() async throws {
+ let directory = try TemporaryDirectory()
+ for name in ["Inkwell", "Slate"] {
+ try directory.file("Library/Application Support/\(name)/User/globalStorage/storage.json", bytes: 4096)
+ }
+ try directory.file("Library/Application Support/Inkwell/User/History/-5c6d/entries.json", bytes: 4096)
+ let editor = { (name: String) in
+ InstalledApp(
+ url: URL(filePath: "/Applications/\(name).app"), bundleIdentifier: "com.example.\(name.lowercased())",
+ name: name,
+ productFolders: ProductFolders.vsCodeFolders(in: ["nameShort": name, "dataFolderName": ".\(name.lowercased())"])
+ )
+ }
+ let apps = [editor("Inkwell"), editor("Slate")]
+
+ let held = await AppReset.prepare(apps[0], installedApps: apps, environment: home(directory))
+ let free = await AppReset.prepare(apps[1], installedApps: apps, environment: home(directory))
+
+ #expect(held.items(in: .appData).isEmpty)
+ #expect(free.items(in: .appData).map(\.url.lastPathComponent) == ["Slate"])
+ #expect(!free.suggestedSelection.contains { $0.lastPathComponent == "Slate" })
+ }
+
@Test func sortsWhatItFindsIntoSettingsWebDataAndAppData() async throws {
let directory = try TemporaryDirectory()
try directory.file("Library/Preferences/com.example.app.plist", bytes: 4096)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 81234b9b..6b6ac9ef 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -245,6 +245,41 @@ struct LeftoverScannerTests {
#expect(others.isEmpty)
}
+ @Test func leavesACodeEditorsDataFolderWithUnsavedFilesOrLocalHistoryForThePersonToSelect() async throws {
+ let directory = try TemporaryDirectory()
+ let support = "home/Library/Application Support"
+ for name in ["Inkwell", "Quill", "Slate", "Plain"] where name != "Plain" {
+ try directory.file("\(support)/\(name)/User/globalStorage/storage.json", bytes: 64)
+ try directory.directory("\(support)/\(name)/Backups")
+ }
+ try directory.file("\(support)/Inkwell/Backups/1a2b/untitled/Untitled-1", bytes: 64)
+ try directory.file("\(support)/Quill/User/History/-5c6d/entries.json", bytes: 64)
+ try directory.file("\(support)/Plain/settings.json", bytes: 64)
+ let editor = { (name: String) in
+ InstalledApp(
+ url: URL(filePath: "/Applications/\(name).app"), bundleIdentifier: "org.example.\(name.lowercased())",
+ name: name,
+ productFolders: ProductFolders.vsCodeFolders(in: ["nameShort": name, "dataFolderName": ".\(name.lowercased())"])
+ )
+ }
+ let apps = ["Inkwell", "Quill", "Slate", "Plain"].map(editor)
+ let scanner = LeftoverScanner(environment: environment(in: directory))
+
+ var folders: [String: Leftover] = [:]
+ for app in apps {
+ let scan = await scanner.scan(app, installedApps: apps)
+ folders[app.name] = scan.leftovers.first { $0.url.lastPathComponent == app.name }
+ }
+
+ for name in ["Inkwell", "Quill"] {
+ #expect(folders[name]?.match.reason == .namedByTheApp, "\(name)")
+ #expect(folders[name]?.match.heldBack == .holdsWorkMadeWithTheApp, "\(name)")
+ }
+ #expect(folders["Slate"]?.match.reason == .namedByTheApp)
+ #expect(folders["Slate"]?.match.isRecommended == true)
+ #expect(folders["Plain"]?.match.reason == .name)
+ }
+
/// 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/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 142336fb..4485447a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -268,6 +268,23 @@ struct OrphanScannerTests {
#expect(items.contains { $0.url.lastPathComponent == "org.example.inkpot" && $0.heldBack == nil })
}
+ @Test func listsTheDataFolderOfACodeEditorThatLeftAndHoldsItsWorkBack() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("home/Library/Application Support/Inkwell/User/globalStorage/storage.json", bytes: 64)
+ try directory.file("home/Library/Application Support/Inkwell/User/History/-5c6d/entries.json", bytes: 64)
+ let gone = RememberedApp(
+ bundleIdentifier: "org.example.inkwell", name: "Inkwell Editor", teamIdentifier: nil, lastSeen: .now,
+ lastPath: "/Applications/Inkwell Editor.app",
+ productFolders: ProductFolders.vsCodeFolders(in: ["nameShort": "Inkwell", "dataFolderName": ".inkwell"])
+ )
+
+ let scan = await scanner(in: directory).scan(installedApps: installed, remembered: [gone])
+
+ let group = scan.groups.first { $0.identifier == "org.example.inkwell" }
+ let folder = group?.items.first { $0.url.lastPathComponent == "Inkwell" }
+ #expect(folder?.heldBack == .holdsWorkMadeWithTheApp)
+ }
+
@Test func listsABrowsersManifestThatStartsNothing() async throws {
let directory = try TemporaryDirectory()
let hosts = "root/Library/Google/Chrome/NativeMessagingHosts"
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProductFoldersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProductFoldersTests.swift
index a14d5f4a..f5e3ce28 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProductFoldersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProductFoldersTests.swift
@@ -31,6 +31,25 @@ struct ProductFoldersTests {
#expect(ProductFolders.of(appAt: try directory.directory("Applications/Plain.app")).isEmpty)
}
+ @Test func namesTheFolderACodeEditorKeepsItsDataInAndTheWorkInside() {
+ let data = ProductFolder(
+ path: "Library/Application Support/Example Editor", proof: "User/globalStorage/storage.json",
+ work: ["Backups", "User/History"]
+ )
+
+ let folders = ProductFolders.vsCodeFolders(in: ["nameShort": "Example Editor", "dataFolderName": ".example-editor"])
+
+ #expect(folders == [ProductFolder(path: ".example-editor", proof: "argv.json"), data])
+ #expect(ProductFolders.vsCodeFolders(in: ["nameShort": "Example Editor"]).isEmpty)
+ for name in ["", ".", "..", ".hidden", "../Documents", "Example/Editor"] {
+ #expect(ProductFolders.vsCodeFolders(in: ["nameShort": name, "dataFolderName": ".x"]).count == 1, "\(name)")
+ }
+ #expect(ProductFolders.believes(data))
+ #expect(!ProductFolders.believes(ProductFolder(path: data.path, proof: nil, work: data.work)))
+ #expect(!ProductFolders.believes(ProductFolder(path: "Library/Caches/Example Editor", proof: data.proof, work: data.work)))
+ #expect(!ProductFolders.believes(ProductFolder(path: "Library/Application Support/..", proof: data.proof, work: data.work)))
+ }
+
@Test func believesAFolderReadBackOnlyAsTheRulesNameIt() {
let ide = ProductFolders.jetBrainsFolders(in: ["productVendor": "ExampleVendor", "dataDirectoryName": "ExampleIDE2025.2"])
let editor = ProductFolders.vsCodeFolders(in: ["dataFolderName": ".example-editor"])
diff --git a/SAFETY.md b/SAFETY.md
index 119fba31..76b43f40 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -389,10 +389,10 @@ Never selected for you, even when found:
- What an app keeps that may exist only on this Mac: local mail, message history, a password manager's vaults and
backups and an authenticator's codes, VPN connections and identities, a torrent client's list of torrents, a game's
saves, a database, a streaming app's scenes and profiles, an office suite's own templates and dictionaries, a
- terminal's scripts and profiles, and the sign-in a tool saved when you logged in, such as Docker's or Cargo's, each
- where the app's own documentation or source says it keeps them, and anything named as an app's backups, or the
- app's folder that keeps them. When you uninstall Xcode, the simulators it made in your home folder are listed too,
- with the apps installed in them and their data, and never selected.
+ terminal's scripts and profiles, a code editor's unsaved files and local history, and the sign-in a tool saved when
+ you logged in, such as Docker's or Cargo's, each where the app's own documentation or source says it keeps them, and
+ anything named as an app's backups, or the app's folder that keeps them. When you uninstall Xcode, the simulators it
+ made in your home folder are listed too, with the apps installed in them and their data, and never selected.
- A copy Mail keeps of an attachment you opened, which you may have changed.
- A file a program has open right now.
- An installer package an app keeps in Application Support, which the app may still need, and an update whose app is