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 ZeroTier's identity and Tunnelblick's shared configurations unselected

Țugui Dragoș555cd65e66b2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0deb8a35..17bf7514 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -75,6 +75,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
- A sign-in a tool saved when you logged in, such as Docker's `config.json` or the folder of the Google Cloud CLI, is
listed and never selected, since logging in again brings it back.
+- ZeroTier's identity on its networks and Tunnelblick's shared VPN configurations, both kept in
+ `/Library/Application Support`, are listed and never selected, like a VPN's connections in your home folder.
#### Space
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift
index 94431cdb..bd0050d0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/KeptOnlyHere.swift
@@ -68,13 +68,26 @@ enum KeptOnlyHere {
(".terraform.d", "credentials.tfrc.json", .holdsSignIns),
]
- static func reason(for path: String, home: String) -> HoldBack? {
+ /// The same, in the Library every account on the Mac shares.
+ static let localPlaces: [(folder: String, inside: String?, reason: HoldBack)] = [
+ // ZeroTier's "How to clear or reset your ZeroTier address": the node's identity is in this working folder,
+ // and a new one has to be authorized again on every network.
+ ("Library/Application Support/ZeroTier", "One", .holdsVPNConnections),
+ // Tunnelblick's "File Locations": shared configurations, and the backups of the configurations deployed
+ // inside the app.
+ ("Library/Application Support/Tunnelblick", "Shared", .holdsVPNConnections),
+ ("Library/Application Support/Tunnelblick", "Backup", .holdsVPNConnections),
+ ]
+
+ static func reason(for path: String, home: String, root: String) -> HoldBack? {
let item = PathComponents.of(path.lowercased())
- let home = (home as NSString).standardizingPath
- for (folder, inside, reason) in places {
- let folder = PathComponents.of((home as NSString).appendingPathComponent(folder).lowercased())
- let place = folder + (inside.map { PathComponents.of($0.lowercased()) } ?? [])
- if item.starts(with: place) || item == folder { return reason }
+ for (base, list) in [(home, places), (root, localPlaces)] {
+ let base = (base as NSString).standardizingPath
+ for (folder, inside, reason) in list {
+ let folder = PathComponents.of((base as NSString).appendingPathComponent(folder).lowercased())
+ let place = folder + (inside.map { PathComponents.of($0.lowercased()) } ?? [])
+ if item.starts(with: place) || item == folder { return reason }
+ }
}
// What an app names as its backups is a copy the person may need, whichever app made it.
let words = (item.last ?? "").split { !$0.isLetter }
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index 8626c22b..12985a22 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -102,6 +102,7 @@ public struct LeftoverScanner: Sendable {
// container makes macOS ask for its data unless Peel has Full Disk Access.
for location in environment.locations where location.kind != .safariWebApps || app.isASafariWebApp {
let home = environment.homeDirectory.path(percentEncoded: false)
+ let root = environment.rootDirectory.path(percentEncoded: false)
let bundle = PathPattern.comparablePath(of: app.url)
_ = group.addTaskUnlessCancelled {
[exclusions, measure, refuses, installedByApple, nestedFolderLimit] in
@@ -109,6 +110,7 @@ public struct LeftoverScanner: Sendable {
location,
matcher: matcher,
home: home,
+ root: root,
bundle: bundle,
exclusions: exclusions,
measure: measure,
@@ -199,6 +201,7 @@ public struct LeftoverScanner: Sendable {
_ location: SearchLocation,
matcher: LeftoverMatcher,
home: String,
+ root: String,
bundle: String,
exclusions: Exclusions,
measure: @escaping Measure,
@@ -243,10 +246,11 @@ public struct LeftoverScanner: Sendable {
}
let taken = await withoutWhatAppleInstalled(toMeasure, home: home, installedByApple: installedByApple)
- let leftovers = await measured(taken, kind: location.kind, home: home, measure: measure)
+ let leftovers = await measured(taken, kind: location.kind, home: home, root: root, measure: measure)
let inside = await nested(
- in: nobodysFolders, of: location, matcher: matcher, home: home, bundle: bundle, exclusions: exclusions,
- measure: measure, refuses: refuses, installedByApple: installedByApple, limit: nestedFolderLimit
+ in: nobodysFolders, of: location, matcher: matcher, home: home, root: root, bundle: bundle,
+ exclusions: exclusions, measure: measure, refuses: refuses, installedByApple: installedByApple,
+ limit: nestedFolderLimit
)
return .found(
leftovers + inside.found, cutShort: inside.wasCutShort ? location : nil,
@@ -261,6 +265,7 @@ public struct LeftoverScanner: Sendable {
of location: SearchLocation,
matcher: LeftoverMatcher,
home: String,
+ root: String,
bundle: String,
exclusions: Exclusions,
measure: @escaping Measure,
@@ -294,7 +299,7 @@ public struct LeftoverScanner: Sendable {
return .lookInside
}
let taken = await withoutWhatAppleInstalled(search.found, home: home, installedByApple: installedByApple)
- let found = await measured(taken, kind: kind, home: home, measure: measure)
+ let found = await measured(taken, kind: kind, home: home, root: root, measure: measure)
// A program keeps its files in a folder named by its identifier (Apple's File System Programming Guide), so
// one the app has no claim on holds none of its files, even where Peel can't look inside.
let unreadable = search.unreadable.filter { folder in
@@ -351,11 +356,11 @@ public struct LeftoverScanner: Sendable {
/// Measures what one location found, a few at a time, and keeps the order it was found in.
private static func measured(
- _ found: [Found], kind: SearchLocation.Kind, home: String, measure: @escaping Measure
+ _ found: [Found], kind: SearchLocation.Kind, home: String, root: String, measure: @escaping Measure
) async -> [Leftover] {
await found.concurrentMap(width: concurrentMeasurements) { item in
await leftover(
- at: item.url, kind: kind, match: item.match, parent: item.parent, home: home,
+ at: item.url, kind: kind, match: item.match, parent: item.parent, home: home, root: root,
foldersAbove: item.foldersAbove, measure: measure
)
}
@@ -369,6 +374,7 @@ public struct LeftoverScanner: Sendable {
match: LeftoverMatch,
parent: ParentAccess,
home: String,
+ root: String,
foldersAbove: FoldersAbove = .itsOwn,
measure: Measure = LeftoverScanner.walk,
syncsToOtherDevices: (URL) -> Bool = SyncedFolders().syncsToOtherDevices
@@ -393,7 +399,9 @@ public struct LeftoverScanner: Sendable {
.holdsWorkKeptInACache
} else if syncsToOtherDevices(url) {
.inTheCloud
- } else if let keptOnlyHere = KeptOnlyHere.reason(for: url.path(percentEncoded: false), home: home) {
+ } else if let keptOnlyHere = KeptOnlyHere.reason(
+ for: url.path(percentEncoded: false), home: home, root: root
+ ) {
keptOnlyHere
} else if contents?.couldNotBeRead == true {
.couldNotBeRead
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index 501ee39e..e53bd860 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -91,6 +91,7 @@ public struct OrphanScanner: Sendable {
let results = await withTaskGroup(of: (location: SearchLocation, result: LocationResult).self) { group in
let home = environment.homeDirectory.path(percentEncoded: false)
+ let root = environment.rootDirectory.path(percentEncoded: false)
// Safari's web app container is another app's container, which macOS asks about, and is read only for one
// of its web apps.
for location in environment.locations where location.kind != .safariWebApps {
@@ -102,8 +103,8 @@ public struct OrphanScanner: Sendable {
}
return (location, await Self.scan(
location, ownership: ownership, jobs: jobs, goneBundles: goneBundles, goneApps: goneApps,
- goneNames: goneNames, goneFolders: goneFolders, home: home, exclusions: exclusions,
- nestedFolderLimit: nestedFolderLimit, walk: walk
+ goneNames: goneNames, goneFolders: goneFolders, home: home, root: root,
+ exclusions: exclusions, nestedFolderLimit: nestedFolderLimit, walk: walk
))
}
}
@@ -219,6 +220,7 @@ public struct OrphanScanner: Sendable {
reach: HelperReach
) async -> [AdministratorItem] {
let home = environment.homeDirectory.path(percentEncoded: false)
+ let root = environment.rootDirectory.path(percentEncoded: false)
let installed = Set(installedApps.map { $0.reference.lowercased() })
let merged = LeftForAnAdministrator.Record.merged(records)
var seen: Set<ItemKey> = []
@@ -262,7 +264,7 @@ public struct OrphanScanner: Sendable {
let item = Self.holdingBack(
Self.item(
at: url, kind: record.kind, contents: contents,
- parent: ParentAccess(url.deletingLastPathComponent()), home: home
+ parent: ParentAccess(url.deletingLastPathComponent()), home: home, root: root
),
beyond: reach
)
@@ -647,6 +649,7 @@ public struct OrphanScanner: Sendable {
goneNames: [String: String],
goneFolders: GoneFolders,
home: String,
+ root: String,
exclusions: Exclusions,
nestedFolderLimit: Int,
walk: @escaping LeftoverScanner.Measure
@@ -727,7 +730,7 @@ public struct OrphanScanner: Sendable {
identifier: candidate.identifier,
item: item(
at: candidate.url, kind: location.kind, contents: contents, parent: candidate.parent, home: home,
- namedAfter: candidate.namedAfter, folder: candidate.folder
+ root: root, namedAfter: candidate.namedAfter, folder: candidate.folder
)
)
}
@@ -746,6 +749,7 @@ public struct OrphanScanner: Sendable {
contents: FolderContents?,
parent: ParentAccess,
home: String,
+ root: String,
namedAfter: String? = nil,
folder: ProductFolder? = nil
) -> OrphanItem {
@@ -761,7 +765,7 @@ public struct OrphanScanner: Sendable {
.holdsALibrary
} else if ProtectedData.holdsWorkKeptInACache(path) {
.holdsWorkKeptInACache
- } else if let keptOnlyHere = KeptOnlyHere.reason(for: path, home: home) {
+ } else if let keptOnlyHere = KeptOnlyHere.reason(for: path, home: home, root: root) {
keptOnlyHere
} else if folder?.holdsWork(at: url) == true {
.holdsWorkMadeWithTheApp
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index 8034ec16..4e0d4fc3 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -129,7 +129,8 @@ public struct Uninstallation: Sendable {
otherCopies: others.copies
),
parent: ParentAccess(url.deletingLastPathComponent()),
- home: home.path(percentEncoded: false)
+ home: home.path(percentEncoded: false),
+ root: environment.rootDirectory.path(percentEncoded: false)
)
.heldBack(managedBy.leftBehind)
leftovers.append(exclusions.holds(url) ? leftover.heldBack(.holdsAnExclusion) : leftover)
@@ -165,7 +166,8 @@ public struct Uninstallation: Sendable {
kind: .receipts,
match: LeftoverMatch(reason: .installerReceipt, confidence: .certain, sharedWith: []),
parent: ParentAccess(url.deletingLastPathComponent()),
- home: environment.homeDirectory.path(percentEncoded: false)
+ home: environment.homeDirectory.path(percentEncoded: false),
+ root: environment.rootDirectory.path(percentEncoded: false)
))
}
}
@@ -204,12 +206,14 @@ public struct Uninstallation: Sendable {
return installed?.reference ?? Bundle(url: URL(filePath: target))?.bundleIdentifier ?? target
})
let home = environment.homeDirectory.path(percentEncoded: false)
+ let root = environment.rootDirectory.path(percentEncoded: false)
let leftover = await LeftoverScanner.leftover(
at: folder,
kind: .homebrewReceipt,
match: LeftoverMatch(reason: .homebrewReceipt, confidence: .certain, sharedWith: sharedWith.sorted()),
parent: ParentAccess(folder.deletingLastPathComponent()),
- home: home
+ home: home,
+ root: root
)
var leftovers = [exclusions.holds(folder) ? leftover.heldBack(.holdsAnExclusion) : leftover]
let receipt = PathPattern.comparablePath(of: folder)
@@ -223,7 +227,8 @@ public struct Uninstallation: Sendable {
reason: .leadsIntoItsHomebrewReceipt, confidence: .certain, sharedWith: sharedWith.sorted()
),
parent: ParentAccess(location.url),
- home: home
+ home: home,
+ root: root
))
}
}
@@ -265,7 +270,8 @@ public struct Uninstallation: Sendable {
otherCopies: claims.flatMap(\.copies) + (own?.otherCopies ?? [])
),
parent: ParentAccess(item.url.deletingLastPathComponent()),
- home: environment.homeDirectory.path(percentEncoded: false)
+ home: environment.homeDirectory.path(percentEncoded: false),
+ root: environment.rootDirectory.path(percentEncoded: false)
)
leftovers.append(exclusions.holds(item.url) ? leftover.heldBack(.holdsAnExclusion) : leftover)
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/KeptOnlyHereTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/KeptOnlyHereTests.swift
index a26e8761..3fb4945c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/KeptOnlyHereTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/KeptOnlyHereTests.swift
@@ -33,7 +33,17 @@ struct KeptOnlyHereTests {
(".azure/msal_token_cache.json", .holdsSignIns), (".terraform.d/credentials.tfrc.json", .holdsSignIns),
]
for (path, reason) in held {
- #expect(KeptOnlyHere.reason(for: "\(home)/\(path)", home: home) == reason, "\(path)")
+ #expect(KeptOnlyHere.reason(for: "\(home)/\(path)", home: home, root: "/") == reason, "\(path)")
+ }
+ let heldOnTheMac: [(String, HoldBack)] = [
+ ("Library/Application Support/ZeroTier", .holdsVPNConnections),
+ ("Library/Application Support/ZeroTier/One/identity.secret", .holdsVPNConnections),
+ ("Library/Application Support/Tunnelblick", .holdsVPNConnections),
+ ("Library/Application Support/Tunnelblick/Shared/Office.tblk", .holdsVPNConnections),
+ ("Library/Application Support/Tunnelblick/Backup/Deployed/Office.tblk", .holdsVPNConnections),
+ ]
+ for (path, reason) in heldOnTheMac {
+ #expect(KeptOnlyHere.reason(for: "/\(path)", home: home, root: "/") == reason, "\(path)")
}
}
@@ -49,8 +59,16 @@ struct KeptOnlyHereTests {
".docker/contexts", ".cargo/registry", ".config", ".local/share", ".terraform.d/plugins",
]
for path in free {
- #expect(KeptOnlyHere.reason(for: "\(home)/\(path)", home: home) == nil, "\(path)")
+ #expect(KeptOnlyHere.reason(for: "\(home)/\(path)", home: home, root: "/") == nil, "\(path)")
+ }
+ let freeOnTheMac = [
+ "Library/Application Support/ZeroTier/Other", "Library/Application Support/Tunnelblick/Logs",
+ "Library/Application Support/Tunnelblick/Users/me", "Library/Application Support/Signal",
+ ]
+ for path in freeOnTheMac {
+ #expect(KeptOnlyHere.reason(for: "/\(path)", home: home, root: "/") == nil, "\(path)")
}
- #expect(KeptOnlyHere.reason(for: "/Users/someone/Library/Application Support/Signal", home: home) == nil)
+ #expect(KeptOnlyHere.reason(for: "/Users/someone/Library/Application Support/Signal", home: home, root: "/") == nil)
+ #expect(KeptOnlyHere.reason(for: "\(home)/Library/Application Support/ZeroTier", home: home, root: "/") == nil)
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index f3e5954e..1c305884 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -709,6 +709,26 @@ struct LeftoverScannerTests {
#expect(Set(scan.unreadableLocations.map(\.url.lastPathComponent)) == ["net.example.shared", "Shared Data"])
}
+ @Test func aVPNsIdentityAndItsSharedConnectionsInTheMacsLibraryAreNotSelected() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("root/Library/Application Support/ZeroTier/One/identity.secret")
+ try directory.file("root/Library/Application Support/Tunnelblick/Shared/Office.tblk/Contents/Resources/config.ovpn")
+ let zeroTier = InstalledApp(
+ url: URL(filePath: "/Applications/ZeroTier.app"), bundleIdentifier: "org.example.zerotier", name: "ZeroTier"
+ )
+ let tunnelblick = InstalledApp(
+ url: URL(filePath: "/Applications/Tunnelblick.app"), bundleIdentifier: "org.example.tunnelblick",
+ name: "Tunnelblick"
+ )
+ let scanner = LeftoverScanner(environment: environment(in: directory))
+
+ for app in [zeroTier, tunnelblick] {
+ let leftovers = await scanner.scan(app, installedApps: [zeroTier, tunnelblick]).leftovers
+ #expect(leftovers.map(\.url.lastPathComponent) == [app.name])
+ #expect(leftovers.map(\.match.heldBack) == [.holdsVPNConnections])
+ }
+ }
+
@Test(.permissionsHold) func flagsItemsInReadOnlyLocationsAsRequiringPrivileges() async throws {
let directory = try TemporaryDirectory()
try directory.file("root/Library/LaunchDaemons/net.example.client.helper.plist")
@@ -1147,6 +1167,7 @@ struct LeftoverScannerTests {
match: LeftoverMatch(reason: .bundleIdentifier, confidence: .certain, sharedWith: []),
parent: ParentAccess(folder.deletingLastPathComponent()),
home: directory.url.appending(path: "home").path(percentEncoded: false),
+ root: directory.url.appending(path: "root").path(percentEncoded: false),
measure: { _ in FolderContents(size: 0, holdsRepository: false, couldNotBeRead: true) }
)
@@ -1172,6 +1193,7 @@ struct LeftoverScannerTests {
match: LeftoverMatch(reason: .bundleIdentifier, confidence: .certain, sharedWith: []),
parent: ParentAccess(url.deletingLastPathComponent()),
home: directory.url.appending(path: "home").path(percentEncoded: false),
+ root: directory.url.appending(path: "root").path(percentEncoded: false),
measure: unread
)
}
@@ -1191,6 +1213,7 @@ struct LeftoverScannerTests {
match: LeftoverMatch(reason: .bundleIdentifier, confidence: .certain, sharedWith: []),
parent: ParentAccess(url.deletingLastPathComponent()),
home: directory.url.appending(path: "home").path(percentEncoded: false),
+ root: directory.url.appending(path: "root").path(percentEncoded: false),
syncsToOtherDevices: { $0.lastPathComponent == "Example" }
)
}
@@ -1212,7 +1235,8 @@ struct LeftoverScannerTests {
kind: .elsewhere,
match: LeftoverMatch(reason: .bundleIdentifier, confidence: .certain, sharedWith: []),
parent: ParentAccess(url.deletingLastPathComponent()),
- home: directory.url.appending(path: "home").path(percentEncoded: false)
+ home: directory.url.appending(path: "home").path(percentEncoded: false),
+ root: directory.url.appending(path: "root").path(percentEncoded: false)
)
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 731927dd..4383439e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -1168,6 +1168,21 @@ struct OrphanScannerTests {
#expect(items.map(\.heldBack) == [.holdsVPNConnections])
}
+ @Test func aVPNsIdentityInTheMacsLibraryOfAnAppThatLeftSaysSo() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("root/Library/Application Support/ZeroTier/One/identity.secret")
+ let gone = RememberedApp(
+ bundleIdentifier: "org.example.zerotier", name: "ZeroTier", teamIdentifier: nil, lastSeen: .now,
+ lastPath: "/Applications/ZeroTier.app"
+ )
+
+ let items = await scanner(in: directory).scan(installedApps: installed, remembered: [gone]).groups
+ .flatMap(\.items)
+
+ #expect(items.map(\.url.lastPathComponent) == ["ZeroTier"])
+ #expect(items.map(\.heldBack) == [.holdsVPNConnections])
+ }
+
/// As on an app's page, since the app's developer may still ask for the report.
@Test func aCrashReportOfAnAppThatLeftIsLeftForThePersonToChoose() async throws {
let directory = try TemporaryDirectory()