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.

Say what the helper's two fixed refusals mean for the item

Țugui Dragoș29946413fa62
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 7ad71626..0712e2fc 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -82270,6 +82270,112 @@
}
}
},
+ "It still leads to %@ on this Mac." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Stále vede na %@ v tomto Macu."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Der Link führt noch zu %@ auf diesem Mac."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aún lleva a %@ en este Mac."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il mène encore à %@ sur ce Mac."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Punta ancora a %@ su questo Mac."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このMacの%@をまだ指しています。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "아직 이 Mac에 있는 %@(으)로 연결됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het leidt nog steeds naar %@ op deze Mac."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nadal prowadzi do %@ na tym Macu."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ainda aponta para %@ neste Mac."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Încă duce la %@ de pe acest Mac."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ссылка все еще ведет к %@ на этом Mac."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Länken leder fortfarande till %@ på den här datorn."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hâlâ bu Mac’teki %@ konumunu gösteriyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Посилання досі веде до %@ на цьому Mac."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它仍指向这台Mac上的%@。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它仍指向這部Mac上的%@。"
+ }
+ }
+ }
+ },
"It still leads to something on this Mac." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index ecce1896..196bda4b 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -659,6 +659,7 @@ extension TrashFailure.Reason {
"in use as an input source; in System Settings > Keyboard > Text Input, click Edit beside Input Sources, select it and click Remove, then try again"
case .inUseByMacOS(let processes): "in use by macOS (\(processes.map(Output.plain).joined(separator: ", ")))"
case .attachedDiskImage: "a disk image open right now; eject it, then try again"
+ case .stillLeadsTo(let target): "still leads to \(Output.plain(target)) on this Mac"
case .failed(let message): Output.plain(message)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index c85c81de..3e70caec 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -122,6 +122,8 @@ public struct TrashFailure: Sendable, Hashable {
case inUseByMacOS(by: [String])
/// It is a disk image attached right now, or a folder holding one, which macOS holds open until it is ejected.
case attachedDiskImage
+ /// A link the helper takes only once it leads nowhere still leads to this path.
+ case stillLeadsTo(String)
case failed(String)
}
@@ -146,7 +148,7 @@ extension TrashFailure.Reason {
.movedWithoutATrace,
.somethingElseMoved, .heldOpen, .heldOpenByAJob, .peelRunsFromIt, .heldByAnotherAccount,
.openForAnotherUser,
- .heldByABuildTool, .inUseAsAnInputSource, .inUseByMacOS, .attachedDiskImage, .failed: true
+ .heldByABuildTool, .inUseAsAnInputSource, .inUseByMacOS, .attachedDiskImage, .stillLeadsTo, .failed: true
}
}
@@ -184,6 +186,7 @@ extension TrashFailure.Reason {
case .inUseAsAnInputSource: "in-use-as-an-input-source"
case .inUseByMacOS: "in-use-by-macos"
case .attachedDiskImage: "attached-disk-image"
+ case .stillLeadsTo: "still-leads-to"
case .failed: "failed"
}
}
@@ -192,6 +195,7 @@ extension TrashFailure.Reason {
switch self {
case .guarded(let refusal): refusal?.detail
case .failed(let message): message
+ case .stillLeadsTo(let target): target
case .somethingElseMoved(let name): name
case .historyCannotBeWritten(let problem): problem?.detail
case .heldOpen(let processes), .heldOpenByAJob(let processes), .heldByAnotherAccount(let processes),
@@ -234,6 +238,7 @@ extension TrashFailure.Reason {
case "in-use-as-an-input-source": self = .inUseAsAnInputSource
case "in-use-by-macos": self = .inUseByMacOS(by: (detail ?? "").split(separator: "\n").map(String.init))
case "attached-disk-image": self = .attachedDiskImage
+ case "still-leads-to": self = .stillLeadsTo(detail ?? "")
case "failed": self = .failed(detail ?? "")
default: return nil
}
@@ -796,7 +801,7 @@ public struct TrashService: Sendable {
journal?.note(moved.trashed, batch: removal)
MoveCount.current?.add(moved.trashed.count)
helperResult.trashed += moved.trashed
- helperResult.failures += moved.failures
+ helperResult.failures += moved.failures.map(explained)
}
}
ownMoves.ended(landedAt: helperResult.trashed.map(\.trashedURL))
@@ -817,6 +822,20 @@ public struct TrashService: Sendable {
return await stopJobs(jobs.filter { moved.contains($0.plist) }, canUseHelper)
}
+ /// A helper's refusal with what Peel can tell of the item from here, since the helper sends only its fixed
+ /// sentence: the guard's own reason for something it holds, or where a link still leads.
+ private func explained(_ failure: TrashFailure) -> TrashFailure {
+ guard case .failed(let message) = failure.reason, let sentence = FixedSentence(message) else { return failure }
+ let reason: TrashFailure.Reason? = switch sentence {
+ case .irreplaceable: removalGuard.refusal(of: failure.url).map { .guarded($0) }
+ case .leadsSomewhere:
+ (try? FileManager.default.destinationOfSymbolicLink(atPath: failure.url.path(percentEncoded: false)))
+ .map { .stillLeadsTo($0) }
+ default: nil
+ }
+ return reason.map { TrashFailure(url: failure.url, reason: $0, error: failure.error) } ?? failure
+ }
+
/// Moves `urls` through the helper. When the helper is not enabled, nothing moves and every item fails with
/// `.needsHelper`.
private static func moveThroughTheHelper(_ urls: [URL]) async -> TrashResult {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index 27986329..637be92a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -1679,4 +1679,37 @@ struct TrashServiceTests {
#expect(throughHelper.withLock { $0 } == [product, makers[0]])
#expect(result.failures.isEmpty)
}
+
+ /// The helper sends only its fixed sentence, so Peel says what it sees of the item itself: here a library that
+ /// landed in the folder between Peel's check and the helper's, and the file a link still leads to.
+ @Test func saysWhatTheHelpersFixedRefusalsMean() async throws {
+ let directory = try TemporaryDirectory()
+ let folder = try directory.directory("home/Library/Caches/org.example.cache")
+ let tool = try directory.file("root/usr/local/lib/org.example/tool")
+ let link = directory.url.appending(path: "root/usr/local/bin/tool")
+ try FileManager.default.createDirectory(at: link.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try FileManager.default.createSymbolicLink(at: link, withDestinationURL: tool)
+ let service = TrashService(
+ environment: SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home"),
+ rootDirectory: directory.url.appending(path: "root")
+ ),
+ moveThroughHelper: { urls in
+ try? FileManager.default.createDirectory(
+ at: folder.appending(path: "Photos Library.photoslibrary"), withIntermediateDirectories: true
+ )
+ return TrashResult(failures: urls.map { url in
+ let refused = url == link ? PrivilegedPathPolicy.Rejection.leadsSomewhere : .irreplaceable
+ return TrashFailure(url: url, reason: .failed(refused.explanation))
+ })
+ },
+ moveToTrash: { _ in throw CocoaError(.fileWriteNoPermission) }
+ )
+
+ let result = await service.trash([folder, link], usingHelperFor: [folder, link])
+
+ let reasons = Dictionary(uniqueKeysWithValues: result.failures.map { ($0.url, $0.reason) })
+ #expect(reasons[folder] == .guarded(.holdsALibrary))
+ #expect(reasons[link] == .stillLeadsTo(tool.path(percentEncoded: false)))
+ }
}
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index e74fa37d..d3341a97 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -232,6 +232,8 @@ extension TrashFailure.Reason {
String(localized: "macOS is using it right now, through \(processes.formatted(.list(type: .and))), so it stays where it is.", bundle: bundle)
case .attachedDiskImage:
String(localized: "It is a disk image that is open right now. Eject it, then try again.", bundle: bundle)
+ case .stillLeadsTo(let target):
+ String(localized: "It still leads to \(URL(filePath: target).abbreviatedPath) on this Mac.", bundle: bundle)
case .failed(let message): FixedSentence.translated(message, in: bundle)
}
}