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 one reason why a Developer folder stays, on the page and in peel caches

Țugui Dragoșf06d87fc8ea0
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 53516e45..64082746 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -334,7 +334,7 @@ struct CachesCommand: AsyncParsableCommand {
let source: String
/// Whether `--remove` would move it.
let suggested: Bool
- /// What held it back while it was measured, as `HoldBack` names it, or `null`.
+ /// What holds it back, as `HoldBack` names it, or `null`.
let heldBack: String?
/// Why it stays, as the list says it, or `null` when it is suggested.
let reason: String?
@@ -399,6 +399,10 @@ struct CachesCommand: AsyncParsableCommand {
}
}
+ private static func heldBack(of location: DeveloperEnvironment.Location) -> String? {
+ if case .heldBack(let heldBack) = location.keptBecause { heldBack.rawValue } else { nil }
+ }
+
/// The list's last column: "suggested", or why the folder stays.
static func note(for location: DeveloperEnvironment.Location) -> String {
guard let reason = reason(for: location) else { return "suggested" }
@@ -432,7 +436,7 @@ struct CachesCommand: AsyncParsableCommand {
kind: $0.kind.rawValue,
source: $0.source,
suggested: $0.isRecommended,
- heldBack: $0.heldBack?.rawValue,
+ heldBack: heldBack(of: $0),
reason: reason(for: $0)
)
})
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index f1d92993..f44d37c9 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -79,18 +79,22 @@ public struct DeveloperEnvironment: Sendable, Hashable, Identifiable {
/// only content that tools make or fetch again, or logs, and only once measured.
public var isRecommended: Bool { keptBecause == nil }
- /// Why Peel doesn't recommend this location, or nil when it does.
+ /// Why Peel doesn't recommend this location, or nil when it does, which the page and `peel caches` both say:
+ /// a secret seen inside first, then what isn't known, since it may hide anything else, then the rest.
public var keptBecause: Kept? {
+ if let heldBack, heldBack.isASecret { return .heldBack(heldBack) }
+ if size == nil {
+ if closedByPermissions { return .heldBack(.closedByPermissions) }
+ return .heldBack(couldNotBeRead ? .couldNotBeRead : .notMeasured)
+ }
+ if let heldBack { return .heldBack(heldBack) }
switch kind {
case .buildData, .downloads, .cache, .logs: break
case .deviceSupport, .archives, .models, .environments, .keptDownloads, .projectState: return .keptByDefault
}
- if let heldBack { return .heldBack(heldBack) }
if !isTheTools { return .notTheTools }
if let workspace, workspace.mayStillBeInUse { return .workspaceMayBeInUse(lastUsed: workspace.lastUsed) }
- guard size == nil else { return nil }
- if closedByPermissions { return .heldBack(.closedByPermissions) }
- return .heldBack(couldNotBeRead ? .couldNotBeRead : .notMeasured)
+ return nil
}
public enum Kept: Sendable, Equatable {
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index ca124c75..218fd88e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -209,6 +209,10 @@ public enum HoldBack: String, Sendable, Hashable {
return contents.holdsPasswordDatabase ? .holdsAPasswordDatabase : nil
}
+ var isASecret: Bool {
+ self == .holdsAWallet || self == .holdsAPasswordDatabase
+ }
+
/// How long after a write a program may still be using what it wrote (`writtenRecently`).
static let stillInUse: TimeInterval = 15 * 60
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index a3bc75e2..20f6cc0a 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -63,6 +63,36 @@ struct DeveloperCachesTests {
#expect(!refused.isRecommended && !slow.isRecommended)
}
+ @Test func oneRuleSaysWhyAFolderStays() {
+ typealias Location = DeveloperEnvironment.Location
+ func location(
+ _ kind: DeveloperEnvironment.ContentKind = .cache, size: Int64? = 4_000, couldNotBeRead: Bool = false,
+ workspace: DeveloperEnvironment.Workspace? = nil, isTheTools: Bool = true, heldBack: HoldBack? = nil
+ ) -> Location {
+ Location(
+ url: URL(filePath: "/Users/me/Library/Caches/org.example.tool", directoryHint: .isDirectory),
+ kind: kind, size: size, source: "https://example.org", couldNotBeRead: couldNotBeRead,
+ workspace: workspace, isTheTools: isTheTools, heldBack: heldBack
+ )
+ }
+ let openedToday = DeveloperEnvironment.Workspace(name: "Example", lastUsed: .now)
+
+ #expect(location(size: nil, couldNotBeRead: true, heldBack: .holdsAWallet).keptBecause
+ == .heldBack(.holdsAWallet))
+ #expect(location(.models, size: nil, heldBack: .holdsAPasswordDatabase).keptBecause
+ == .heldBack(.holdsAPasswordDatabase))
+ #expect(location(size: nil, heldBack: .holdsRepository).keptBecause == .heldBack(.notMeasured))
+ #expect(location(size: nil, workspace: openedToday).keptBecause == .heldBack(.notMeasured))
+ #expect(location(size: nil, isTheTools: false).keptBecause == .heldBack(.notMeasured))
+ #expect(location(.models, size: nil).keptBecause == .heldBack(.notMeasured))
+ #expect(location(size: nil, couldNotBeRead: true).keptBecause == .heldBack(.couldNotBeRead))
+ #expect(location(.models, heldBack: .writtenRecently).keptBecause == .heldBack(.writtenRecently))
+ #expect(location(.models).keptBecause == .keptByDefault)
+ #expect(location(isTheTools: false).keptBecause == .notTheTools)
+ #expect(location(workspace: openedToday).keptBecause == .workspaceMayBeInUse(lastUsed: openedToday.lastUsed))
+ #expect(location().keptBecause == nil)
+ }
+
@Test func aSearchFindsAToolByTheNamesOfItsFolders() {
let hub = URL(filePath: "/Users/me/.cache/huggingface/hub", directoryHint: .isDirectory)
let tool = DeveloperEnvironment(
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
index b2f3824b..d6306fa9 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileCommandTests.swift
@@ -957,6 +957,7 @@ struct FileCommandTests {
#expect(written[0]["reason"] is NSNull && written[0]["heldBack"] is NSNull)
#expect(written[1]["heldBack"] as? String == "holdsAWallet")
#expect(written[1]["reason"] as? String == "holds a wallet or a signing key")
+ #expect(written[2]["heldBack"] as? String == "closedByPermissions")
#expect(CachesCommand.staying(in: [held]).count == 6)
#expect(CachesCommand.staying(in: [held])[0].hasSuffix("wallet stays: holds a wallet or a signing key"))
#expect(CachesCommand.notes(for: [held]) == [
diff --git a/Peel/Views/Developer/DeveloperDetailView.swift b/Peel/Views/Developer/DeveloperDetailView.swift
index 478f4ae3..e792015f 100644
--- a/Peel/Views/Developer/DeveloperDetailView.swift
+++ b/Peel/Views/Developer/DeveloperDetailView.swift
@@ -83,25 +83,19 @@ struct DeveloperDetailView: View {
}
private func warning(for location: DeveloperEnvironment.Location) -> String? {
- if location.size == nil {
- return String(
- localized: location.couldNotBeRead
- ? (location.closedByPermissions ? HoldBack.closedByPermissions : .couldNotBeRead).explanation
- : HoldBack.notMeasured.explanation
- )
- }
- if let heldBack = location.heldBack {
+ switch location.keptBecause {
+ case nil, .keptByDefault:
+ return nil
+ case .heldBack(let heldBack):
return String(localized: heldBack.explanation)
- }
- if !location.isTheTools {
+ case .notTheTools:
return String(localized: "Not selected: nothing shows that \(environment.name) made this folder.")
+ case .workspaceMayBeInUse(let lastUsed):
+ let name = location.workspace?.name ?? ""
+ return lastUsed == nil
+ ? String(localized: "Not selected: Xcode didn’t record when \(name) was last opened, so its build data may still be needed.")
+ : String(localized: "Not selected: \(name) was opened in the last week, so its build data may be needed again soon.")
}
- if let workspace = location.workspace, workspace.mayStillBeInUse {
- return workspace.lastUsed == nil
- ? String(localized: "Not selected: Xcode didn’t record when \(workspace.name) was last opened, so its build data may still be needed.")
- : String(localized: "Not selected: \(workspace.name) was opened in the last week, so its build data may be needed again soon.")
- }
- return nil
}
private var keptByDefault: Int {