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.

Wrap the helper's long lines at 120 columns

Țugui Dragoșb3fad1a06fd3
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift b/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift
index cb826135..7ebfe17e 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/BrowserWallets.swift
@@ -254,8 +254,12 @@ extension ProtectedData {
/// comes with the listing, so a folder of many files costs no call for each file.
private static func entries(of folder: String) -> [(name: String, isAFile: Bool)] {
let url = URL(filePath: folder, directoryHint: .isDirectory)
- let found = (try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: [.isRegularFileKey])) ?? []
- return found.map { ($0.lastPathComponent, (try? $0.resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile == true) }
+ let found =
+ (try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: [.isRegularFileKey]))
+ ?? []
+ return found.map {
+ ($0.lastPathComponent, (try? $0.resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile == true)
+ }
}
/// True for `name`, inside a folder called `folder`, when it is a wallet extension's storage. Both lowercase.
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/CodeSigning.swift b/Packages/PeelCore/Sources/PeelPrivileged/CodeSigning.swift
index 839dd6ff..7f1b3fbb 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/CodeSigning.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/CodeSigning.swift
@@ -23,7 +23,11 @@ public enum CodeSigning {
guard SecCodeCopyStaticCode(code, [], &staticCode) == errSecSuccess, let staticCode else { return nil }
var information: CFDictionary?
guard
- SecCodeCopySigningInformation(staticCode, SecCSFlags(rawValue: UInt32(kSecCSSigningInformation)), &information) == errSecSuccess,
+ SecCodeCopySigningInformation(
+ staticCode,
+ SecCSFlags(rawValue: UInt32(kSecCSSigningInformation)),
+ &information
+ ) == errSecSuccess,
let team = (information as? [String: Any])?[kSecCodeInfoTeamIdentifier as String] as? String,
isValidTeamIdentifier(team)
else { return nil }
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift b/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift
index 48a48adf..3b04b984 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/DirectoryHandle.swift
@@ -110,15 +110,24 @@ public final class OpenItem: Sendable {
/// The item at `path`, held through a descriptor on the folder it sits in. Links in the folder's path are
/// resolved once, here, and the last component is never followed.
public static func at(_ path: String) -> Result<OpenItem, POSIXError> {
- guard path.hasPrefix("/"), PrivilegedPathPolicy.isPlainlyReadable(path) else { return .failure(POSIXError(.EINVAL)) }
+ guard path.hasPrefix("/"), PrivilegedPathPolicy.isPlainlyReadable(path) else {
+ return .failure(POSIXError(.EINVAL))
+ }
let components = PathComponents.of(path)
guard let name = components.last, !components.contains(where: { $0 == "." || $0 == ".." }) else {
return .failure(POSIXError(.EINVAL))
}
return DirectoryHandle.at("/" + components.dropLast().joined(separator: "/")).flatMap { parent in
var info = stat()
- guard name.withCString({ fstatat(parent.descriptor, $0, &info, AT_SYMLINK_NOFOLLOW) }) == 0 else { return .failure(.last) }
- return .success(OpenItem(path: (parent.path == "/" ? "" : parent.path) + "/" + name, name: name, parent: parent, status: info))
+ guard name.withCString({ fstatat(parent.descriptor, $0, &info, AT_SYMLINK_NOFOLLOW) }) == 0 else {
+ return .failure(.last)
+ }
+ return .success(OpenItem(
+ path: (parent.path == "/" ? "" : parent.path) + "/" + name,
+ name: name,
+ parent: parent,
+ status: info
+ ))
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift b/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift
index b71c0e7b..25dfda53 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/HelperInterface.swift
@@ -20,15 +20,29 @@ public enum HelperIdentity {
/// Replies with two dictionaries keyed by original path: where each moved item now is in the user's
/// Trash, and why each other item failed.
- func moveItemsToTrash(version: Int, atPaths paths: [String], withReply reply: @escaping @Sendable ([String: String], [String: String]) -> Void)
+ func moveItemsToTrash(
+ version: Int,
+ atPaths paths: [String],
+ withReply reply: @escaping @Sendable ([String: String], [String: String]) -> Void
+ )
/// Runs `launchctl` with `command` for the system daemon `label`. Replies with nil on success, or a
/// failure description.
- func runDaemonCommand(version: Int, command: String, label: String, withReply reply: @escaping @Sendable (String?) -> Void)
+ func runDaemonCommand(
+ version: Int,
+ command: String,
+ label: String,
+ withReply reply: @escaping @Sendable (String?) -> Void
+ )
/// Moves an item back from the user's Trash, when the helper's own ledger says it moved that item from
/// exactly there. Replies with nil on success, or a failure description.
- func restoreItem(version: Int, fromTrashPath trashPath: String, toPath destination: String, withReply reply: @escaping @Sendable (String?) -> Void)
+ func restoreItem(
+ version: Int,
+ fromTrashPath trashPath: String,
+ toPath destination: String,
+ withReply reply: @escaping @Sendable (String?) -> Void
+ )
/// Moves the helper's own ledger to the user's Trash, for Remove Peel just before it unregisters the helper.
/// Replies with nil once it is there or when there is none, or a failure description.
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/HelperLedger.swift b/Packages/PeelCore/Sources/PeelPrivileged/HelperLedger.swift
index 97735809..e77f3c28 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/HelperLedger.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/HelperLedger.swift
@@ -72,7 +72,10 @@ public final class HelperLedger: Sendable {
/// Moves the folder the ledger lives in to `trash` and returns where it went, or nil when there is none. It is
/// for Remove Peel, just before the helper goes, since nothing else can move it, and it moves only a folder that
/// is the helper's own and closed to everyone else, as the ledger keeps its folder.
- public static func moveFolder(_ folder: String = defaultFolder, into trash: DirectoryHandle) -> Result<String?, POSIXError> {
+ public static func moveFolder(
+ _ folder: String = defaultFolder,
+ into trash: DirectoryHandle
+ ) -> Result<String?, POSIXError> {
lock.withLock {
switch OpenItem.at(folder) {
case .failure(let error):
@@ -130,7 +133,9 @@ public final class HelperLedger: Sendable {
private func write(_ entries: some Sequence<Entry>) -> Bool {
let encoder = PropertyListEncoder()
encoder.outputFormat = .binary
- guard let data = try? encoder.encode(Array(entries)), (try? data.write(to: url, options: .atomic)) != nil else { return false }
+ guard let data = try? encoder.encode(Array(entries)), (try? data.write(to: url, options: .atomic)) != nil else {
+ return false
+ }
return chmod(url.path(percentEncoded: false), 0o600) == 0
}
}
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift b/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift
index 0a7ef438..41253a25 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/PrivilegedPathPolicy.swift
@@ -180,7 +180,9 @@ public struct PrivilegedPathPolicy: Sendable {
var target = stat()
let leads = item.name.withCString { fstatat(parent.descriptor, $0, &target, 0) } == 0
let error = errno
- guard !leads, error == ENOENT || error == ENOTDIR || error == ELOOP else { return .failure(.leadsSomewhere) }
+ guard !leads, error == ENOENT || error == ENOTDIR || error == ELOOP else {
+ return .failure(.leadsSomewhere)
+ }
}
return .success(OpenItem(path: item.path, name: item.name, parent: parent, status: info))
}
@@ -198,7 +200,9 @@ public struct PrivilegedPathPolicy: Sendable {
guard let mode = trashed.mode, mode & S_IFMT == S_IFLNK else { return .failure(.notALink) }
}
if !restorable.contains(where: { PathComponents.isPath(item.path, inside: $0) }) {
- guard trashed.owner == trustedOwner, let mode = trashed.mode, mode & 0o022 == 0 else { return .failure(.loadsCode) }
+ guard trashed.owner == trustedOwner, let mode = trashed.mode, mode & 0o022 == 0 else {
+ return .failure(.loadsCode)
+ }
}
let parent: DirectoryHandle
switch DirectoryHandle.at(canonical: item.parent) {
@@ -245,7 +249,8 @@ public struct PrivilegedPathPolicy: Sendable {
public static func isValidLabel(_ label: String) -> Bool {
guard (1...255).contains(label.utf8.count), !label.hasPrefix("com.apple.") else { return false }
return label.utf8.allSatisfy { byte in
- (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x5A) || (byte >= 0x61 && byte <= 0x7A) || byte == 0x2E || byte == 0x2D || byte == 0x5F
+ (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x5A) || (byte >= 0x61 && byte <= 0x7A)
+ || byte == 0x2E || byte == 0x2D || byte == 0x5F
} && label.first != "." && label.first != "-"
}
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
index 978e9bf1..75e7f17c 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
@@ -157,7 +157,8 @@ public enum ProtectedData: Sendable {
/// `group.`, `groups.`, or `systemgroup.`.
public static func isApplesName(_ name: String) -> Bool {
var name = Substring(name.lowercased())
- if let dot = name.firstIndex(of: "."), name[..<dot].count == 10, name[..<dot].allSatisfy({ $0.isASCII && ($0.isLetter || $0.isNumber) }) {
+ if let dot = name.firstIndex(of: "."), name[..<dot].count == 10,
+ name[..<dot].allSatisfy({ $0.isASCII && ($0.isLetter || $0.isNumber) }) {
name = name[name.index(after: dot)...]
}
if let prefix = ["group.", "groups.", "systemgroup."].first(where: name.hasPrefix) {
@@ -255,7 +256,9 @@ public enum ProtectedData: Sendable {
let homeNames = PathComponents.of(home)
return spellings(of: path).contains { spelling in
let names = PathComponents.of(spelling)
- guard names.count == homeNames.count + 1, names.starts(with: homeNames), let name = names.last else { return false }
+ guard names.count == homeNames.count + 1, names.starts(with: homeNames), let name = names.last else {
+ return false
+ }
return sharedHomeItemNames.contains(name)
}
}
@@ -334,7 +337,9 @@ public enum ProtectedData: Sendable {
private static func trees(under home: String) -> Trees {
treesByHome.withLock { cache in
if let trees = cache[home] { return trees }
- let trees = Trees(homeTrees.map { PathComponents.of((home as NSString).appendingPathComponent($0).lowercased()) })
+ let trees = Trees(
+ homeTrees.map { PathComponents.of((home as NSString).appendingPathComponent($0).lowercased()) }
+ )
if cache.count >= 32 { cache.removeAll() }
cache[home] = trees
return trees
@@ -359,7 +364,9 @@ public enum ProtectedData: Sendable {
/// around one, and this looks inside the folder instead. It reads the disk.
public static func holdsALibrary(_ path: String) -> Bool {
let folder = URL(filePath: path, directoryHint: .isDirectory)
- let children = (try? FileManager.default.contentsOfDirectory(at: folder, includingPropertiesForKeys: [.isDirectoryKey])) ?? []
+ let children =
+ (try? FileManager.default.contentsOfDirectory(at: folder, includingPropertiesForKeys: [.isDirectoryKey]))
+ ?? []
return children.contains { child in
if isALibrary(child.lastPathComponent.lowercased()) { return true }
guard (try? child.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) == true else { return false }
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/Subprocess.swift b/Packages/PeelCore/Sources/PeelPrivileged/Subprocess.swift
index 5f2de1bb..fea9e120 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/Subprocess.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/Subprocess.swift
@@ -90,7 +90,9 @@ public enum Subprocess {
try? outputPipe.fileHandleForReading.close()
try? errorPipe.fileHandleForReading.close()
if let failure = run.failure { return .failure(failure) }
- return .success(Output(status: process.terminationStatus, standardOutput: standardOutput, standardError: standardError))
+ return .success(
+ Output(status: process.terminationStatus, standardOutput: standardOutput, standardError: standardError)
+ )
}
/// One tool being run: whoever waits for it is woken once, and it is stopped once, for one reason.
@@ -143,7 +145,9 @@ public enum Subprocess {
guard !state.withLock({ $0.hasEnded }), process.isRunning else { return }
kill(process.processIdentifier, SIGKILL)
// A tool stuck in the kernel survives even `SIGKILL`, so the waiter is let go anyway.
- DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + Subprocess.grace) { [self] in ended() }
+ DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + Subprocess.grace) { [self] in
+ ended()
+ }
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/SystemDaemons.swift b/Packages/PeelCore/Sources/PeelPrivileged/SystemDaemons.swift
index 1f033e20..5234bf0b 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/SystemDaemons.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/SystemDaemons.swift
@@ -22,15 +22,20 @@ public enum SystemDaemons {
/// two files declare returns nil.
public static func file(declaring label: String, in directory: String = installed) -> String? {
let contents = (try? FileManager.default.contentsOfDirectory(atPath: directory)) ?? []
- let declaring = contents.lazy.filter { $0.hasSuffix(".plist") }.map { (directory as NSString).appendingPathComponent($0) }.filter { path in
- var info = stat()
- guard lstat(path, &info) == 0, info.st_mode & S_IFMT == S_IFREG, info.st_size <= 1_024 * 1_024 else { return false }
- guard
- let data = FileManager.default.contents(atPath: path),
- let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any]
- else { return false }
- return plist["Label"] as? String == label
- }
+ let declaring = contents.lazy
+ .filter { $0.hasSuffix(".plist") }
+ .map { (directory as NSString).appendingPathComponent($0) }
+ .filter { path in
+ var info = stat()
+ guard lstat(path, &info) == 0, info.st_mode & S_IFMT == S_IFREG, info.st_size <= 1_024 * 1_024 else {
+ return false
+ }
+ guard
+ let data = FileManager.default.contents(atPath: path),
+ let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any]
+ else { return false }
+ return plist["Label"] as? String == label
+ }
let found = Array(declaring.prefix(2))
return found.count == 1 ? found[0] : nil
}
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/TrashMover.swift b/Packages/PeelCore/Sources/PeelPrivileged/TrashMover.swift
index d57499e4..29fad99c 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/TrashMover.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/TrashMover.swift
@@ -9,7 +9,11 @@ public enum TrashMover {
move(item, into: trash, exclusively: renameExclusively)
}
- static func move(_ item: OpenItem, into trash: DirectoryHandle, exclusively: ExclusiveRename) -> Result<String, POSIXError> {
+ static func move(
+ _ item: OpenItem,
+ into trash: DirectoryHandle,
+ exclusively: ExclusiveRename
+ ) -> Result<String, POSIXError> {
let base = (item.name as NSString).deletingPathExtension
let pathExtension = (item.name as NSString).pathExtension
@@ -31,7 +35,11 @@ public enum TrashMover {
}
/// Renames `item` to `name` in `directory` through both descriptors, refusing to replace anything there.
- public static func rename(_ item: OpenItem, to name: String, in directory: DirectoryHandle) -> Result<Void, POSIXError> {
+ public static func rename(
+ _ item: OpenItem,
+ to name: String,
+ in directory: DirectoryHandle
+ ) -> Result<Void, POSIXError> {
rename(item, to: name, in: directory, exclusively: renameExclusively)
}
@@ -41,7 +49,12 @@ public enum TrashMover {
/// A file system that cannot refuse to replace by itself answers `ENOTSUP` (rename(2)), as exFAT does for a free
/// name. There the name is first taken with an empty placeholder of the item's kind, which only a free name
/// allows, and a plain rename then replaces the placeholder.
- static func rename(_ item: OpenItem, to name: String, in directory: DirectoryHandle, exclusively: ExclusiveRename) -> Result<Void, POSIXError> {
+ static func rename(
+ _ item: OpenItem,
+ to name: String,
+ in directory: DirectoryHandle,
+ exclusively: ExclusiveRename
+ ) -> Result<Void, POSIXError> {
switch exclusively(item, name, directory) {
case .failure(let error) where error.code == .ENOTSUP:
return renameOntoPlaceholder(item, to: name, in: directory)
@@ -50,9 +63,15 @@ public enum TrashMover {
}
}
- private static func renameOntoPlaceholder(_ item: OpenItem, to name: String, in directory: DirectoryHandle) -> Result<Void, POSIXError> {
+ private static func renameOntoPlaceholder(
+ _ item: OpenItem,
+ to name: String,
+ in directory: DirectoryHandle
+ ) -> Result<Void, POSIXError> {
var info = stat()
- guard item.name.withCString({ fstatat(item.parent.descriptor, $0, &info, AT_SYMLINK_NOFOLLOW) }) == 0 else { return .failure(.last) }
+ guard item.name.withCString({ fstatat(item.parent.descriptor, $0, &info, AT_SYMLINK_NOFOLLOW) }) == 0 else {
+ return .failure(.last)
+ }
let isFolder = info.st_mode & S_IFMT == S_IFDIR
let placeholder: ItemIdentity
switch makePlaceholder(named: name, in: directory, isFolder: isFolder) {
@@ -71,7 +90,11 @@ public enum TrashMover {
}
/// Makes an empty folder, or an empty file for anything else, at `name`, failing with `EEXIST` when it is taken.
- private static func makePlaceholder(named name: String, in directory: DirectoryHandle, isFolder: Bool) -> Result<ItemIdentity, POSIXError> {
+ private static func makePlaceholder(
+ named name: String,
+ in directory: DirectoryHandle,
+ isFolder: Bool
+ ) -> Result<ItemIdentity, POSIXError> {
var info = stat()
if isFolder {
guard name.withCString({ mkdirat(directory.descriptor, $0, 0o700) }) == 0 else { return .failure(.last) }
@@ -81,7 +104,9 @@ public enum TrashMover {
return .failure(error)
}
} else {
- let file = name.withCString { openat(directory.descriptor, $0, O_CREAT | O_EXCL | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, 0o600) }
+ let file = name.withCString {
+ openat(directory.descriptor, $0, O_CREAT | O_EXCL | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, 0o600)
+ }
guard file >= 0 else { return .failure(.last) }
defer { close(file) }
guard fstat(file, &info) == 0 else { return .failure(.last) }
@@ -90,7 +115,12 @@ public enum TrashMover {
}
/// Takes away the placeholder a failed rename left, only while it is still the one made for it.
- private static func removePlaceholder(_ placeholder: ItemIdentity, named name: String, in directory: DirectoryHandle, isFolder: Bool) {
+ private static func removePlaceholder(
+ _ placeholder: ItemIdentity,
+ named name: String,
+ in directory: DirectoryHandle,
+ isFolder: Bool
+ ) {
var info = stat()
guard
name.withCString({ fstatat(directory.descriptor, $0, &info, AT_SYMLINK_NOFOLLOW) }) == 0,
@@ -99,7 +129,11 @@ public enum TrashMover {
_ = name.withCString { unlinkat(directory.descriptor, $0, isFolder ? AT_REMOVEDIR : 0) }
}
- private static func renameExclusively(_ item: OpenItem, to name: String, in directory: DirectoryHandle) -> Result<Void, POSIXError> {
+ private static func renameExclusively(
+ _ item: OpenItem,
+ to name: String,
+ in directory: DirectoryHandle
+ ) -> Result<Void, POSIXError> {
let moved = item.name.withCString { from in
name.withCString { to in
renameatx_np(item.parent.descriptor, from, directory.descriptor, to, UInt32(RENAME_EXCL))
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/UserAuthorization.swift b/Packages/PeelCore/Sources/PeelPrivileged/UserAuthorization.swift
index 6687f45d..648b5bc6 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/UserAuthorization.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/UserAuthorization.swift
@@ -19,7 +19,12 @@ public enum UserAuthorization {
var administrators = [UInt8](repeating: 0, count: MemoryLayout<uuid_t>.size)
guard
mbr_uid_to_uuid(user, &account) == 0,
- mbr_identifier_to_uuid(ID_TYPE_GROUPNAME, administratorsGroup, administratorsGroup.utf8.count, &administrators) == 0
+ mbr_identifier_to_uuid(
+ ID_TYPE_GROUPNAME,
+ administratorsGroup,
+ administratorsGroup.utf8.count,
+ &administrators
+ ) == 0
else { return false }
var isMember: Int32 = 0
diff --git a/PeelHelper/HelperListenerDelegate.swift b/PeelHelper/HelperListenerDelegate.swift
index 7ab50135..12024f53 100644
--- a/PeelHelper/HelperListenerDelegate.swift
+++ b/PeelHelper/HelperListenerDelegate.swift
@@ -34,7 +34,12 @@ final class HelperListenerDelegate: NSObject, NSXPCListenerDelegate {
let trash = #selector((any PeelHelperProtocol).moveItemsToTrash(version:atPaths:withReply:))
interface.setClasses(classes(NSArray.self, NSString.self), for: trash, argumentIndex: 1, ofReply: false)
for index in 0...1 {
- interface.setClasses(classes(NSDictionary.self, NSString.self), for: trash, argumentIndex: index, ofReply: true)
+ interface.setClasses(
+ classes(NSDictionary.self, NSString.self),
+ for: trash,
+ argumentIndex: index,
+ ofReply: true
+ )
}
return interface
}
diff --git a/PeelHelper/HelperService.swift b/PeelHelper/HelperService.swift
index 08ed4021..4d6d02fe 100644
--- a/PeelHelper/HelperService.swift
+++ b/PeelHelper/HelperService.swift
@@ -34,7 +34,11 @@ final class HelperService: NSObject, PeelHelperProtocol {
reply(HelperIdentity.protocolVersion)
}
- func moveItemsToTrash(version: Int, atPaths paths: [String], withReply finish: @escaping @Sendable ([String: String], [String: String]) -> Void) {
+ func moveItemsToTrash(
+ version: Int,
+ atPaths paths: [String],
+ withReply finish: @escaping @Sendable ([String: String], [String: String]) -> Void
+ ) {
lifetime.requestStarted()
let reply: @Sendable ([String: String], [String: String]) -> Void = { [lifetime] moved, failed in
finish(moved, failed)
@@ -67,13 +71,21 @@ final class HelperService: NSObject, PeelHelperProtocol {
}
// Recorded before anything moves, so no item reaches the Trash without a record. The helper puts
// back only what its ledger lists.
- guard let ledger = HelperLedger(), let result = TrashMover.moveRecorded(items, into: trash, ledger: ledger, movedBy: caller.user) else {
+ guard
+ let ledger = HelperLedger(),
+ let result = TrashMover.moveRecorded(items, into: trash, ledger: ledger, movedBy: caller.user)
+ else {
return refuse(HelperRefusal.cannotKeepRecord.rawValue)
}
reply(result.moved, failed.merging(result.failed) { refused, _ in refused })
}
- func restoreItem(version: Int, fromTrashPath trashPath: String, toPath destination: String, withReply finish: @escaping @Sendable (String?) -> Void) {
+ func restoreItem(
+ version: Int,
+ fromTrashPath trashPath: String,
+ toPath destination: String,
+ withReply finish: @escaping @Sendable (String?) -> Void
+ ) {
lifetime.requestStarted()
let reply = tracked(finish)
let caller: HelperRequest.Caller
@@ -122,7 +134,8 @@ final class HelperService: NSObject, PeelHelperProtocol {
} catch {
return reply(error.rawValue)
}
- guard let trash = PrivilegedPathPolicy(homeDirectory: caller.homeDirectory).openTrash(ownedBy: caller.user) else {
+ guard let trash = PrivilegedPathPolicy(homeDirectory: caller.homeDirectory).openTrash(ownedBy: caller.user)
+ else {
return reply(HelperRefusal.noTrash.rawValue)
}
switch HelperLedger.moveFolder(into: trash) {
@@ -131,7 +144,12 @@ final class HelperService: NSObject, PeelHelperProtocol {
}
}
- func runDaemonCommand(version: Int, command: String, label: String, withReply finish: @escaping @Sendable (String?) -> Void) {
+ func runDaemonCommand(
+ version: Int,
+ command: String,
+ label: String,
+ withReply finish: @escaping @Sendable (String?) -> Void
+ ) {
lifetime.requestStarted()
let reply = tracked(finish)
if case .failure(let refusal) = HelperRequest.admit(version: version, caller: Self.caller) {