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.

Tell a folder that holds only build output from one too large to read

Țugui Dragoșda13cccbb77d
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index 3dea0f2c..7415dbad 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -872,8 +872,11 @@ public enum ProjectArtifacts {
let base = key(of: project)
var samples = 0
+ // The project's artifacts are among its entries, so a walk that saw nothing could not read the folder.
+ var sawAnything = false
for case let url as URL in enumerator {
guard !isGivenUp() else { return (newest, false) }
+ sawAnything = true
let name = url.lastPathComponent
let relative = String(key(of: url).dropFirst(base.count + 1))
if artifacts.contains(name) || artifacts.contains(relative) || passedByForActivity.contains(name) {
@@ -887,7 +890,7 @@ public enum ProjectArtifacts {
if newest == nil || date > newest! { newest = date }
if date > cutoff { return (date, true) }
}
- return (newest, newest != nil)
+ return (newest, newest != nil || sawAnything)
}
static func key(of url: URL) -> String {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index 097b2564..d206912e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -1104,6 +1104,17 @@ struct ProjectArtifactsTests {
#expect(try !isActive("packages"), "a package install is not work on the project")
}
+ @Test func aFolderHoldingNothingButBuildOutputKnowsItHasNotChanged() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file("old/__pycache__/app.cpython-313.pyc", bytes: 400_000)
+ try age(directory.url, days: 60)
+
+ let artifact = try #require(await ProjectArtifacts.scan(roots: [directory.url]).artifacts.first)
+
+ #expect(artifact.lastActivityIsCertain)
+ #expect(artifact.isRecommended)
+ }
+
/// Every git command that changes something writes under `.git`, so three files there tell when the whole
/// repository was last used, without reading a sample of its files.
@Test func readsWhenTheRepositoryWasLastUsed() throws {