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.

Stop asking macOS about folders once Installers' scan was left

Țugui Dragoșcd2a2ab28fd8
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
index 428752aa..72e18753 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
@@ -140,14 +140,16 @@ public enum Installers {
)
} + [Folder(url: root.appending(path: "Users/Shared", directoryHint: .isDirectory), isSharedWithEveryone: true)]
var folders: [Folder] = []
+ // A scan its page left asks nothing more: reading a folder macOS guards puts up macOS's question again.
for place in places {
+ guard !Task.isCancelled else { break }
if canList(place.url) == .missing { unreadable.append(place.url) }
folders += [place] + subfolders(of: place.url).map {
Folder(url: $0, isSharedWithEveryone: place.isSharedWithEveryone, holdsDownloads: place.holdsDownloads)
}
}
- for folder in folders {
+ for folder in folders where !Task.isCancelled {
for url in files(in: folder.url) {
// The extension is checked before measuring, since measuring a folder walks all of it.
let suffix = url.pathExtension.lowercased()
@@ -181,6 +183,7 @@ public enum Installers {
}
}
+ guard !Task.isCancelled else { return InstallerScan(items: items, unreadableLocations: unreadable) }
let applications = root.appending(path: "Applications", directoryHint: .isDirectory)
items += await macOSInstallers(
in: [Folder(url: applications, isSharedWithEveryone: false)] + folders,
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
index dc7a0b93..7a217893 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
@@ -627,6 +627,34 @@ struct InstallersTests {
#expect(measured.withLock { $0 } == 1, "it went on measuring after it was canceled")
}
+ @Test func aScanCanceledWhileMacOSAsksAsksNothingMore() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("Applications")
+ let home = directory.url
+ let asked = Mutex<[String]>([])
+ let answer = DispatchSemaphore(value: 0)
+ let (firstQuestion, isAsked) = AsyncStream.makeStream(of: Void.self)
+
+ let scan = Task {
+ await Installers.scan(
+ installedApps: [], home: home, root: home, exclusions: .none, minimumSize: 100_000,
+ measure: LeftoverScanner.walk,
+ canList: { url in
+ asked.withLock { $0.append(url.lastPathComponent) }
+ isAsked.yield()
+ if url.lastPathComponent == "Downloads" { answer.wait() }
+ return .granted
+ }
+ )
+ }
+ for await _ in firstQuestion { break }
+ scan.cancel()
+ answer.signal()
+ _ = await scan.value
+
+ #expect(asked.withLock { $0 } == ["Downloads"])
+ }
+
/// A device backup can hold hundreds of thousands of files, so it is the most likely to run out of time. An
/// unknown size is not zero: the backup is listed first, where the biggest go, and its size reads as unknown.
@Test func aBackupThatDidNotAnswerInTimeIsNotReadAsEmpty() async throws {