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
Keep the update an app's own source found when its next check fails
Țugui Dragoșc3306b3d0d83
diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swiftindex cacd46ca..98c15590 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateChecker.swift@@ -378,6 +378,17 @@ public struct UpdateAnswer: Sendable, Hashable {self.notesPage = notesPageself.standsInFor = standsInFor}++ /// The status to keep when this answer follows `previous`. A check whose own source failed keeps an update that+ /// source found earlier, even where Homebrew answered in its place, since failing to reach the server says+ /// nothing about that update. An update Homebrew reported is kept only while Homebrew gives it.+ public func following(_ previous: UpdateStatus?) -> UpdateStatus {+ if (standsInFor ?? status) == .failed, let previous, case .updateAvailable(_, let source, _) = previous,+ source != .homebrew {+ return previous+ }+ return status+ }}/// What asking for an update's notes came to.diff --git a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swiftindex f346ccfe..17b66c3a 100644--- a/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift+++ b/Packages/PeelCore/Sources/PeelCore/Updates/UpdateFeed.swift@@ -42,13 +42,6 @@ public enum UpdateStatus: Sendable, Hashable, Codable {return source == .homebrew ? String(version.prefix { $0 != "," }) : version}- /// The status to keep when this answer follows `previous`. A failed check keeps an update found earlier,- /// since failing to reach the server says nothing about that update.- public func following(_ previous: UpdateStatus?) -> UpdateStatus {- if self == .failed, case .updateAvailable = previous { return previous ?? self }- return self- }-public var releaseNotes: URL? {if case .updateAvailable(_, _, let notes) = self { notes } else { nil }}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UpdateScheduleTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UpdateScheduleTests.swiftindex abb3cd5f..a2654d4d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UpdateScheduleTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UpdateScheduleTests.swift@@ -139,10 +139,18 @@ struct UpdateScheduleTests {/// A failed round, such as one with no network, learns nothing, so an update known to be waiting stays known.@Test func aFailureDoesNotEraseAnUpdateThatWasWaiting() {let waiting = UpdateStatus.updateAvailable(version: "2.0")- #expect(UpdateStatus.failed.following(waiting) == waiting)- #expect(UpdateStatus.failed.following(.upToDate) == .failed)- #expect(UpdateStatus.failed.following(nil) == .failed)- #expect(UpdateStatus.upToDate.following(waiting) == .upToDate, "a real answer replaces what was known")- #expect(UpdateStatus.updateAvailable(version: "3.0").following(waiting) == .updateAvailable(version: "3.0"))+ let homebrews = UpdateStatus.updateAvailable(version: "2.0", source: .homebrew)+ let failed = UpdateAnswer(status: .failed)+ #expect(failed.following(waiting) == waiting)+ #expect(failed.following(.upToDate) == .failed)+ #expect(failed.following(nil) == .failed)+ #expect(UpdateAnswer(status: .upToDate).following(waiting) == .upToDate, "a real answer replaces what was known")+ #expect(UpdateAnswer(status: .updateAvailable(version: "3.0")).following(waiting) == .updateAvailable(version: "3.0"))++ let homebrewInstead = UpdateAnswer(status: .upToDate, standsInFor: .failed)+ #expect(homebrewInstead.following(waiting) == waiting, "the feed failed")+ #expect(homebrewInstead.following(homebrews) == .upToDate, "Homebrew no longer reports it")+ #expect(failed.following(homebrews) == .failed, "Homebrew no longer reports it")+ #expect(UpdateAnswer(status: .upToDate, standsInFor: .unsupported).following(waiting) == .upToDate)}}diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swiftindex 34240989..4b0c3aa7 100644--- a/Peel/Model/AppLibrary.swift+++ b/Peel/Model/AppLibrary.swift@@ -584,12 +584,14 @@ final class AppLibrary {guard let app = asked[id], apps.contains(where: { $0.id == id && $0.isTheSameBuild(as: app) }) else {continue}- let kept = answer.status.following(updateStatuses[id])+ let kept = answer.following(updateStatuses[id])+ // Homebrew's answer stands in for the app's own only where it is the status kept.+ let standsInFor = kept == answer.status ? answer.standsInFor : nil// Homebrew may have been read again while this answer was on its way: its casks decide where they can.let shown = casks == self.casks? kept: checker.statusWithoutAsking(- for: app, preference: preference, casks: self.casks, known: answer.standsInFor ?? kept+ for: app, preference: preference, casks: self.casks, known: standsInFor ?? kept) ?? kept// Any write redraws the whole Applications list, so an answer that changes nothing is not written.if updateStatuses[id] != shown {@@ -608,7 +610,7 @@ final class AppLibrary {checked: answer.status == .failed ? memory[identifier]?.checked : .now,describing: app,developer: answer.developer ?? memory[identifier]?.developer,- standsInFor: answer.standsInFor+ standsInFor: standsInFor)// Only an answer that found this update can say what is new in it; a failed one keeps what was known.if case .updateAvailable(let version, _, _) = kept, answer.status == kept {diff --git a/PeelTests/AppLibraryTests.swift b/PeelTests/AppLibraryTests.swiftindex 45a5f328..4a83c2aa 100644--- a/PeelTests/AppLibraryTests.swift+++ b/PeelTests/AppLibraryTests.swift@@ -312,6 +312,55 @@ private nonisolated final class TestClock: Sendable {#expect(library.shownUpdateStatus(of: app) == .failed)}+ @Test func homebrewsUpToDateInPlaceOfAFailedFeedLeavesTheUpdateTheFeedFound() async throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ let bundle = try caskApp("Fed", in: folder, feed: "https://feed.example.com/appcast.xml")+ defer { try? FileManager.default.removeItem(at: folder) }+ let made = try MadeUpDefaults()+ defer { made.forget() }+ let clock = TestClock(homebrewChecked + 60 * 60)+ let library = library(with: made.defaults, notesIn: folder, clock: clock)++ #expect(await library.reveal([bundle]))+ let app = try #require(library.apps.first { $0.bundleIdentifier == "org.example.fed" })+ library.loadHomebrewCasks([cask("Fed", checked: homebrewChecked)], knowsItsOwnApps: true)+ AppcastProtocol.body.withLock {+ $0 = Data(#"<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"><channel><item><enclosure url="https://feed.example.com/u.zip" sparkle:version="101" sparkle:shortVersionString="1.1" /></item></channel></rss>"#.utf8)+ }+ await library.checkForUpdates([app], force: true)+ #expect(library.shownUpdateStatus(of: app)?.version == "1.1")++ AppcastProtocol.body.withLock { $0 = Data() }+ await library.checkForUpdates([app], force: true)+ #expect(library.shownUpdateStatus(of: app)?.version == "1.1", "the feed failed")++ clock.set(homebrewChecked + 2 * Homebrew.autoUpdateInterval)+ library.loadHomebrewCasks([cask("Fed", checked: homebrewChecked)], knowsItsOwnApps: true)+ #expect(library.shownUpdateStatus(of: app)?.version == "1.1")+ }++ @Test func aFeedThatFailedKeepsNoUpdateHomebrewNoLongerReports() async throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ let bundle = try caskApp("Fed", in: folder, feed: "https://feed.example.com/appcast.xml")+ defer { try? FileManager.default.removeItem(at: folder) }+ let made = try MadeUpDefaults()+ defer { made.forget() }+ AppcastProtocol.body.withLock { $0 = Data() }+ let clock = TestClock(homebrewChecked + 60 * 60)+ let library = library(with: made.defaults, notesIn: folder, clock: clock)++ #expect(await library.reveal([bundle]))+ let app = try #require(library.apps.first { $0.bundleIdentifier == "org.example.fed" })+ library.loadHomebrewCasks([cask("Fed", latest: "2.0", checked: homebrewChecked)], knowsItsOwnApps: true)+ await library.checkForUpdates([app], force: true)+ #expect(library.shownUpdateStatus(of: app)?.version == "2.0")++ clock.set(homebrewChecked + 2 * Homebrew.autoUpdateInterval)+ library.loadHomebrewCasks([cask("Fed", checked: homebrewChecked)], knowsItsOwnApps: true)+ await library.checkForUpdates([app], force: true)+ #expect(library.shownUpdateStatus(of: app) == .failed)+ }+@Test func anAppPeelNeverChecksGetsNothingFromHomebrew() async throws {let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")let bundle = try caskApp("Tool", in: folder)