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.

Move an app before its files, so an app that stays keeps them

Țugui Dragoș3e0bcceef8a4
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 98b06e2a..fc87687c 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -3970,6 +3970,112 @@
}
}
},
+ "%@ stayed, and so did its files." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aplikace %@ zůstala, stejně jako její soubory."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "„%@“ ist geblieben, und ebenso die zugehörigen Dateien."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ se ha quedado, y sus archivos también."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ est resté en place, tout comme ses fichiers."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ è rimasta, e anche i suoi file."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“%@”は残り、そのファイルも残りました。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "‘%@’은(는) 그대로 남았으며, 앱의 파일도 함께 남았습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ is blijven staan, en de bestanden ervan ook."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aplikacja %@ została na miejscu, a wraz z nią jej pliki."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ ficou, e os arquivos do app também."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aplicația %@ a rămas pe loc, la fel și fișierele ei."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Приложение «%@» осталось на месте, как и его файлы."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ stannade kvar, och det gjorde dess filer också."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@ olduğu yerde kaldı, dosyaları da."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Програма «%@» лишилася на місці, а з нею і її файли."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "“%@”仍留在原处,它的文件也随之保留。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "「%@」仍留在原處,它的檔案也是如此。"
+ }
+ }
+ }
+ },
"%@ stays installed and forgets what is selected below. What is selected goes to the Trash, and the settings are copied first." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
index 4280be6a..a6d89c80 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
@@ -80,16 +80,16 @@ struct UninstallPlan {
)
}
- /// Moves the bundle to the Trash on its own, then the rest only if the bundle really moved. Call it only when
- /// `appStays` is nil: it takes the first item that moves to be the bundle.
+ /// Moves the bundle to the Trash on its own, then the rest only if the bundle really moved. When the app itself
+ /// stays, nothing moves.
func move(using service: TrashService) async -> TrashResult {
let urls = moving.map(\.url)
- guard let bundle = urls.first else { return TrashResult() }
- var result = await service.trash([bundle])
- guard !result.trashed.isEmpty else { return result }
- let rest = await service.trash(Array(urls.dropFirst()))
- result.trashed += rest.trashed
- result.failures += rest.failures
- return result
+ guard urls.contains(app) else { return TrashResult() }
+ let files = urls.filter { $0 != app }
+ return await service.trash(
+ apps: [app],
+ thenFiles: { stayed in stayed.isEmpty ? files : [] },
+ usingHelperFor: []
+ )
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
index 6b102372..a75495d8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
@@ -152,11 +152,40 @@ public struct BulkUninstallation: Sendable {
)
}
- /// Returns the selection in the order it is moved: leftovers first, then the apps. Excluded items and Peel's
+ /// Returns the selection in the order it is moved: the apps first, then the files. Excluded items and Peel's
/// are left out.
public func removalOrder(of selection: Set<URL>) -> [URL] {
let movable = items.filter { !$0.isExcluded && !$0.isPeels && selection.contains($0.url) }
- return movable.filter { !$0.isApplication }.map(\.url) + movable.filter(\.isApplication).map(\.url)
+ return movable.filter(\.isApplication).map(\.url) + movable.filter { !$0.isApplication }.map(\.url)
+ }
+
+ /// Moves `selection`, the apps first: a file follows only once every selected app it belongs to has moved, so
+ /// an app that stays keeps everything of its own, what it shares with another chosen app included.
+ public func move(_ selection: Set<URL>, using service: TrashService) async -> TrashResult {
+ let order = removalOrder(of: selection)
+ let apps = Set(items.filter(\.isApplication).map(\.url))
+ let owners = Dictionary(items.map { ($0.url, $0.apps) }, uniquingKeysWith: { first, _ in first })
+ let identifiers = Dictionary(
+ uninstallations.map { ($0.app.url, $0.app.bundleIdentifier) },
+ uniquingKeysWith: { first, _ in first }
+ )
+ return await service.trash(
+ apps: order.filter(apps.contains),
+ thenFiles: { stayed in
+ let kept = Set(stayed.compactMap { identifiers[$0] })
+ return order.filter { !apps.contains($0) && !(owners[$0] ?? []).contains(where: kept.contains) }
+ },
+ usingHelperFor: privilegedURLs
+ )
+ }
+
+ /// The chosen apps that stayed while files of their own were selected, which then stayed with them.
+ public func appsThatKeptTheirFiles(after result: TrashResult, selection: Set<URL>) -> [InstalledApp] {
+ let failed = Set(result.failures.map(\.url))
+ return apps.filter { app in
+ selection.contains(app.url) && failed.contains(app.url)
+ && !files(of: app.bundleIdentifier).isDisjoint(with: selection)
+ }
}
static func merge(_ uninstallations: [Uninstallation]) -> [Item] {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
index e55f3560..90aa3c1f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/SelfRemoval.swift
@@ -2,8 +2,9 @@ public import Foundation
/// Moves Peel's own files to the Trash, and then the Peel folder, which holds History.
public enum SelfRemoval {
- /// Moves `urls` to the Trash, and then `folder` if `app` moved. `record` writes History into `folder` first,
- /// so the record goes with it. Nothing is written after that, or the folder would be created again.
+ /// Moves `app` to the Trash, then the rest of `urls` once it has moved, and then `folder`. `record` writes
+ /// History into `folder` first, so the record goes with it. Nothing is written after that, or the folder would
+ /// be created again.
public static func move(
_ urls: [URL],
app: URL,
@@ -11,7 +12,12 @@ public enum SelfRemoval {
using service: TrashService,
recording record: (TrashResult) async -> Void
) async -> TrashResult {
- var result = await service.trash(urls)
+ let files = urls.filter { $0 != app }
+ var result = await service.trash(
+ apps: urls.filter { $0 == app },
+ thenFiles: { stayed in stayed.isEmpty ? files : [] },
+ usingHelperFor: []
+ )
await record(result)
guard
result.trashed.contains(where: { $0.originalURL == app }),
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 59bfb68a..e9999b90 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -346,8 +346,32 @@ public struct TrashService: Sendable {
/// Moves `privilegedURLs` through the privileged helper and everything else as the current user.
@concurrent
public func trash(_ urls: [URL], usingHelperFor privilegedURLs: Set<URL>) async -> TrashResult {
- if let refused = refusingAllWhileHistoryCannotBeRead(urls) { return refused }
+ await trash(urls, usingHelperFor: privilegedURLs, removal: UUID())
+ }
+
+ /// Moves `apps` first, then what `files` returns for the apps that stayed, as one removal. An app's files wait
+ /// for it, so an app that stays keeps everything of its own.
+ @concurrent
+ public func trash(
+ apps: [URL],
+ thenFiles files: @Sendable (_ appsThatStayed: Set<URL>) -> [URL],
+ usingHelperFor privilegedURLs: Set<URL>
+ ) async -> TrashResult {
let removal = UUID()
+ var result = apps.isEmpty
+ ? TrashResult()
+ : await trash(apps, usingHelperFor: privilegedURLs, removal: removal)
+ let moved = Set(result.trashed.map(\.originalURL))
+ let rest = files(Set(apps.filter { !moved.contains($0) }))
+ guard !rest.isEmpty else { return result }
+ let more = await trash(rest, usingHelperFor: privilegedURLs, removal: removal)
+ result.trashed += more.trashed
+ result.failures += more.failures
+ return result
+ }
+
+ private func trash(_ urls: [URL], usingHelperFor privilegedURLs: Set<URL>, removal: UUID) async -> TrashResult {
+ if let refused = refusingAllWhileHistoryCannotBeRead(urls) { return refused }
var result = await trash(urls.filter { !privilegedURLs.contains($0) }, ownedBy: nil, removal: removal)
let helperURLs = urls.filter(privilegedURLs.contains)
guard !helperURLs.isEmpty else { return result }
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index 5df37357..3e5931e7 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -14,8 +14,7 @@ public struct Uninstallation: Sendable {
/// True when moving the bundle would free less than half the space it takes, because most of its files share
/// their blocks with another copy, such as one in the Trash: `appSize` is then far below the app's size.
public var appSharesStorage = false
- /// True when the app needs administrator rights and the helper may not move it. The app is then never
- /// selected: its leftovers would move first, and the app would stay without them.
+ /// True when the app needs administrator rights and the helper may not move it, so it is never selected.
public var isAppBeyondTheHelper = false
/// True when the app is already in the Trash, where Watch the Trash finds it: its bundle can't move again, so
/// it is never selected or counted, and what it left behind still is.
@@ -178,9 +177,8 @@ public struct Uninstallation: Sendable {
}
/// True when the app itself would stay: excluded, Peel, kept by macOS, part of another package, beyond the
- /// helper, or needing the helper while it is not there. Nothing of it is then selected for the user: what it
- /// left behind would go first, and it would stay without its settings. For an app macOS keeps, what it holds is
- /// data in use.
+ /// helper, or needing the helper while it is not there. Nothing of it is then selected for the user: while it
+ /// stays, its files are not leftovers. For an app macOS keeps, what it holds is data in use.
public func appStays(canUseHelper: Bool) -> Bool {
isExcluded || isPeel || app.isSystemProtected || app.enclosingPackage != nil || isAppBeyondTheHelper
|| (appRequiresPrivileges && !canUseHelper)
@@ -256,13 +254,35 @@ public struct Uninstallation: Sendable {
return urls
}
- /// The selected leftovers, then the app itself.
+ /// The app itself, then the selected leftovers.
public func removalOrder(of selection: Set<URL>) -> [URL] {
guard !isExcluded, !isPeel else { return [] }
return order(of: selection)
}
+ /// Moves `selection`, the app first: its files follow only once it has moved, so an app that stays keeps
+ /// everything of its own. Without the app selected, the files move on their own.
+ public func move(
+ _ selection: Set<URL>,
+ using service: TrashService,
+ throughTheHelper: Bool = true
+ ) async -> TrashResult {
+ let order = removalOrder(of: selection)
+ let files = order.filter { $0 != app.url }
+ return await service.trash(
+ apps: order.filter { $0 == app.url },
+ thenFiles: { stayed in stayed.isEmpty ? files : [] },
+ usingHelperFor: throughTheHelper ? privilegedURLs : []
+ )
+ }
+
+ /// Whether the app stayed while files of its own were selected, which then stayed with it.
+ public func keptItsFiles(after result: TrashResult, selection: Set<URL>) -> Bool {
+ selection.contains(app.url) && result.failures.contains { $0.url == app.url }
+ && !Set(scan.leftovers.map(\.url)).isDisjoint(with: selection)
+ }
+
private func order(of selection: Set<URL>) -> [URL] {
- scan.leftovers.map(\.url).filter(selection.contains) + (selection.contains(app.url) ? [app.url] : [])
+ (selection.contains(app.url) ? [app.url] : []) + scan.leftovers.map(\.url).filter(selection.contains)
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift
index c40c40f5..d5b162b6 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift
@@ -258,7 +258,46 @@ struct BulkUninstallationTests {
#expect(bulk.total == SizeTotal(known: 1_000 + 10, isComplete: false))
}
- @Test func removesLeftoversBeforeTheAppsThemselves() {
+ /// Apps chosen together: an app that stays keeps its files, those it shares with another chosen app included,
+ /// and the others go whole.
+ @Test func anAppThatStaysKeepsItsFilesWhileTheOthersGo() async throws {
+ let directory = try TemporaryDirectory()
+ let stays = InstalledApp(url: try directory.directory("Applications/Stays.app"), bundleIdentifier: "com.example.stays", name: "Stays")
+ let goes = InstalledApp(url: try directory.directory("Applications/Goes.app"), bundleIdentifier: "com.example.goes", name: "Goes")
+ let kept = try directory.directory("home/Library/Caches/com.example.stays")
+ let shared = try directory.directory("home/Library/Application Support/Example")
+ let gone = try directory.directory("home/Library/Caches/com.example.goes")
+ let bulk = BulkUninstallation(uninstallations: [
+ uninstallation(stays, [kept, shared].map { leftover($0.path(percentEncoded: false), size: 1) }),
+ uninstallation(goes, [gone, shared].map { leftover($0.path(percentEncoded: false), size: 1) }),
+ ])
+ let trash = try directory.directory("Trash")
+ let service = TrashService(
+ environment: SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ ) { url in
+ // As macOS refuses an app it won't let Peel move.
+ guard url != stays.url else { throw CocoaError(.fileWriteNoPermission) }
+ let destination = trash.appending(path: UUID().uuidString)
+ try FileManager.default.moveItem(at: url, to: destination)
+ return destination
+ }
+
+ let selection = Set(bulk.items.map(\.url))
+ let result = await bulk.move(selection, using: service)
+
+ #expect(result.failures.map(\.url) == [stays.url])
+ #expect(bulk.appsThatKeptTheirFiles(after: result, selection: selection) == [stays])
+ let moved = Set(result.trashed.map { PathPattern.comparablePath(of: $0.originalURL) })
+ #expect(moved == Set([goes.url, gone].map(PathPattern.comparablePath)))
+ for url in [kept, shared] {
+ #expect(FileManager.default.fileExists(atPath: url.path(percentEncoded: false)), "\(url.lastPathComponent) moved although its app stayed")
+ }
+ }
+
+ @Test func movesTheAppsBeforeTheirFiles() {
let first = app("com.example.one", "One")
let second = app("com.example.two", "Two")
let bulk = BulkUninstallation(uninstallations: [
@@ -269,7 +308,7 @@ struct BulkUninstallationTests {
let selection = bulk.suggestedSelection(canUseHelper: true)
#expect(selection.count == 4)
let order = bulk.removalOrder(of: selection).map { $0.lastPathComponent }
- #expect(order == ["com.example.two", "com.example.one", "One.app", "Two.app"])
+ #expect(order == ["One.app", "Two.app", "com.example.two", "com.example.one"])
#expect(bulk.total == SizeTotal(known: 2030, isComplete: true))
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
index efba0098..9aff93bd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
@@ -49,7 +49,7 @@ struct SelfRemovalTests {
#expect(try String(contentsOf: moved.trashedURL.appending(path: "removals.json"), encoding: .utf8) == "2")
}
- /// When the app stays, its folder stays too, since History there is the way to put back what did move.
+ /// When the app stays, its files and its folder stay too: Peel goes on using them.
@Test func leavesTheFolderWhenTheAppStayed() async throws {
let directory = try TemporaryDirectory()
let app = try directory.directory("home/Applications/Peel.app")
@@ -64,6 +64,7 @@ struct SelfRemovalTests {
) { _ in }
#expect(paths(result.failures.map(\.url)) == paths([app]))
+ #expect(FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)), "a file moved although Peel stayed")
#expect(FileManager.default.fileExists(atPath: folder.path(percentEncoded: false)))
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
index 7108d8bb..7aab7a79 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
@@ -46,7 +46,7 @@ struct UninstallationTests {
let sharedTool = leftover("com.example.app.Sync", confidence: .likely, sharedWith: ["com.example.other"])
let plan = uninstallation(leftovers: [own, named, shared, rootOwned, tool, sharedTool])
- #expect(plan.unreviewedSelection == [own.url, tool.url, app.url])
+ #expect(plan.unreviewedSelection == [app.url, own.url, tool.url])
#expect(uninstallation(appRequiresPrivileges: true, leftovers: [own]).unreviewedSelection.isEmpty)
}
@@ -167,18 +167,18 @@ struct UninstallationTests {
#expect(plan.removalOrder(of: [peel.url, own.url]).isEmpty)
#expect(plan.movable(among: [own], withApp: true).count == 0)
#expect(plan.privilegedURLs.isEmpty)
- #expect(plan.unreviewedSelection == [own.url, peel.url], "Remove Peel no longer takes what is Peel's")
+ #expect(plan.unreviewedSelection == [peel.url, own.url], "Remove Peel no longer takes what is Peel's")
let example = leftover("com.example.app")
let bulk = BulkUninstallation(uninstallations: [plan, uninstallation(leftovers: [example])])
#expect(bulk.suggestedSelection(canUseHelper: true) == [app.url, example.url])
- #expect(bulk.removalOrder(of: [peel.url, own.url, app.url, example.url]) == [example.url, app.url])
+ #expect(bulk.removalOrder(of: [peel.url, own.url, app.url, example.url]) == [app.url, example.url])
#expect(Set(bulk.items.filter(\.isPeels).map(\.url)) == [peel.url, own.url])
#expect(bulk.total.known == 11_000, "Peel's files were counted as something to remove")
}
- /// Leftovers move before the app. If the helper then refused the app, it would stay without them, so an app
- /// the helper may not move is never offered. Neither is an app macOS keeps, wherever it sits.
+ /// An app the helper may not move would stay, and so would everything of its own, so it is never offered.
+ /// Neither is an app macOS keeps, wherever it sits.
@Test(.permissionsHold) func anAppTheHelperMayNotMoveIsNeverOffered() async throws {
let directory = try TemporaryDirectory()
try directory.file("root/Applications/Scribbler.app/Contents/Info.plist", bytes: 4_096)
@@ -530,15 +530,61 @@ struct UninstallationTests {
#expect(place.components == ["\u{301}Foo", "cache.db"])
}
- @Test func movesLeftoversBeforeTheApp() {
+ @Test func movesTheAppBeforeItsLeftovers() {
let first = leftover("first")
let second = leftover("second")
let plan = uninstallation(leftovers: [first, second])
- #expect(plan.removalOrder(of: [app.url, second.url, first.url]) == [first.url, second.url, app.url])
+ #expect(plan.removalOrder(of: [app.url, second.url, first.url]) == [app.url, first.url, second.url])
#expect(plan.removalOrder(of: [second.url]) == [second.url])
}
+ /// A service that moves into the test's own Trash and refuses `refused`, as macOS refuses an app it won't let
+ /// Peel move.
+ private func service(in directory: borrowing TemporaryDirectory, refusing refused: URL?) throws -> TrashService {
+ let trash = try directory.directory("Trash")
+ let environment = SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ )
+ return TrashService(environment: environment) { url in
+ guard url != refused else { throw CocoaError(.fileWriteNoPermission) }
+ let destination = trash.appending(path: UUID().uuidString)
+ try FileManager.default.moveItem(at: url, to: destination)
+ return destination
+ }
+ }
+
+ /// An app's files move only once the app has, so an app that stays keeps everything of its own.
+ @Test func anAppThatStaysKeepsEverythingOfItsOwn() async throws {
+ let directory = try TemporaryDirectory()
+ let bundle = try directory.directory("Applications/Example.app")
+ let cache = try directory.directory("home/Library/Caches/com.example.app")
+ let plan = uninstallation(
+ app: InstalledApp(url: bundle, bundleIdentifier: "com.example.app", name: "Example"),
+ leftovers: [Leftover(
+ url: cache,
+ kind: .caches,
+ match: LeftoverMatch(reason: .bundleIdentifier, confidence: .certain, sharedWith: []),
+ size: 16,
+ isMeasured: true,
+ requiresPrivileges: false
+ )]
+ )
+
+ let stayed = await plan.move([bundle, cache], using: try service(in: directory, refusing: bundle))
+ #expect(stayed.trashed.isEmpty)
+ #expect(stayed.failures.map(\.url) == [bundle])
+ #expect(FileManager.default.fileExists(atPath: cache.path(percentEncoded: false)), "a file moved although its app stayed")
+ #expect(plan.keptItsFiles(after: stayed, selection: [bundle, cache]))
+ #expect(!plan.keptItsFiles(after: stayed, selection: [bundle]))
+
+ let went = await plan.move([bundle, cache], using: try service(in: directory, refusing: nil))
+ #expect(went.trashed.map(\.originalURL) == [bundle, cache])
+ #expect(went.failures.isEmpty)
+ #expect(!plan.keptItsFiles(after: went, selection: [bundle, cache]))
+ }
+
/// The receipt is what keeps macOS counting the package as installed, so it goes with the app. A receipt
/// proves an app only up to a separator: `com.example.app2.pkg` is another package's.
@Test func offersTheInstallerReceiptWithTheApp() async throws {
diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swift
index d7a179a5..4f28496a 100644
--- a/Peel/Model/BulkRemovalPlan.swift
+++ b/Peel/Model/BulkRemovalPlan.swift
@@ -119,9 +119,7 @@ final class BulkRemovalPlan {
/// Moves what `request` asked about, whatever has been selected since.
func move(_ request: RemovalRequest) async -> TrashResult {
guard let bulk else { return TrashResult() }
- let urls = bulk.removalOrder(of: request.urls)
- return await TrashService(exclusions: ExclusionsStore.shared.exclusions)
- .trash(urls, usingHelperFor: bulk.privilegedURLs)
+ return await bulk.move(request.urls, using: TrashService(exclusions: ExclusionsStore.shared.exclusions))
}
/// The source History records: up to three app names, or a count in English that History shows in the
diff --git a/Peel/Model/RemovalOutcome.swift b/Peel/Model/RemovalOutcome.swift
index 538893ae..dfc7c3ea 100644
--- a/Peel/Model/RemovalOutcome.swift
+++ b/Peel/Model/RemovalOutcome.swift
@@ -17,6 +17,8 @@ final class RemovalOutcome {
private(set) var privacy: [Privacy] = []
/// The apps to quit before what their tools kept can move.
private(set) var appsToQuit: [String] = []
+ /// The apps that stayed while files of their own were selected, which stayed with them.
+ private(set) var keptTheirFiles: [String] = []
private(set) var movedCount = 0
var isEmpty: Bool { failures.isEmpty && privacy.isEmpty && appsToQuit.isEmpty }
@@ -26,7 +28,8 @@ final class RemovalOutcome {
func report(
_ result: TrashResult,
privacy resets: [(app: InstalledApp, result: PrivacyReset.Result)] = [],
- appsToQuit: [String] = []
+ appsToQuit: [String] = [],
+ keptTheirFiles: [String] = []
) {
let privacy = PrivacyReset.worthTelling(resets, after: result).map {
Privacy(app: $0.app.name, result: $0.result)
@@ -36,6 +39,7 @@ final class RemovalOutcome {
movedCount = result.trashed.count
self.privacy = privacy
self.appsToQuit = appsToQuit
+ self.keptTheirFiles = keptTheirFiles
}
func clear() {
@@ -43,5 +47,6 @@ final class RemovalOutcome {
movedCount = 0
privacy = []
appsToQuit = []
+ keptTheirFiles = []
}
}
diff --git a/Peel/Model/RemovalPlan.swift b/Peel/Model/RemovalPlan.swift
index 2caa26c8..42a55193 100644
--- a/Peel/Model/RemovalPlan.swift
+++ b/Peel/Model/RemovalPlan.swift
@@ -153,13 +153,11 @@ final class RemovalPlan {
/// Moves what `request` asked about, whatever has been selected since.
func move(_ request: RemovalRequest) async -> TrashResult {
- let urls = uninstallation?.removalOrder(of: request.urls) ?? []
+ guard let uninstallation else { return TrashResult() }
// These paths are about to hold something else, or nothing, so their cached icons are dropped.
- IconCache.forget(urls)
- return await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(
- urls,
- usingHelperFor: uninstallation?.privilegedURLs ?? []
- )
+ IconCache.forget(uninstallation.removalOrder(of: request.urls))
+ let service = TrashService(exclusions: ExclusionsStore.shared.exclusions)
+ return await uninstallation.move(request.urls, using: service)
}
/// The app's processes that run now, the helpers it ships included, which quit before any of its files move.
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index 3d499de1..cf938399 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -466,7 +466,8 @@ struct AppDetailView: View {
// The one step that goes before the move: `tccutil` only finds an app that is still in its place.
let privacy = await PrivacyReset.reset(resetting(request.urls))
let result = await plan.move(request)
- outcome.report(result, privacy: privacy)
+ let keptItsFiles = plan.uninstallation?.keptItsFiles(after: result, selection: request.urls) == true
+ outcome.report(result, privacy: privacy, keptTheirFiles: keptItsFiles ? [plan.app.name] : [])
if removesDockTile, result.trashed.contains(where: { $0.originalURL == plan.app.url }) {
_ = await DockTiles().takeOut([plan.app.url])
}
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index c3db5c96..a5af2ee1 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -349,7 +349,8 @@ struct MultipleAppsView: View {
// The privacy reset runs before the move, because `tccutil` only finds an app that is still in its place.
let privacy = await PrivacyReset.reset(resetting(request.urls))
let result = await plan.move(request)
- outcome.report(result, privacy: privacy)
+ let kept = plan.bulk?.appsThatKeptTheirFiles(after: result, selection: request.urls) ?? []
+ outcome.report(result, privacy: privacy, keptTheirFiles: kept.map(\.name))
if removesDockTiles {
let moved = Set(result.trashed.map(\.originalURL))
_ = await DockTiles().takeOut(appsInTheDock.filter(moved.contains).sorted { $0.path < $1.path })
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index 46ec7fd7..aceb4451 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -52,10 +52,15 @@ struct RemovalFailureAlert: ViewModifier {
if rest > 0 {
lines.append(String(inflecting: "And ^[\(rest) more item](inflect: true)."))
}
- lines += extraLines
+ lines += keptLines + extraLines
return lines.joined(separator: "\n\n")
}
+ /// A line for each app that stayed, since its files, which wait for it, stayed too and are not listed.
+ private var keptLines: [String] {
+ outcome.keptTheirFiles.map { String(localized: "\($0) stayed, and so did its files.") }
+ }
+
private var extraLines: [String] {
var lines: [String] = []
if needsAppManagement {
@@ -68,7 +73,8 @@ struct RemovalFailureAlert: ViewModifier {
/// Copies every item with its full path, since the alert lists only the first few and its text can't be
/// selected.
private func copyDetails() {
- let lines = quitLines + outcome.failures.map { "\($0.url.path(percentEncoded: false))\n\($0.reason.explanation)" } + extraLines
+ let lines = quitLines + outcome.failures.map { "\($0.url.path(percentEncoded: false))\n\($0.reason.explanation)" }
+ + keptLines + extraLines
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(lines.joined(separator: "\n\n"), forType: .string)
}