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.

Look for Intel commands under the root an Intel scan is given

Țugui Dragoș7c98a9be5dcb
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
index c9a4b72d..8f032516 100644
--- a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift
@@ -55,7 +55,11 @@ public enum IntelInspector {
.flatMap { library in folders.map { library.appending(path: $0).path(percentEncoded: false) } }
}
- static let toolDirectories = ["/usr/local/bin", "/usr/local/sbin", "/usr/local/libexec"]
+ static func toolDirectories(_ environment: SearchEnvironment) -> [String] {
+ ["usr/local/bin", "usr/local/sbin", "usr/local/libexec"].map {
+ environment.rootDirectory.appending(path: $0).path(percentEncoded: false)
+ }
+ }
/// Folders inside an app whose contents run as processes of their own, so an Intel-only one really does
/// need Rosetta.
@@ -181,7 +185,7 @@ public enum IntelInspector {
// A command that leads into an app listed already is that app's.
let apps = findings.filter { $0.kind == .app }.map { PathPattern.comparablePath(of: $0.url) }
- for tool in tools(in: toolDirectories) where !Task.isCancelled && !exclusions.excludes(tool.url) {
+ for tool in tools(in: toolDirectories(environment)) where !Task.isCancelled && !exclusions.excludes(tool.url) {
let path = PathPattern.comparablePath(of: tool.url)
guard !apps.contains(where: { PathComponents.isPath(path, inside: $0) }) else { continue }
guard isIntelOnly(executable: tool.url), isNew(tool.url) else { continue }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
index b3c15eb6..ef3c416b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift
@@ -250,6 +250,27 @@ struct IntelInspectorTests {
#expect(tools.map { PathPattern.comparablePath(of: $0.url) } == [PathPattern.comparablePath(of: program)])
}
+ @Test func looksForCommandsUnderTheRootItIsGiven() async throws {
+ let directory = try TemporaryDirectory()
+ let tool = try directory.file("root/usr/local/bin/tool", contents: fatHeader([intel]))
+ try directory.setPermissions(0o755, of: tool)
+
+ let scan = await IntelInspector.scan(
+ installedApps: [],
+ plugins: [],
+ backgroundItems: [],
+ exclusions: .none,
+ environment: SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home", directoryHint: .isDirectory),
+ rootDirectory: directory.url.appending(path: "root", directoryHint: .isDirectory)
+ ),
+ measure: { _ in 1 }
+ )
+
+ #expect(scan.findings.map(\.name) == ["tool"])
+ #expect(scan.findings.allSatisfy { $0.kind == .commandLineTool })
+ }
+
/// Every Electron app keeps its helper processes under `Contents/Frameworks`, and Sparkle keeps its
/// XPC services two levels down inside its framework. Those are processes, not libraries.
@Test func findsTheHelperProcessesKeptUnderFrameworks() throws {