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.

Refuse . and .. as the name of an Electron app's data folder

Țugui Dragoș60e9dccc7a70
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index 3f252b94..57a2a9e2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -1319,7 +1319,8 @@ public enum DeveloperCaches {
else { return nil }
let editor = vsCodeProductName(of: app)
let name = editor ?? bundleName
- guard !name.isEmpty, !name.contains("/"), !covered.contains(name.lowercased()) else { return nil }
+ guard !name.isEmpty, !name.contains("/"), name != ".", name != "..", !covered.contains(name.lowercased())
+ else { return nil }
let data = "Library/Application Support/\(name)"
guard exists(home.appending(path: "\(data)/Local State")) else { return nil }
// Each persistent session an app opens keeps the same caches in a folder of its own.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 00e28df0..e138d4b4 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -301,6 +301,29 @@ struct DeveloperCachesTests {
#expect(listed("org.example.chat") == ["GPUCache"])
}
+ /// `.` or `..` for a name, in the bundle or in `product.json`, names no folder of the app's own.
+ @Test func neverReadsAFolderAboveApplicationSupportAsAnElectronAppsData() throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ try directory.file("home/Library/Local State")
+ try directory.file("home/Library/Application Support/Local State")
+ let apps = try [("Up", "..", "{\"nameShort\": \"..\", \"dataFolderName\": \".up\"}"),
+ ("Here", ".", "{\"nameShort\": \".\", \"dataFolderName\": \".here\"}"),
+ ("Parent", "..", nil), ("Same", ".", nil)].map { file, name, product in
+ try directory.directory("Applications/\(file).app/Contents/Frameworks/Electron Framework.framework")
+ if let product {
+ try directory.file("Applications/\(file).app/Contents/Resources/app/product.json", contents: Data(product.utf8))
+ }
+ return InstalledApp(
+ url: directory.url.appending(path: "Applications/\(file).app", directoryHint: .isDirectory),
+ bundleIdentifier: "org.example.\(file.lowercased())", name: file,
+ bundleName: product == nil ? name : file
+ )
+ }
+
+ #expect(DeveloperCaches.electronDefinitions(for: apps, home: home).isEmpty)
+ }
+
@Test func listsTheCachesOfAnElectronAppsPartitionsAndNeverTheirStorage() async throws {
let directory = try TemporaryDirectory()
let home = directory.url.appending(path: "home", directoryHint: .isDirectory)