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
Learn App Management from a move only when it was needed
Țugui Dragoșe20fa309ac65
diff --git a/Packages/PeelCore/Sources/PeelCore/Home/Access.swift b/Packages/PeelCore/Sources/PeelCore/Home/Access.swiftindex 5d672145..a4a74894 100644--- a/Packages/PeelCore/Sources/PeelCore/Home/Access.swift+++ b/Packages/PeelCore/Sources/PeelCore/Home/Access.swift@@ -144,16 +144,34 @@ public enum CommandLineTool {public enum AppManagement {public static let settingsURL = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_AppBundles")!- /// What a removal shows about App Management, or nil when it shows nothing. An app bundle Peel moved means- /// granted. A bundle macOS refused to move from a folder the user can write to, when nothing locks it, means- /// missing. Bundles the root helper moved don't count, since the helper doesn't need Peel's permission.+ /// What a removal shows about App Management, or nil when it shows nothing. A bundle Peel moved means granted+ /// only when it is signed by another team than Peel's: App Management keeps apps of one team from changing+ /// another's (WWDC 2022, "What's new in privacy"), so an unsigned app, or one of Peel's own team, moves without+ /// it. A bundle macOS refused to move from a folder the user can write to, when nothing locks it, means missing.+ /// Bundles the root helper moved don't count, since the helper doesn't need Peel's permission.public static func state(after result: TrashResult,appBundles: Set<URL>,movedByTheHelper: Set<URL> = []+ ) -> AccessState? {+ state(+ after: result, appBundles: appBundles, movedByTheHelper: movedByTheHelper,+ ownTeam: CodeSignature.teamIdentifier(at: Bundle.main.bundleURL), teamOf: CodeSignature.teamIdentifier(at:)+ )+ }++ static func state(+ after result: TrashResult,+ appBundles: Set<URL>,+ movedByTheHelper: Set<URL> = [],+ ownTeam: String?,+ teamOf: (URL) -> String? = CodeSignature.teamIdentifier(at:)) -> AccessState? {let asked = appBundles.subtracting(movedByTheHelper)- if result.trashed.contains(where: { asked.contains($0.originalURL) }) {+ let guarded = result.trashed.contains { item in+ asked.contains(item.originalURL) && teamOf(item.trashedURL).map { $0 != ownTeam } == true+ }+ if guarded {return .granted}for failure in result.failures where asked.contains(failure.url) && failure.reason == .notPermitted {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swiftindex a8a71426..db6311d1 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift@@ -146,7 +146,9 @@ struct AccessTests {let directory = try TemporaryDirectory()let bundle = try directory.directory("Applications/Example.app")let trashed = TrashResult(trashed: [TrashedItem(originalURL: bundle, trashedURL: URL(filePath: "/Users/x/.Trash/Example.app"), date: .now)])- #expect(AppManagement.state(after: trashed, appBundles: [bundle]) == .granted)+ #expect(AppManagement.state(after: trashed, appBundles: [bundle]) == nil, "an unsigned app moves without it")+ #expect(AppManagement.state(after: trashed, appBundles: [bundle], ownTeam: "PEELTEAM01", teamOf: { _ in "OTHERTEAM1" }) == .granted)+ #expect(AppManagement.state(after: trashed, appBundles: [bundle], ownTeam: "PEELTEAM01", teamOf: { _ in "PEELTEAM01" }) == nil)let refused = TrashResult(failures: [TrashFailure(url: bundle, reason: .notPermitted)])#expect(AppManagement.state(after: refused, appBundles: [bundle]) == .missing)@@ -202,8 +204,13 @@ struct AppManagementTests {let bundle = URL(filePath: "/Applications/Example.app", directoryHint: .isDirectory)let trashed = TrashResult(trashed: [TrashedItem(originalURL: bundle, trashedURL: bundle, date: .now)])- #expect(AppManagement.state(after: trashed, appBundles: [bundle]) == .granted)- #expect(AppManagement.state(after: trashed, appBundles: [bundle], movedByTheHelper: [bundle]) == nil)+ let otherTeam = { (_: URL) in "OTHERTEAM1" }+ #expect(AppManagement.state(after: trashed, appBundles: [bundle], ownTeam: "PEELTEAM01", teamOf: otherTeam) == .granted)+ #expect(+ AppManagement.state(+ after: trashed, appBundles: [bundle], movedByTheHelper: [bundle], ownTeam: "PEELTEAM01", teamOf: otherTeam+ ) == nil+ )}/// A link left by a Peel that is gone, or somebody else's `peel`, is not Peel's tool. It is never counted as