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.

Leave out folders that hold nothing whatever the smallest size

Țugui Dragoș0f43ac6d2826
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
index 6334ddbc..c2ae070f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/DuplicateFinder.swift
@@ -173,7 +173,6 @@ public struct DuplicateFinder: Sendable {
var keys: Set<URLResourceKey> = [.isDirectoryKey, .isRegularFileKey]
if options.kind != .any { keys.insert(.contentTypeKey) }
let excludedFolders = Self.managedPaths(home: homeDirectory)
- let minimumSize = max(1, options.minimumSize)
let unreadable = UnreadableLocations()
var walked: [Candidate] = []
var projects = Set<String>()
@@ -222,7 +221,7 @@ public struct DuplicateFinder: Sendable {
lstat(url.path(percentEncoded: false), &info) == 0,
info.st_mode & S_IFMT == S_IFREG,
info.st_flags & UInt32(SF_DATALESS) == 0,
- ReclaimableSpace.held(info) >= minimumSize,
+ ReclaimableSpace.held(info) >= options.minimumSize,
options.kind == .any || values.contentType.map(options.kind.includes) == true
else { return }
walked.append(Candidate(url: url, identity: FileIdentity(info)))
diff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
index ebe46407..ea8b7cd4 100644
--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift
@@ -3,7 +3,11 @@ public import Foundation
public struct DuplicateScanOptions: Sendable, Hashable {
public var folders: [URL]
public var kind = FileKind.any
- public var minimumSize: Int64 = 1
+ /// The fewest bytes a file holds, or a folder holds in all, to be compared. Never less than one: a copy of
+ /// nothing frees nothing.
+ public var minimumSize: Int64 = 1 {
+ didSet { minimumSize = max(1, minimumSize) }
+ }
public init(folders: [URL]) {
self.folders = folders
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift
index fc12fe34..3f068c29 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FolderDuplicateTests.swift
@@ -56,6 +56,18 @@ struct FolderDuplicateTests {
#expect(result.groups.isEmpty)
}
+ @Test func aFloorOfZeroStillLeavesOutFoldersThatHoldNothing() async throws {
+ let directory = try TemporaryDirectory()
+ for folder in ["home/Documents/Notes", "home/Desktop/Notes"] {
+ try directory.file("\(folder)/todo.txt", bytes: 0)
+ }
+
+ let result = try await scan(directory) { $0.minimumSize = 0 }
+
+ #expect(names(result).isEmpty)
+ #expect(result.groups.isEmpty)
+ }
+
@Test func groupsFoldersWithIdenticalContents() async throws {
let directory = try TemporaryDirectory()
try trip(in: directory)