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.

A project too large to read says it can't tell when it changed

Țugui Dragoș69c6e90b26eb
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 2349871b..68f1f88c 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -130458,6 +130458,112 @@
}
}
},
+ "Too large to tell when it last changed" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Příliš velký na to, aby šlo poznat, kdy se naposledy změnil"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zu groß, um zu sagen, wann es sich zuletzt geändert hat"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Demasiado grande para saber cuándo cambió por última vez"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Trop volumineux pour savoir quand il a été modifié pour la dernière fois"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Troppo grande per capire quando è cambiato l’ultima volta"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "大きすぎるため、最後にいつ変更されたか判断できません"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "너무 커서 마지막으로 변경된 시점을 알 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Te groot om te zien wanneer het voor het laatst is gewijzigd"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Zbyt duży, by określić, kiedy ostatnio się zmienił"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Grande demais para o Peel saber quando mudou pela última vez"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Prea mare pentru a spune când s‑a modificat ultima dată"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Слишком велик, чтобы определить, когда он последний раз изменялся"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "För stort för att avgöra när det senast ändrades"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "En son ne zaman değiştiğini anlamak için fazla büyük"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Завеликий, щоб визначити, коли він востаннє змінювався"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "太大,无法判断它上次更改的时间"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "太大,無法判斷上次變更的時間"
+ }
+ }
+ }
+ },
"Too many items in one request." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index b99d3819..7d28eea2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -36,6 +36,22 @@ public enum ProjectArtifacts {
/// A project changed within this time is in use, so none of its artifacts are selected for the user.
public static let recentlyActive: TimeInterval = 7 * 24 * 60 * 60
+ /// When a project's own files last changed, as far as its artifacts' walks could tell.
+ public enum LastChange: Sendable, Equatable {
+ /// Seen within `recentlyActive`, which is true however much of the project was read.
+ case recently
+ case at(Date)
+ /// The project was too large to read whole, so the newest date seen is only a sample's.
+ case notKnown
+ case none
+ }
+
+ public static func lastChange(of artifacts: [ProjectArtifact]) -> LastChange {
+ if artifacts.contains(where: \.isRecentlyActive) { return .recently }
+ if artifacts.contains(where: { !$0.lastActivityIsCertain }) { return .notKnown }
+ return artifacts.compactMap(\.lastActivity).max().map { .at($0) } ?? .none
+ }
+
/// The artifacts to leave out of Time Machine: never one with a generic name, since the mark travels with the
/// folder, even into a copy of it (`man tmutil`).
public static func markableForBackups(_ artifacts: [ProjectArtifact], excludedFromAbove: Set<URL>) -> [URL] {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index b4361275..6bcd920c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -56,6 +56,26 @@ struct ProjectArtifactsTests {
#expect(ProjectArtifacts.markableForBackups([modules], excludedFromAbove: [modules.url]).isEmpty)
}
+ @Test func saysWhenAProjectLastChangedOnlyWhenItKnows() {
+ func artifact(_ name: String, changed: Date?, certain: Bool) -> ProjectArtifact {
+ let project = URL(filePath: "/Users/x/Code/App")
+ var artifact = ProjectArtifact(
+ url: project.appending(path: name), project: project, name: name, tool: "tool", size: 10,
+ lastActivity: changed, hasGenericName: false, isEnvironment: false
+ )
+ artifact.lastActivityIsCertain = certain
+ return artifact
+ }
+ let monthsAgo = Date.now.addingTimeInterval(-90 * 86_400)
+ let yesterday = Date.now.addingTimeInterval(-86_400)
+
+ let known = artifact("build", changed: monthsAgo, certain: true)
+ #expect(ProjectArtifacts.lastChange(of: [known]) == .at(monthsAgo))
+ #expect(ProjectArtifacts.lastChange(of: [artifact("build", changed: monthsAgo, certain: false)]) == .notKnown)
+ #expect(ProjectArtifacts.lastChange(of: [artifact("build", changed: yesterday, certain: false)]) == .recently)
+ #expect(ProjectArtifacts.lastChange(of: [artifact("build", changed: nil, certain: true)]) == .none)
+ }
+
@Test(.permissionsHold) func doesNotBlameFullDiskAccessForOrdinaryPermissions() async throws {
let directory = try TemporaryDirectory()
try directory.file("Code/app/package.json", bytes: 16)
diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swift
index b9365243..291547bc 100644
--- a/Peel/Model/ProjectLibrary.swift
+++ b/Peel/Model/ProjectLibrary.swift
@@ -10,8 +10,7 @@ struct ProjectGroup: Identifiable, Hashable {
var id: URL { project }
var total: SizeTotal { SizeTotal(artifacts.map(\.size)) }
- var lastActivity: Date? { artifacts.compactMap(\.lastActivity).max() }
- var isRecentlyActive: Bool { artifacts.contains { $0.isRecentlyActive } }
+ var lastChange: ProjectArtifacts.LastChange { ProjectArtifacts.lastChange(of: artifacts) }
}
@Observable
diff --git a/Peel/Views/Projects/ProjectDetailView.swift b/Peel/Views/Projects/ProjectDetailView.swift
index 8ba2326d..f353a288 100644
--- a/Peel/Views/Projects/ProjectDetailView.swift
+++ b/Peel/Views/Projects/ProjectDetailView.swift
@@ -85,7 +85,7 @@ struct ProjectDetailView: View {
.foregroundStyle(.secondary)
.lineLimit(1)
.truncationMode(.middle)
- if group.isRecentlyActive {
+ if group.lastChange == .recently {
NoteBadge(
title: Text("Changed in the last 7 days"), systemImage: "hand.raised", tint: .secondary,
name: String(localized: "Changed in the last 7 days"),
diff --git a/Peel/Views/Projects/ProjectList.swift b/Peel/Views/Projects/ProjectList.swift
index ff0d50f1..60483860 100644
--- a/Peel/Views/Projects/ProjectList.swift
+++ b/Peel/Views/Projects/ProjectList.swift
@@ -149,12 +149,17 @@ private struct ProjectRow: View {
Text(verbatim: group.project.lastPathComponent)
.lineLimit(1)
} details: {
- if group.isRecentlyActive {
+ switch group.lastChange {
+ case .recently:
Text("Changed in the last 7 days")
.rowTint(Color.accentColor)
- } else if let last = group.lastActivity {
+ case .at(let last):
Text("Last changed \(last, format: .relative(presentation: .named))")
.lineLimit(1)
+ case .notKnown:
+ Text("Too large to tell when it last changed")
+ case .none:
+ EmptyView()
}
} trailing: {
Text(group.total.text)