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
Ask the helper whether it answers before sending it a request
Țugui Dragoș40f521fe2bd4
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swiftindex 647ca388..fce4c3aa 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/PrivilegedHelper.swift@@ -296,7 +296,19 @@ public enum PrivilegedHelper {fallback: T,_ body: (any PeelHelperProtocol, @escaping @Sendable (T) -> Void) -> Void) async -> T {- await ask(over: helperConnection(), waitingAtMost: requestWait, fallback: fallback, body)+ await request(connecting: helperConnection, fallback: fallback, body)+ }++ /// Sends a request only once the helper has answered, within its own short wait, on a connection of its own: a+ /// helper launchd keeps but cannot start never answers, and the request would wait the longest any request may.+ static func request<T: Sendable>(+ connecting connect: () -> NSXPCConnection?,+ answerWait wait: TimeInterval = answerWait,+ fallback: T,+ _ body: (any PeelHelperProtocol, @escaping @Sendable (T) -> Void) -> Void+ ) async -> T {+ guard await isResponding(over: connect(), waitingAtMost: wait) else { return fallback }+ return await ask(over: connect(), waitingAtMost: requestWait, fallback: fallback, body)}/// A connection that takes only the helper's own code, or nil when Peel has no team to require.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swiftindex c7b56772..4d372c17 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HelperAnswerTests.swift@@ -1,6 +1,7 @@import Foundation@testable import PeelCoreimport PeelPrivileged+import Synchronizationimport Testing/// The helper's version question, under the selector Peel sends.@@ -74,4 +75,34 @@ struct HelperAnswerTests {@Test func withNoConnectionThereIsNoAnswer() async {#expect(await !PrivilegedHelper.isResponding(over: nil))}++ @Test func aRequestIsNeverSentToAHelperThatDoesNotAnswer() async {+ let helper = StandInHelper(answering: nil)+ defer { helper.stop() }+ let sent = Mutex(false)+ let start = ContinuousClock.now++ let answer = await PrivilegedHelper.request(connecting: { helper.connection }, fallback: "unanswered") {+ _, finish in+ sent.withLock { $0 = true }+ finish("answered")+ }++ #expect(answer == "unanswered")+ #expect(!sent.withLock { $0 })+ #expect(ContinuousClock.now - start < .seconds(PrivilegedHelper.requestWait))+ }++ @Test func aRequestIsSentToTheHelperOfThisVersion() async {+ let helper = StandInHelper(answering: HelperIdentity.protocolVersion)+ defer { helper.stop() }++ let answer = await PrivilegedHelper.request(+ connecting: { helper.connection }, answerWait: Self.anyWait, fallback: "unanswered"+ ) { _, finish in+ finish("answered")+ }++ #expect(answer == "answered")+ }}