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.

Make every program a test starts from one app before starting any

Țugui Dragoșd90188fe0862
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
index ec10d3d0..7a0b5007 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SelfRemovalTests.swift
@@ -281,10 +281,13 @@ struct SelfRemovalTests {
@Test func endsOnlyTheExtensionsStillRunningFromTheMovedApp() async throws {
let directory = try TemporaryDirectory()
let app = "Applications/Peel.app"
- let finder = try directory.runningProgram("\(app)/Contents/PlugIns/PeelFinder.appex/Contents/MacOS/PeelFinder")
- let tool = try directory.runningProgram("\(app)/Contents/Helpers/peel")
- let other = try directory.runningProgram("Other.app/Contents/PlugIns/Other.appex/Contents/MacOS/Other")
- defer { [finder, tool, other].forEach { $0.terminate() } }
+ let running = try directory.runningPrograms([
+ "\(app)/Contents/PlugIns/PeelFinder.appex/Contents/MacOS/PeelFinder",
+ "\(app)/Contents/Helpers/peel",
+ "Other.app/Contents/PlugIns/Other.appex/Contents/MacOS/Other",
+ ])
+ let (finder, tool, other) = (running[0], running[1], running[2])
+ defer { running.forEach { $0.terminate() } }
let moved = try directory.directory("Trash").appending(path: "Peel.app")
try FileManager.default.moveItem(at: directory.url.appending(path: app), to: moved)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift b/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift
index cedfbe08..90d70039 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TemporaryDirectory.swift
@@ -84,21 +84,29 @@ struct TemporaryDirectory: ~Copyable {
/// `sleep` is signed ad hoc first. It lives five minutes, longer than the rest of the suite can hold a test back,
/// and each test ends its own.
func runningProgram(_ path: String) throws -> Process {
- let program = url.appending(path: path)
- try FileManager.default.createDirectory(
- at: program.deletingLastPathComponent(),
- withIntermediateDirectories: true
- )
- try FileManager.default.copyItem(at: URL(filePath: "/bin/sleep"), to: program)
- let signing = try Process.run(
- URL(filePath: "/usr/bin/codesign"),
- arguments: ["--force", "--sign", "-", program.path(percentEncoded: false)]
- )
- signing.waitUntilExit()
- guard signing.terminationStatus == 0 else {
- throw CocoaError(.executableLoad, userInfo: [NSFilePathErrorKey: program.path])
+ try runningPrograms([path])[0]
+ }
+
+ /// Every copy is made before any starts: once a program inside an app starts, macOS may refuse to write into it.
+ func runningPrograms(_ paths: [String]) throws -> [Process] {
+ let programs = try paths.map { path in
+ let program = url.appending(path: path)
+ try FileManager.default.createDirectory(
+ at: program.deletingLastPathComponent(),
+ withIntermediateDirectories: true
+ )
+ try FileManager.default.copyItem(at: URL(filePath: "/bin/sleep"), to: program)
+ let signing = try Process.run(
+ URL(filePath: "/usr/bin/codesign"),
+ arguments: ["--force", "--sign", "-", program.path(percentEncoded: false)]
+ )
+ signing.waitUntilExit()
+ guard signing.terminationStatus == 0 else {
+ throw CocoaError(.executableLoad, userInfo: [NSFilePathErrorKey: program.path])
+ }
+ return program
}
- return try Process.run(program, arguments: ["300"])
+ return try programs.map { try Process.run($0, arguments: ["300"]) }
}
func setPermissions(_ permissions: Int, of path: String) throws {