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
Read only bundles for an app's identifiers in its frameworks
Țugui Dragoș68f3ed7fb21b
diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swiftindex 36b3d5e9..63ddb355 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/AppInspector.swift@@ -264,7 +264,7 @@ public enum AppInspector {if !isWrapped {var unread: [URL] = []let app = contents.deletingLastPathComponent()- for bundle in IntelInspector.frameworkProcesses(inside: app, unreadable: &unread) {+ for bundle in IntelInspector.frameworkProcesses(inside: app, bundlesOnly: true, unreadable: &unread) {let info = infoDictionary(in: bundle.appending(path: "Contents", directoryHint: .isDirectory))if let identifier = info?["CFBundleIdentifier"] as? String { identifiers.append(identifier) }}diff --git a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swiftindex e1c8fc8b..ef737f3e 100644--- a/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift+++ b/Packages/PeelCore/Sources/PeelCore/Apps/IntelInspector.swift@@ -301,7 +301,8 @@ public enum IntelInspector {/// Electron app keeps its helpers, and those in each framework's `XPCServices` and `Helpers` folders, at the top/// of each version, as Sparkle keeps its updater, and in its `Resources`, as Squirrel does. `Versions/Current` is/// skipped: it is a link to one of the versions beside it, so following it would report the same bundle twice.- static func frameworkProcesses(inside bundle: URL, unreadable: inout [URL]) -> [URL] {+ /// `bundlesOnly` leaves out the files that run, which carry no identifier, and looks at no file to tell.+ static func frameworkProcesses(inside bundle: URL, bundlesOnly: Bool = false, unreadable: inout [URL]) -> [URL] {let frameworks = bundle.appending(path: "Contents/Frameworks", directoryHint: .isDirectory)var found: [URL] = []for url in entries(of: frameworks, unreadable: &unreadable) {@@ -320,25 +321,28 @@ public enum IntelInspector {found += entries(of: folder, unreadable: &unreadable).filter { processExtensions.contains($0.pathExtension.lowercased()) }}- found += processes(in: version, unreadable: &unreadable)+ found += processes(in: version, bundlesOnly: bundlesOnly, unreadable: &unreadable)let resources = version.appending(path: "Resources", directoryHint: .isDirectory)if version != url || resources.isRealFolder {- found += processes(in: resources, unreadable: &unreadable)+ found += processes(in: resources, bundlesOnly: bundlesOnly, unreadable: &unreadable)}}}return found}- /// What in `folder` can run as a process of its own: a bundle that runs as one, or a file that can be run. Links- /// are passed over, since at the top of a framework they lead into a version read on its own.- private static func processes(in folder: URL, unreadable: inout [URL]) -> [URL] {+ /// What in `folder` can run as a process of its own: a bundle that runs as one, or, unless `bundlesOnly`, a file+ /// that can be run. Links are passed over, since at the top of a framework they lead into a version read on its+ /// own.+ private static func processes(in folder: URL, bundlesOnly: Bool = false, unreadable: inout [URL]) -> [URL] {entries(of: folder, unreadable: &unreadable).filter { url in+ let isABundle = processExtensions.contains(url.pathExtension.lowercased())+ guard isABundle || !bundlesOnly else { return false }var info = stat()guard lstat(url.path(percentEncoded: false), &info) == 0 else { return false }switch info.st_mode & S_IFMT {- case S_IFDIR: return processExtensions.contains(url.pathExtension.lowercased())- case S_IFREG: return info.st_mode & 0o111 != 0+ case S_IFDIR: return isABundle+ case S_IFREG: return !bundlesOnly && info.st_mode & 0o111 != 0default: return false}}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swiftindex 8a9db7db..ddba814c 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/IntelInspectorTests.swift@@ -372,6 +372,20 @@ struct IntelInspectorTests {#expect(found.map(\.lastPathComponent).sorted() == ["Autoupdate", "Installer.app", "ShipIt", "Updater.app", "helper"])}+ @Test func readsOnlyTheBundlesAFrameworkKeepsWhenOnlyBundlesAreAsked() throws {+ let directory = try TemporaryDirectory()+ let version = "Universal.app/Contents/Frameworks/Sparkle.framework/Versions/B"+ _ = try bundle(directory, "\(version)/Updater.app", cpuTypes: [intel])+ try directory.setPermissions(0o755, of: try directory.file("\(version)/Autoupdate", contents: intelHeader(fileType: 2)))+ let app = directory.url.appending(path: "Universal.app", directoryHint: .isDirectory)++ let bundles = readable { IntelInspector.frameworkProcesses(inside: app, bundlesOnly: true, unreadable: &$0) }+ let everything = readable { IntelInspector.frameworkProcesses(inside: app, unreadable: &$0) }++ #expect(bundles.map(\.lastPathComponent) == ["Updater.app"])+ #expect(everything.map(\.lastPathComponent).sorted() == ["Autoupdate", "Updater.app"])+ }+/// A Homebrew installed for Intel keeps every command in `/usr/local/bin` as a link into its `Cellar`. The/// program the link leads to is what needs Rosetta, listed under the command's name.@Test func findsTheIntelProgramACommandLinkLeadsTo() throws {