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.

Name the app macOS installed a system extension for in Orphaned Files

Țugui Dragoșdda5350df82c
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index fed8b7d7..d241c82a 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -198516,6 +198516,218 @@
}
}
},
+ "macOS installed these for %@, at %@, which is no longer there." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Systém macOS je nainstaloval pro aplikaci %@ v umístění %@, která už neexistuje."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS hat diese Dateien für die App „%@“ installiert, die unter %@ nicht mehr vorhanden ist."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS los instaló para %@, que estaba en %@ y ya no está."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS a installé ces fichiers pour %@, qui se trouvait à l’emplacement %@ et qui n’est plus là."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS ha installato questi file per %@, che si trovava in %@ e non c’è più."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "これらは、macOSが“%@”のためにインストールしたものですが、このアプリは%@にはもう存在しません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS가 ‘%@’을(를) 위해 이 파일들을 설치했으며, 이 앱은 더 이상 %@에 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS heeft deze geïnstalleerd voor %@, in %@, die er niet meer is."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS zainstalował je dla aplikacji %@, której już nie ma w %@."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O macOS instalou estes itens para %@, em %@, que não existe mais."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS a instalat aceste fișiere pentru aplicația %@ de la %@, care nu mai există."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS установила эти файлы для приложения «%@», которого больше нет в %@."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS har installerat dessa för %@, på %@, som inte längre finns."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS bunları %@ uygulaması için yükledi; %@ konumundaki uygulama artık yerinde değil."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS інсталювала їх для програми «%@», якої вже немає за шляхом %@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS为“%@”安装了这些文件,该App原位于%@,现已不存在。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS為「%@」安裝了這些項目,該App原本位於%@,現已不存在。"
+ }
+ }
+ }
+ },
+ "macOS installed these for %@, which is gone" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Systém macOS je nainstaloval pro aplikaci %@, která už tu není"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS hat diese für die App „%@“ installiert, die nicht mehr vorhanden ist"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS los instaló para %@, que ya no está"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS a installé ces fichiers pour %@, qui a disparu"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS li ha installati per %@, che non c’è più"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOSが、すでになくなった“%@”のためにインストールしたものです"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS가 사라진 앱인 ‘%@’을(를) 위해 이 항목을 설치함"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS heeft deze geïnstalleerd voor %@, die er niet meer is"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS zainstalował je dla aplikacji %@, której już nie ma"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O macOS instalou estes itens para %@, que não existe mais"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS le‑a instalat pentru aplicația %@, care nu mai există"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS установила их для приложения «%@», которого больше нет"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS har installerat dessa för %@, som är borta"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS bunları, artık olmayan %@ uygulaması için yükledi"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS інсталювала їх для програми «%@», якої вже немає"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS为“%@”安装了这些文件,该App已不存在"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS為「%@」安裝了這些項目,該App已不存在"
+ }
+ }
+ }
+ },
"macOS installed this apart from the app that brought it, and keeps its own copy." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 888cc5f9..3dba5acf 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -383,6 +383,7 @@ extension OrphanConfidence {
case .appLeft(let name, let lastSeen): "Peel last saw \(Output.plain(name)) installed on \(Output.day(lastSeen))"
case .untouched(let months): "\(months) months since anything wrote here"
case .nothingClaimsIt, nil: "nothing installed claims these"
+ case .installedForAnAppThatIsGone(let name): "macOS installed these for \(Output.plain(name)), which is gone"
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift b/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift
index d259f0d9..917bb531 100644
--- a/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Extensions/AppExtensions.swift
@@ -24,7 +24,8 @@ public struct AppExtension: Sendable, Hashable, Identifiable {
url: URL?,
election: Election,
teamIdentifier: String?,
- reportedState: String?
+ reportedState: String?,
+ installedFor: String? = nil
) {
self.id = id ?? identifier
self.identifier = identifier
@@ -36,6 +37,7 @@ public struct AppExtension: Sendable, Hashable, Identifiable {
self.election = election
self.teamIdentifier = teamIdentifier
self.reportedState = reportedState
+ self.installedFor = installedFor
}
public enum Kind: String, Sendable, Hashable, CaseIterable {
@@ -83,6 +85,9 @@ public struct AppExtension: Sendable, Hashable, Identifiable {
/// The state `systemextensionsctl` printed, like `activated waiting for user`. Nil for an app extension,
/// since `pluginkit` prints no such state.
public let reportedState: String?
+ /// For a system extension, the path of the app macOS's record says it was installed for: the app it is held
+ /// for, or once that app has moved, the app it was installed from.
+ public let installedFor: String?
/// Tells rows apart in a list. The identifier alone can't: while an app updates a system extension, macOS
/// lists the old and the new version under the same identifier.
public let id: String
@@ -303,7 +308,8 @@ public enum AppExtensions {
url: record?.staged,
election: election(forSystemExtensionState: row.state),
teamIdentifier: row.teamIdentifier,
- reportedState: row.state
+ reportedState: row.state,
+ installedFor: record.flatMap(installedFor)
)
}
}
@@ -362,6 +368,17 @@ public enum AppExtensions {
let version: String?
let staged: URL?
let container: String?
+ /// Where the extension was installed from, inside its app (`originPath`).
+ var origin: String? = nil
+ }
+
+ /// The path of the app a record says its extension was installed for: the app macOS holds it for, or, once
+ /// Finder has moved that app and the record holds none, the app its original copy sat in.
+ static func installedFor(_ record: SystemExtensionRecord) -> String? {
+ if let container = record.container { return container }
+ let names = PathComponents.of(record.origin ?? "")
+ guard let app = names.firstIndex(where: { $0.hasSuffix(".app") }) else { return nil }
+ return "/" + names[...app].joined(separator: "/")
}
/// The record of the extension `systemextensionsctl` listed: the one of its version, or the only one of its
@@ -390,7 +407,8 @@ public enum AppExtensions {
identifier: identifier,
version: [short, build].compactMap(\.self).joined(separator: "/"),
staged: staged.flatMap(URL.init(string:)),
- container: (entry["container"] as? [String: Any])?["bundlePath"] as? String
+ container: (entry["container"] as? [String: Any])?["bundlePath"] as? String,
+ origin: entry["originPath"] as? String
)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift
index 078a2bb9..2c3f36ec 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/Orphan.swift
@@ -15,6 +15,9 @@ public struct OrphanItem: Sendable, Hashable, Identifiable {
public var namedAfter: String?
/// True for a preference file that is no property list (`PreferenceFile.isDamaged`).
public var holdsDamagedSettings = false
+ /// For a copy macOS keeps of a system extension, the path of the app its record says it was installed for, when
+ /// that app is gone.
+ public var installedFor: String?
/// Why the item cannot be selected at all: `RemovalGuard` or the helper would refuse it.
public var leftAlone: HoldBack? {
@@ -57,6 +60,12 @@ public struct OrphanGroup: Sendable, Hashable, Identifiable {
items.compactMap(\.modificationDate).max()
}
+ /// The gone app macOS's record says these system extension copies were installed for, when every item names it.
+ public var installedFor: String? {
+ guard let app = items.first?.installedFor, items.allSatisfy({ $0.installedFor == app }) else { return nil }
+ return app
+ }
+
/// Peel recommends no row it held back, and nothing in a group something may still use: such rows wait to be
/// chosen by hand, as Review Before Removing does on an app's page.
public func selectableRows(canUseHelper: Bool) -> SelectableRows<URL> {
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift
index 28b86ef3..c3b10eee 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanConfidence.swift
@@ -12,7 +12,8 @@ public struct OrphanConfidence: Sendable, Hashable {
/// Nothing installed claims it.
case likely
/// Nothing claims it, and Peel knows why: it saw the app go and nothing wrote here after, nothing has
- /// written here in months, or the files are links into an app that is gone.
+ /// written here in months, the files are links into an app that is gone, or they are system extension
+ /// copies of an app that is gone, which macOS removes at the next restart.
case certain
public static func < (one: Level, other: Level) -> Bool { one.rawValue < other.rawValue }
@@ -38,6 +39,8 @@ public struct OrphanConfidence: Sendable, Hashable {
case onlyTheName(of: String)
/// Nothing installed claims the identifier, which is all Peel can say.
case nothingClaimsIt
+ /// macOS's record of these system extension copies names the app they were installed for, which is gone.
+ case installedForAnAppThatIsGone(name: String)
}
/// A write this recent means something may still be running. A week covers a Mac left unused over a weekend.
@@ -68,6 +71,16 @@ public struct OrphanConfidence: Sendable, Hashable {
if group.items.allSatisfy(\.kind.isForLinks) {
return OrphanConfidence(level: .certain, reasons: [.leadsIntoAnAppThatIsGone])
}
+ // macOS's own record of a system extension says which app it was installed for. macOS may still run a copy
+ // it keeps turned on, so only copies it removes at the next restart are surely unused.
+ if let app = group.installedFor {
+ let name = URL(filePath: app).deletingPathExtension().lastPathComponent
+ let removing = group.items.allSatisfy { $0.heldBack == .systemExtensionGoingAtRestart }
+ return OrphanConfidence(
+ level: removing ? .certain : .likely,
+ reasons: [.installedForAnAppThatIsGone(name: name)]
+ )
+ }
if let app = group.rememberedApp, group.items.allSatisfy({ $0.namedAfter != nil }) {
return OrphanConfidence(level: .unsure, reasons: [.onlyTheName(of: app.name)])
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
index 7a0341c7..9d896d87 100644
--- a/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Orphans/OrphanScanner.swift
@@ -123,10 +123,16 @@ public struct OrphanScanner: Sendable {
let isStaged = { (item: OrphanItem) in
PathComponents.isPath(PathPattern.comparablePath(of: item.url), inside: staged)
}
- let goingAtRestart = found.contains { isStaged($0.item) }
- ? Set((await systemExtensions() ?? []).filter { $0.election == .beingRemoved }.compactMap(\.url)
- .map(PathPattern.comparablePath(of:)))
- : []
+ let extensions = found.contains { isStaged($0.item) } ? await systemExtensions() ?? [] : []
+ let goingAtRestart = Set(
+ extensions.filter { $0.election == .beingRemoved }.compactMap(\.url).map(PathPattern.comparablePath(of:))
+ )
+ let installedFor = Dictionary(
+ extensions.compactMap { copy in
+ copy.url.flatMap { url in copy.installedFor.map { (PathPattern.comparablePath(of: url), $0) } }
+ },
+ uniquingKeysWith: { first, _ in first }
+ )
let folders = manifestFolders
let kept = found.filter {
!exclusions.excludes($0.item.url) && !exclusions.holds($0.item.url)
@@ -137,8 +143,9 @@ public struct OrphanScanner: Sendable {
.map { entry in
var item = entry.item
if isStaged(item) {
- let removing = goingAtRestart.contains(PathPattern.comparablePath(of: item.url))
- item.heldBack = removing ? .systemExtensionGoingAtRestart : .systemExtension
+ let path = PathPattern.comparablePath(of: item.url)
+ item.heldBack = goingAtRestart.contains(path) ? .systemExtensionGoingAtRestart : .systemExtension
+ item.installedFor = installedFor[path].flatMap { URL(filePath: $0).isMissing ? $0 : nil }
return (entry.identifier, item)
}
guard item.requiresPrivileges, item.leftAlone == nil, reach.isBeyond(item.url) else { return entry }
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift
index e58fca89..2dc29963 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AppExtensionsTests.swift
@@ -171,6 +171,22 @@ struct AppExtensionsTests {
#expect(records.last?.staged == nil)
}
+ @Test func knowsTheAppAnExtensionWasInstalledForOnceFinderMovedIt() {
+ let record = { (container: String?, origin: String?) in
+ AppExtensions.SystemExtensionRecord(
+ identifier: "org.example.ext", version: nil, staged: nil, container: container, origin: origin
+ )
+ }
+ let inside = "/Contents/Library/SystemExtensions/org.example.ext.systemextension"
+
+ #expect(AppExtensions.installedFor(record("/Applications/Example.app", "/Applications/Example.app\(inside)"))
+ == "/Applications/Example.app")
+ #expect(AppExtensions.installedFor(record(nil, "/Applications/Suite/Guard.app\(inside)"))
+ == "/Applications/Suite/Guard.app")
+ #expect(AppExtensions.installedFor(record(nil, "/Library/org.example.ext.systemextension")) == nil)
+ #expect(AppExtensions.installedFor(record(nil, nil)) == nil)
+ }
+
/// During an update one identifier has two records, one per version. A row is paired with its own version's
/// record, and with another version's never: no path is better than the path of the other copy. With only
/// one record, the identifier is enough.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 140a8e6d..78c5dcc2 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -95,6 +95,41 @@ struct OrphanScannerTests {
#expect(item(going)?.leftAlone == .systemExtensionGoingAtRestart)
}
+ @Test func namesTheGoneAppMacOSInstalledASystemExtensionFor() async throws {
+ let directory = try TemporaryDirectory()
+ let copy = try directory.directory("root/Library/SystemExtensions/77689A22/org.example.guard.ext.systemextension")
+ let going = try directory.directory("root/Library/SystemExtensions/837351C0/org.example.shield.ext.systemextension")
+ let other = try directory.directory("root/Library/SystemExtensions/5DF88A99/org.example.kept.ext.systemextension")
+ let kept = try directory.directory("root/Applications/Kept.app")
+ let gone = { (name: String) in directory.url.appending(path: "root/Applications/\(name).app") }
+ let copies: [(URL, URL, AppExtension.Election)] = [
+ (copy, gone("Guard"), .on), (going, gone("Shield"), .beingRemoved), (other, kept, .waitingForApproval),
+ ]
+ let extensions = copies.map { url, app, election in
+ AppExtension(
+ identifier: url.deletingPathExtension().lastPathComponent, name: "Extension", kind: .systemExtension,
+ point: nil, owner: nil, url: url, election: election, teamIdentifier: nil,
+ reportedState: nil, installedFor: app.path(percentEncoded: false)
+ )
+ }
+
+ let maker = RememberedApp(
+ bundleIdentifier: "org.example.other", name: "Other", teamIdentifier: nil, lastSeen: .now,
+ lastPath: "/Applications/Other.app"
+ )
+
+ let scan = await scanner(in: directory) { extensions }.scan(installedApps: installed, remembered: [maker])
+ let confidence = { (url: URL) in
+ scan.groups.first { group in group.items.contains { $0.url.lastPathComponent == url.lastPathComponent } }?
+ .confidence
+ }
+
+ #expect(confidence(copy) == OrphanConfidence(level: .likely, reasons: [.installedForAnAppThatIsGone(name: "Guard")]))
+ #expect(confidence(going) == OrphanConfidence(level: .certain, reasons: [.installedForAnAppThatIsGone(name: "Shield")]))
+ #expect(confidence(other)?.reasons.isEmpty == false)
+ #expect(confidence(other)?.reasons.contains(.installedForAnAppThatIsGone(name: "Kept")) == false)
+ }
+
@Test func listsAFileTwoPlacesReachOnce() async throws {
let directory = try TemporaryDirectory()
let recents = "home/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments"
diff --git a/Peel/Views/Orphans/OrphanDetailView.swift b/Peel/Views/Orphans/OrphanDetailView.swift
index 09e90098..211e0ed4 100644
--- a/Peel/Views/Orphans/OrphanDetailView.swift
+++ b/Peel/Views/Orphans/OrphanDetailView.swift
@@ -96,6 +96,12 @@ struct OrphanDetailView: View {
.font(.callout)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
+ } else if let app = group.installedFor {
+ let name = URL(filePath: app).deletingPathExtension().lastPathComponent
+ Text("macOS installed these for \(name), at \((app as NSString).abbreviatingWithTildeInPath), which is no longer there.")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
} else {
Text("No app installed on this Mac claims these files.")
.font(.callout)
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 83a08202..78a21f37 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -378,6 +378,8 @@ extension OrphanConfidence {
Text("^[\(months) month](inflect: true) since anything wrote here")
case .nothingClaimsIt:
Text("No installed app claims these")
+ case .installedForAnAppThatIsGone(let name):
+ Text("macOS installed these for \(name), which is gone")
}
}