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.

Give a build folder one reason it stays, in the app and in peel alike

Țugui Dragoș6c3aeddb125b
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index d0916d4b..ca528cd1 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -650,15 +650,16 @@ struct ProjectsCommand: AsyncParsableCommand {
artifacts.map { [Output.size($0.size), Output.path($0.url), $0.tool ?? "tagged as a cache", note(for: $0)] }
}
- /// Returns why `artifact` is kept, or "suggested". It checks the same conditions as `isRecommended`, and
- /// the two must never disagree.
+ /// Says in words why `artifact` is kept, or "suggested".
static func note(for artifact: ProjectArtifact) -> String {
- if let heldBack = artifact.heldBack { return "\(heldBack.summary), kept" }
- if artifact.isRecentlyActive { return "changed in the last 7 days, kept" }
- if !artifact.lastActivityIsCertain { return "too large to tell when it last changed, kept" }
- if artifact.isEnvironment { return "installed packages, kept" }
- if artifact.hasGenericName { return "name could mean anything, kept" }
- return "suggested"
+ switch artifact.keptBecause {
+ case .heldBack(let heldBack): "\(heldBack.summary), kept"
+ case .installedPackages: "installed packages, kept"
+ case .genericName: "name could mean anything, kept"
+ case .changedRecently: "changed in the last 7 days, kept"
+ case .lastChangeNotKnown: "too large to tell when it last changed, kept"
+ case nil: "suggested"
+ }
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index f8aff277..5f4684d7 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -27,9 +27,26 @@ public struct ProjectArtifact: Sendable, Hashable, Identifiable {
return lastActivity > Date.now.addingTimeInterval(-ProjectArtifacts.recentlyActive)
}
- public var isRecommended: Bool {
- !hasGenericName && !isEnvironment && !isRecentlyActive && lastActivityIsCertain && heldBack == nil
+ public enum Kept: Sendable, Equatable {
+ case heldBack(HoldBack)
+ case installedPackages
+ case genericName
+ case changedRecently
+ case lastChangeNotKnown
}
+
+ /// Why Peel doesn't suggest it, or nil when it does. What time doesn't change comes first, so a folder that will
+ /// never be suggested on its own doesn't read as one that only has to wait.
+ public var keptBecause: Kept? {
+ if let heldBack { return .heldBack(heldBack) }
+ if isEnvironment { return .installedPackages }
+ if hasGenericName { return .genericName }
+ if isRecentlyActive { return .changedRecently }
+ if !lastActivityIsCertain { return .lastChangeNotKnown }
+ return nil
+ }
+
+ public var isRecommended: Bool { keptBecause == nil }
}
extension Collection where Element == ProjectArtifact {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index 95e25412..a0801d92 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -461,6 +461,8 @@ struct FileCommandTests {
(artifact("build", generic: true), "name could mean anything, kept"),
(artifact("slow", size: nil, heldBack: .notMeasured), "not measured in time, kept"),
(artifact("Carthage", heldBack: .holdsRepository), "holds a repository, kept"),
+ (artifact(".venv", certain: false, environment: true), "installed packages, kept"),
+ (artifact("target", lastActivity: .now, generic: true), "name could mean anything, kept"),
]
for (artifact, note) in cases {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index 4e41c535..1481909b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -317,6 +317,30 @@ struct ProjectArtifactsTests {
])
}
+ @Test func saysFirstTheReasonThatTimeDoesNotChange() {
+ let project = URL(filePath: "/Users/me/Developer/App", directoryHint: .isDirectory)
+ func artifact(
+ _ name: String, recent: Bool = false, certain: Bool = true, generic: Bool = false,
+ environment: Bool = false, heldBack: HoldBack? = nil
+ ) -> ProjectArtifact {
+ var artifact = ProjectArtifact(
+ url: project.appending(path: name), project: project, name: name, tool: "Xcode", size: 20,
+ lastActivity: .now.addingTimeInterval(recent ? -60 : -ProjectArtifacts.recentlyActive * 2),
+ hasGenericName: generic, isEnvironment: environment, heldBack: heldBack
+ )
+ artifact.lastActivityIsCertain = certain
+ return artifact
+ }
+
+ #expect(artifact(".venv", certain: false, environment: true).keptBecause == .installedPackages)
+ #expect(artifact("target", recent: true, generic: true).keptBecause == .genericName)
+ #expect(artifact("vendor", generic: true, environment: true, heldBack: .holdsRepository).keptBecause
+ == .heldBack(.holdsRepository))
+ #expect(artifact("build", recent: true).keptBecause == .changedRecently)
+ #expect(artifact("build", certain: false).keptBecause == .lastChangeNotKnown)
+ #expect(artifact("DerivedData").keptBecause == nil && artifact("DerivedData").isRecommended)
+ }
+
@Test func findsWhatJavaScriptToolsBuild() async throws {
try await expectFound([
Kind(artifact: ".nuxt", marker: "nuxt.config.ts", tool: "Nuxt", isGeneric: false),
diff --git a/Peel/Views/Projects/ProjectDetailView.swift b/Peel/Views/Projects/ProjectDetailView.swift
index 1e9040d0..d22735b1 100644
--- a/Peel/Views/Projects/ProjectDetailView.swift
+++ b/Peel/Views/Projects/ProjectDetailView.swift
@@ -141,23 +141,21 @@ struct ProjectDetailView: View {
}
private func warning(for artifact: ProjectArtifact) -> String? {
- if let heldBack = artifact.heldBack {
- return String(localized: heldBack.explanation)
- }
- if artifact.isRecentlyActive {
- return String(localized: "Not selected: something in this project changed in the last 7 days.")
- }
- if artifact.isEnvironment {
- return artifact.name == ".terraform"
+ switch artifact.keptBecause {
+ case .heldBack(let heldBack):
+ String(localized: heldBack.explanation)
+ case .installedPackages:
+ artifact.name == ".terraform"
? String(localized: "Not selected: it holds your current workspace and the last backend configuration, which `terraform init` doesn’t bring back.")
: String(localized: "Not selected: these are installed packages, not build output.")
+ case .genericName:
+ String(localized: "Not selected: a folder called \(artifact.name) could be anyone’s.")
+ case .changedRecently:
+ String(localized: "Not selected: something in this project changed in the last 7 days.")
+ case .lastChangeNotKnown:
+ String(localized: "Not selected: this project is too large for Peel to tell when it last changed.")
+ case nil:
+ nil
}
- if artifact.hasGenericName {
- return String(localized: "Not selected: a folder called \(artifact.name) could be anyone’s.")
- }
- if !artifact.lastActivityIsCertain {
- return String(localized: "Not selected: this project is too large for Peel to tell when it last changed.")
- }
- return nil
}
}