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.

Say when Peel can't keep its record of who signs each app

Țugui Dragoș4232005a6fbb
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 9564a122..4924e536 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -76891,6 +76891,112 @@
}
}
},
+ "Peel can’t read its record of who signs your apps" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemůže přečíst svůj záznam o tom, kdo podepisuje vaše aplikace"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kann seine Aufzeichnung darüber, wer deine Apps signiert, nicht lesen"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no puede leer su registro de quién firma tus apps"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel ne peut pas lire son registre des signataires de vos apps"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non riesce a leggere il registro di chi firma le tue app"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelはアプリの署名者の記録を読み取れません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 앱 서명자 기록을 읽을 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan zijn registratie van wie je apps ondertekent niet lezen"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie może odczytać swojego zapisu tego, kto podpisuje Twoje aplikacje"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não consegue ler o registro de quem assina seus apps"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu poate citi evidența celor care semnează aplicațiile dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удается прочитать журнал того, кем подписаны Ваши приложения"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kan inte läsa sin förteckning över vem som signerar dina appar"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel, uygulamalarınızı kimin imzaladığına ilişkin kaydını okuyamıyor"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдається прочитати запис про те, хто підписує ваші програми"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel无法读取你的App的签名者记录"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法讀取你的App簽署者記錄"
+ }
+ }
+ }
+ },
"Peel can’t see or remove everything yet" : {
"localizations" : {
"cs" : {
@@ -77951,6 +78057,112 @@
}
}
},
+ "Peel couldn’t save its record of who signs your apps" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nemohl uložit svůj záznam o tom, kdo podepisuje vaše aplikace"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel konnte seine Aufzeichnung darüber, wer deine Apps signiert, nicht speichern"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel no ha podido guardar su registro de quién firma tus apps"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel n’a pas pu enregistrer son registre des signataires de vos apps"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel non è riuscito a salvare il registro di chi firma le tue app"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peelはアプリの署名者の記録を保存できませんでした"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel이 앱 서명자 기록을 저장할 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kon zijn registratie van wie je apps ondertekent niet bewaren"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nie mógł zachować swojego zapisu tego, kto podpisuje Twoje aplikacje"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Peel não conseguiu salvar o registro de quem assina seus apps"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel nu a putut salva evidența celor care semnează aplicațiile dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не удалось сохранить журнал того, кем подписаны Ваши приложения"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kunde inte spara sin förteckning över vem som signerar dina appar"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel, uygulamalarınızı kimin imzaladığına ilişkin kaydını saklayamadı"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel не вдалося зберегти запис про те, хто підписує ваші програми"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel未能保存你的App的签名者记录"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel無法儲存你的App簽署者記錄"
+ }
+ }
+ }
+ },
"Peel couldn’t save the settings %@ has now, so it put nothing back." : {
"localizations" : {
"cs" : {
@@ -123372,6 +123584,218 @@
}
}
},
+ "Until it can, Peel may not warn you when an app’s signer changes." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dokud Peel nedokáže záznam uložit, nemusí vás upozornit, když aplikaci začne podepisovat někdo jiný."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bis Peel die Aufzeichnung speichern kann, warnt es dich möglicherweise nicht, wenn eine App von jemand anderem signiert wird."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hasta que pueda hacerlo, es posible que Peel no te avise cuando cambie quién firma una app."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tant qu’il n’y parvient pas, Peel risque de ne pas vous avertir si le signataire d’une app change."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Finché non ci riesce, Peel potrebbe non avvisarti quando cambia chi firma un’app."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "保存できるようになるまで、Peelはアプリの署名者が変わっても警告できないことがあります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "기록을 저장할 수 있게 되기 전까지, Peel은 앱의 서명자가 바뀔 때 경고하지 못할 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Totdat dat lukt, waarschuwt Peel je misschien niet als de ondertekenaar van een app verandert."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dopóki Peel nie będzie mógł go zachować, może Cię nie ostrzec, gdy aplikację zacznie podpisywać ktoś inny."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Até conseguir, o Peel pode não avisar você quando um app passar a ser assinado por outro desenvolvedor."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Până când o poate salva, Peel s‑ar putea să nu vă avertizeze când se schimbă semnatarul unei aplicații."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Пока это не удастся, Peel может не предупредить Вас, когда приложение начнет подписывать кто-то другой."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tills det går kan det hända att Peel inte varnar dig när det ändras vem som signerar en app."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel kaydı saklayabilene kadar, bir uygulamayı imzalayan değiştiğinde sizi uyarmayabilir."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Доки Peel не зможе зберегти запис, вона може не попередити вас, коли програму почне підписувати хтось інший."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在能够保存该记录之前,Peel可能不会在App的签名者更改时提醒你。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在能儲存這份記錄之前,Peel可能無法在App的簽署者變更時提醒你。"
+ }
+ }
+ }
+ },
+ "Until you start the record over, Peel can’t warn you when an app’s signer changes. Starting over keeps the old file beside a new one." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dokud nezačnete záznam znovu, Peel vás nemůže upozornit, když aplikaci začne podepisovat někdo jiný. Když začnete znovu, starý soubor se ponechá vedle nového."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bis du mit der Aufzeichnung neu beginnst, kann Peel dich nicht warnen, wenn eine App von jemand anderem signiert wird. Wenn du neu beginnst, bleibt die alte Datei neben einer neuen erhalten."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hasta que vuelvas a empezar el registro, Peel no puede avisarte cuando cambie quién firma una app. Al volver a empezar, el archivo antiguo se conserva junto a uno nuevo."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tant que vous n’avez pas recommencé le registre, Peel ne peut pas vous avertir si le signataire d’une app change. Si vous recommencez, l’ancien fichier est conservé à côté d’un nouveau."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Finché non ricominci il registro da capo, Peel non può avvisarti quando cambia chi firma un’app. Se ricominci da capo, il vecchio file viene conservato accanto a uno nuovo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "記録を最初からやり直すまで、Peelはアプリの署名者が変わっても警告できません。最初からやり直すと、古いファイルは新しいファイルの横に保管されます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "사용자가 기록을 처음부터 다시 시작하기 전까지, Peel은 앱의 서명자가 바뀔 때 경고할 수 없습니다. 처음부터 다시 시작하면 이전 파일은 새 파일 옆에 보관됩니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Totdat je opnieuw begint met de registratie, kan Peel je niet waarschuwen als de ondertekenaar van een app verandert. Als je opnieuw begint, wordt het oude bestand naast een nieuw bestand bewaard."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dopóki nie zaczniesz zapisu od nowa, Peel nie będzie mógł Cię ostrzec, gdy aplikację zacznie podpisywać ktoś inny. Gdy zaczniesz od nowa, stary plik zostanie zachowany obok nowego."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Até você recomeçar o registro, o Peel não pode avisar você quando um app passar a ser assinado por outro desenvolvedor. Ao recomeçar, o arquivo antigo é guardado ao lado de um novo."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Până când reîncepeți evidența, Peel nu vă poate avertiza când se schimbă semnatarul unei aplicații. Dacă o reîncepeți, fișierul vechi este păstrat lângă unul nou."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Пока Вы не начнете журнал заново, Peel не сможет предупредить Вас, когда приложение начнет подписывать кто-то другой. Если начать заново, старый файл сохранится рядом с новым."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tills du börjar om förteckningen kan Peel inte varna dig när det ändras vem som signerar en app. När du börjar om sparas den gamla filen bredvid en ny."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Siz kaydı baştan başlatana kadar Peel, bir uygulamayı imzalayan değiştiğinde sizi uyaramaz. Baştan başladığınızda eski dosya yeni bir dosyanın yanında saklanır."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Доки ви не почнете запис наново, Peel не зможе попередити вас, коли програму почне підписувати хтось інший. Коли ви починаєте наново, старий файл зберігається поруч із новим."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在你重新开始该记录之前,Peel无法在App的签名者更改时提醒你。重新开始会将旧文件保留在新文件旁边。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "在你重新開始這份記錄之前,Peel無法在App的簽署者變更時提醒你。重新開始時,舊檔案會保留在新檔案旁邊。"
+ }
+ }
+ }
+ },
"Up to date" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift b/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift
index 1bb77635..1d09d773 100644
--- a/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Updates/TeamRegistry.swift
@@ -8,6 +8,19 @@ public struct TeamRegistry: Sendable {
public let current: String
}
+ /// Why the registry is not keeping its record, which the person is told, since no warning comes meanwhile.
+ public enum Problem: Sendable, Equatable {
+ /// The file cannot be read, so nothing is compared or recorded until the person starts it over.
+ case unreadable
+ /// The file could not be written, so what the last check learned is not kept.
+ case unsaved
+ }
+
+ public struct Outcome: Sendable, Equatable {
+ public let changes: [Change]
+ public let problem: Problem?
+ }
+
struct Entry: Codable, Sendable, Equatable {
/// The first team seen signing the app.
var team: String
@@ -40,11 +53,11 @@ public struct TeamRegistry: Sendable {
/// Records the team of every app, and returns a change for each app signed by a team not known for it. A
/// change is returned on every call until the user acknowledges it, or a known team signs the app again.
/// `current` is empty when no team signs the app, which is what a tampered copy looks like. A registry file
- /// that cannot be read reports nothing and is left as it is.
+ /// that cannot be read reports nothing, is left as it is, and says so.
@concurrent
- public func check(_ apps: [InstalledApp], now: Date = .now) async -> [Change] {
+ public func check(_ apps: [InstalledApp], now: Date = .now) async -> Outcome {
FileLock.whileHeld(beside: url) {
- guard let stored = load() else { return [] }
+ guard let stored = load() else { return Outcome(changes: [], problem: .unreadable) }
var entries = stored
var changes: [Change] = []
@@ -68,20 +81,30 @@ public struct TeamRegistry: Sendable {
if let pending = entry.pending { changes.append(pending) }
}
- if entries != stored { save(entries) }
- return changes
+ let isSaved = entries == stored || save(entries)
+ return Outcome(changes: changes, problem: isSaved ? nil : .unsaved)
}
}
/// Records that the user has seen the pending change, so its team counts as known for this app.
@concurrent
- public func acknowledge(_ bundleIdentifier: String) async {
+ public func acknowledge(_ bundleIdentifier: String) async -> Problem? {
FileLock.whileHeld(beside: url) {
- guard var entries = load(), var entry = entries[bundleIdentifier], let pending = entry.pending else { return }
+ guard var entries = load() else { return .unreadable }
+ guard var entry = entries[bundleIdentifier], let pending = entry.pending else { return nil }
entry.acknowledged = (entry.acknowledged ?? []) + [pending.current]
entry.pending = nil
entries[bundleIdentifier] = entry
- save(entries)
+ return save(entries) ? nil : .unsaved
+ }
+ }
+
+ /// Keeps a registry that cannot be read beside a new one, which the next check starts recording in. A registry
+ /// that reads is left as it is. False when the old file could not be set aside.
+ @concurrent
+ public func startOver() async -> Bool {
+ FileLock.whileHeld(beside: url) {
+ load() != nil || DamagedFile.setAside(url) != nil
}
}
@@ -95,12 +118,17 @@ public struct TeamRegistry: Sendable {
return try? decoder.decode([String: Entry].self, from: data)
}
- private func save(_ entries: [String: Entry]) {
+ private func save(_ entries: [String: Entry]) -> Bool {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .iso8601
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
- guard let data = try? encoder.encode(entries) else { return }
- try? FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
- try? data.write(to: url, options: .atomic)
+ do {
+ let data = try encoder.encode(entries)
+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try data.write(to: url, options: .atomic)
+ return true
+ } catch {
+ return false
+ }
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
index f87d839d..4d6610ea 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateTests.swift
@@ -277,14 +277,14 @@ struct TeamRegistryTests {
InstalledApp(url: URL(filePath: "/Applications/\(identifier).app"), bundleIdentifier: identifier, name: identifier, teamIdentifier: team)
}
- /// A registry that leads nowhere cannot be read, so it reports nothing and is left as it is.
+ /// A registry that leads nowhere cannot be read, so it reports nothing, says so, and is left as it is.
@Test func leavesARegistryItCannotReachAsItIs() async throws {
let directory = try TemporaryDirectory()
let url = directory.url.appending(path: "teams.json")
let path = url.path(percentEncoded: false)
try FileManager.default.createSymbolicLink(atPath: path, withDestinationPath: "/nowhere/teams.json")
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")]).isEmpty)
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")]) == .init(changes: [], problem: .unreadable))
let kind = try FileManager.default.attributesOfItem(atPath: path)[.type] as? FileAttributeType
#expect(kind == .typeSymbolicLink, "the registry was written over")
@@ -296,19 +296,19 @@ struct TeamRegistryTests {
let directory = try TemporaryDirectory()
let url = directory.url.appending(path: "teams.json")
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111"), app("com.example.other", team: nil)]).isEmpty)
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")]).isEmpty)
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111"), app("com.example.other", team: nil)]).changes.isEmpty)
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")]).changes.isEmpty)
- let changed = await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")])
+ let changed = await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).changes
#expect(changed.map(\.previous) == ["AAAA111111"])
#expect(changed.map(\.current) == ["BBBB222222"])
- let nextLaunch = await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")])
+ let nextLaunch = await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).changes
#expect(nextLaunch.map(\.previous) == ["AAAA111111"], "the change was said once and then forgotten")
#expect(nextLaunch.map(\.current) == ["BBBB222222"])
- await TeamRegistry(url: url).acknowledge("com.example.app")
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).isEmpty)
+ #expect(await TeamRegistry(url: url).acknowledge("com.example.app") == nil)
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).changes.isEmpty)
}
/// An app signed again by the team it had has no change left to report.
@@ -316,9 +316,9 @@ struct TeamRegistryTests {
let directory = try TemporaryDirectory()
let registry = TeamRegistry(url: directory.url.appending(path: "teams.json"))
_ = await registry.check([app("com.example.app", team: "AAAA111111")])
- #expect(await registry.check([app("com.example.app", team: "BBBB222222")]).count == 1)
+ #expect(await registry.check([app("com.example.app", team: "BBBB222222")]).changes.count == 1)
- #expect(await registry.check([app("com.example.app", team: "AAAA111111")]).isEmpty)
+ #expect(await registry.check([app("com.example.app", team: "AAAA111111")]).changes.isEmpty)
}
/// Someone who tampers with an app has no Developer ID for it, so a known team followed by none is the
@@ -330,12 +330,12 @@ struct TeamRegistryTests {
let start = Date(timeIntervalSince1970: 1_800_000_000)
_ = await registry.check([app("com.example.app", team: "AAAA111111")], now: start)
- #expect(await registry.check([app("com.example.app", team: nil)], now: start.addingTimeInterval(60)).isEmpty, "said at once, which an update in progress would trigger")
- let later = await registry.check([app("com.example.app", team: nil)], now: start.addingTimeInterval(60 + TeamRegistry.settlingTime + 1))
+ #expect(await registry.check([app("com.example.app", team: nil)], now: start.addingTimeInterval(60)).changes.isEmpty, "said at once, which an update in progress would trigger")
+ let later = await registry.check([app("com.example.app", team: nil)], now: start.addingTimeInterval(60 + TeamRegistry.settlingTime + 1)).changes
#expect(later.map(\.previous) == ["AAAA111111"])
#expect(later.map(\.current) == [""])
- #expect(await registry.check([app("com.example.app", team: "AAAA111111")], now: start.addingTimeInterval(7_200)).isEmpty, "signed again by the team it had")
+ #expect(await registry.check([app("com.example.app", team: "AAAA111111")], now: start.addingTimeInterval(7_200)).changes.isEmpty, "signed again by the team it had")
}
/// Two copies of one app signed by different teams are acknowledged once. Otherwise each copy would count as
@@ -346,10 +346,10 @@ struct TeamRegistryTests {
let copies = [app("com.example.app", team: "AAAA111111"), app("com.example.app", team: "BBBB222222")]
_ = await registry.check([copies[0]])
- #expect(await registry.check(copies).map(\.current) == ["BBBB222222"])
- await registry.acknowledge("com.example.app")
- #expect(await registry.check(copies).isEmpty)
- #expect(await registry.check(copies.reversed()).isEmpty)
+ #expect(await registry.check(copies).changes.map(\.current) == ["BBBB222222"])
+ #expect(await registry.acknowledge("com.example.app") == nil)
+ #expect(await registry.check(copies).changes.isEmpty)
+ #expect(await registry.check(copies.reversed()).changes.isEmpty)
}
@Test func writesNothingWhenNothingChanged() async throws {
@@ -374,11 +374,60 @@ struct TeamRegistryTests {
try directory.setPermissions(0o000, of: "teams.json")
defer { try? directory.setPermissions(0o644, of: "teams.json") }
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).isEmpty)
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]) == .init(changes: [], problem: .unreadable))
try directory.setPermissions(0o644, of: "teams.json")
#expect(try Data(contentsOf: url) == before)
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).count == 1)
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).changes.count == 1)
+ }
+
+ /// A registry that cannot be read says so on every check, never silently, and starting it over keeps the old
+ /// file beside a new one, which records who signs each app from then on.
+ @Test func startsARegistryItCannotReadOverWhenAsked() async throws {
+ let directory = try TemporaryDirectory()
+ let url = try directory.file("teams.json", contents: Data("{".utf8))
+ let registry = TeamRegistry(url: url)
+
+ #expect(await registry.check([app("com.example.app", team: "AAAA111111")]) == .init(changes: [], problem: .unreadable))
+ #expect(await registry.acknowledge("com.example.app") == .unreadable)
+ #expect(try Data(contentsOf: url) == Data("{".utf8))
+
+ #expect(await registry.startOver())
+ let kept = try FileManager.default.contentsOfDirectory(atPath: directory.url.path(percentEncoded: false))
+ #expect(kept.contains { $0.hasPrefix("teams-damaged-") && $0.hasSuffix(".json") })
+ #expect(await registry.check([app("com.example.app", team: "AAAA111111")]) == .init(changes: [], problem: nil))
+ #expect(await registry.check([app("com.example.app", team: "BBBB222222")]).changes.map(\.current) == ["BBBB222222"])
+ }
+
+ /// Starting over sets aside only a registry that cannot be read. One that reads is what tells a change of
+ /// signer apart, so it stays.
+ @Test func startsOverOnlyARegistryItCannotRead() async throws {
+ let directory = try TemporaryDirectory()
+ let url = directory.url.appending(path: "teams.json")
+ let registry = TeamRegistry(url: url)
+ _ = await registry.check([app("com.example.app", team: "AAAA111111")])
+
+ #expect(await registry.startOver())
+ let files = try FileManager.default.contentsOfDirectory(atPath: directory.url.path(percentEncoded: false))
+ #expect(!files.contains { $0.hasPrefix("teams-damaged-") })
+ #expect(await registry.check([app("com.example.app", team: "BBBB222222")]).changes.map(\.previous) == ["AAAA111111"])
+ }
+
+ /// A registry that cannot be saved has not recorded what the check learned, so it says so rather than let the
+ /// next launch start again from the apps as they are then.
+ @Test func saysWhenTheRegistryCannotBeSaved() async throws {
+ let directory = try TemporaryDirectory()
+ _ = try directory.directory("Peel")
+ let url = directory.url.appending(path: "Peel/teams.json")
+ try directory.setPermissions(0o555, of: "Peel")
+ defer { try? directory.setPermissions(0o755, of: "Peel") }
+
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")]) == .init(changes: [], problem: .unsaved))
+ #expect(url.isMissing)
+
+ try directory.setPermissions(0o755, of: "Peel")
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "AAAA111111")]) == .init(changes: [], problem: nil))
+ #expect(!url.isMissing)
}
/// A registry written by an earlier version of Peel has no pending changes in it, and still reads.
@@ -386,7 +435,7 @@ struct TeamRegistryTests {
let directory = try TemporaryDirectory()
let url = try directory.file("teams.json", contents: Data(#"{"com.example.app":{"firstSeen":"2026-01-01T00:00:00Z","team":"AAAA111111"}}"#.utf8))
- #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).map(\.previous) == ["AAAA111111"])
+ #expect(await TeamRegistry(url: url).check([app("com.example.app", team: "BBBB222222")]).changes.map(\.previous) == ["AAAA111111"])
}
}
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index 6e6c4359..6233d713 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -103,6 +103,8 @@ final class AppLibrary {
private(set) var lastUpdateChecks: [InstalledApp.ID: Date] = [:]
/// Apps whose signing team changed without the user acknowledging it yet, by bundle identifier.
private(set) var teamChanges: [String: TeamRegistry.Change] = [:]
+ /// Why the record of who signs each app is not being kept, or nil while it is.
+ private(set) var teamRecordProblem: TeamRegistry.Problem?
/// The casks Homebrew knows, installed or not, for telling where an app came from and comparing versions.
private(set) var casks: [HomebrewPackage] = []
/// The cask each Homebrew-installed app came from. Matched with the same evidence everything else uses,
@@ -612,13 +614,22 @@ final class AppLibrary {
/// Records the team that signs each app, and keeps the apps whose team changed. The registry reports each
/// change again on every launch until the user acknowledges it.
func checkSigningTeams() async {
- let changes = await teamRegistry.check(apps)
- teamChanges = Dictionary(changes.map { ($0.bundleIdentifier, $0) }, uniquingKeysWith: { first, _ in first })
+ let outcome = await teamRegistry.check(apps)
+ teamChanges = Dictionary(outcome.changes.map { ($0.bundleIdentifier, $0) }, uniquingKeysWith: { first, _ in first })
+ teamRecordProblem = outcome.problem
}
func acknowledgeTeamChange(for app: InstalledApp) async {
teamChanges.removeValue(forKey: app.bundleIdentifier)
- await teamRegistry.acknowledge(app.bundleIdentifier)
+ if let problem = await teamRegistry.acknowledge(app.bundleIdentifier) {
+ teamRecordProblem = problem
+ }
+ }
+
+ /// Keeps a record of signers that cannot be read beside a new one, and records who signs each app now.
+ func startTeamRecordOver() async {
+ guard await teamRegistry.startOver() else { return }
+ await checkSigningTeams()
}
/// Selects an app, adding it first when it lives outside the scanned folders, for example in the Trash.
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index b40fe08c..e07edcd7 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -15,6 +15,9 @@ struct AppList: View {
let row = { (app: InstalledApp) in self.row(for: app, isExcluded: excluded.contains(app.id)) }
List(selection: $library.selection) {
+ if let problem = library.teamRecordProblem {
+ TeamRecordNotice(problem: problem)
+ }
if visible.waiting.isEmpty {
ForEach(visible.rest, content: row)
} else {
@@ -101,6 +104,35 @@ struct AppList: View {
}
}
+/// Says that Peel is not keeping its record of who signs each app, so no change of signer is being reported.
+private struct TeamRecordNotice: View {
+ @Environment(AppLibrary.self) private var library
+ let problem: TeamRegistry.Problem
+
+ var body: some View {
+ Group {
+ switch problem {
+ case .unreadable:
+ Notice(
+ title: Text("Peel can’t read its record of who signs your apps"),
+ detail: Text("Until you start the record over, Peel can’t warn you when an app’s signer changes. Starting over keeps the old file beside a new one.")
+ ) {
+ Button("Start Over") {
+ Task { await library.startTeamRecordOver() }
+ }
+ }
+ case .unsaved:
+ Notice(
+ title: Text("Peel couldn’t save its record of who signs your apps"),
+ detail: Text("Until it can, Peel may not warn you when an app’s signer changes.")
+ ) { EmptyView() }
+ }
+ }
+ .padding(.vertical, 6)
+ .listRowSeparator(.hidden)
+ }
+}
+
/// Writes out what is installed and where each app came from.
private struct ExportMenu: View {
@Environment(AppLibrary.self) private var library