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.

Installers and Backups leaves a download still in progress unselected

Țugui Dragoșa1227d6a1d46
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 5eb36f9b..ac11b40f 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -68769,6 +68769,112 @@
}
}
},
+ "Not selected: a program has this open right now, and may still be downloading it." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nevybráno: nějaký program má tento soubor právě teď otevřený a možná ho ještě stahuje."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nicht ausgewählt: Ein Programm hat dieses Objekt gerade geöffnet und lädt es möglicherweise noch."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sin seleccionar: un programa lo tiene abierto ahora mismo, y puede que aún lo esté descargando."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non sélectionné : un programme garde ce fichier ouvert en ce moment et le télécharge peut-être encore."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non selezionato: un programma lo tiene aperto proprio ora, e potrebbe ancora scaricarlo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選択: 現在ほかのプログラムがこれを開いていて、まだダウンロード中の可能性があります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "선택되지 않음: 지금 어떤 프로그램이 이 파일을 열고 있으며, 아직 다운로드하는 중일 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niet geselecteerd: een programma heeft dit op dit moment geopend en is het misschien nog aan het downloaden."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie zaznaczono: jakiś program ma właśnie otwarty ten plik i może go jeszcze pobierać."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não selecionado: um programa está com este item aberto neste momento e pode ainda estar baixando-o."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neselectat: acest fișier este deschis chiar acum de un program și poate fi încă în curs de descărcare."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не выбрано: этот файл сейчас открыт в какой-то программе, которая, возможно, еще загружает его."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inte markerad: ett program har den här filen öppen just nu och kanske fortfarande hämtar den."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seçilmedi: bir program bu dosyayı şu anda açık tutuyor ve onu hâlâ indiriyor olabilir."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вибрано: цей файл саме зараз відкрито в якійсь програмі, яка, можливо, ще його викачує."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未选择:某个程序现在已打开此文件,可能仍在下载它。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選取:某個程式現在正打開此項目,而且可能仍在下載它。"
+ }
+ }
+ }
+ },
"Not selected: a report macOS wrote when the app crashed, which its developer may still ask you for." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 3348f434..d99e350c 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -275,6 +275,7 @@ extension HoldBack {
case .openedFromMail: "an attachment opened from Mail, which may be the only copy"
case .crashReport: "a crash report, which the app's developer may still ask for"
case .inTheCloud: "in iCloud Drive, so moving it removes it from every device"
+ case .openInAProgram: "open in a program right now, which may still be downloading it"
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index 33496c1f..1c9fe891 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -67,6 +67,8 @@ public enum HoldBack: String, Sendable, Hashable {
case crashReport
/// A file in iCloud Drive, which moving to the Trash removes from every device.
case inTheCloud
+ /// A file a program has open right now, which may still be downloading it.
+ case openInAProgram
/// True when the item cannot be selected at all, rather than only left unselected.
public var cannotBeMoved: Bool {
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
index 048838ea..fd3251d0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
@@ -83,7 +83,8 @@ public enum Installers {
minimumSize: Int64,
measure: LeftoverScanner.Measure,
canList: (URL) -> AccessState = FullDiskAccess.canList,
- isInTheCloud: (URL) -> Bool = { $0.isInTheCloud }
+ isInTheCloud: (URL) -> Bool = { $0.isInTheCloud },
+ openFiles: OpenFiles = OpenFiles()
) async -> InstallerScan {
var items: [InstallerItem] = []
var unreadable: [URL] = []
@@ -107,7 +108,7 @@ public enum Installers {
guard isInstaller || isArchive || firmwareExtensions.contains(suffix), !exclusions.excludes(url), !Task.isCancelled else { continue }
let (size, seen) = await measured(url, by: measure)
guard isWorthARow(size, minimumSize) else { continue }
- let heldBack = heldBack(url, seen: seen, in: folder, isInTheCloud: isInTheCloud)
+ let heldBack = heldBack(url, seen: seen, in: folder, isInTheCloud: isInTheCloud, openFiles: openFiles)
if isArchive {
guard let inside = installerInside(zip: url) else { continue }
items.append(
@@ -129,7 +130,8 @@ public enum Installers {
exclusions: exclusions,
minimumSize: minimumSize,
measure: measure,
- isInTheCloud: isInTheCloud
+ isInTheCloud: isInTheCloud,
+ openFiles: openFiles
)
items += await firmwareFiles(home: home, exclusions: exclusions, minimumSize: minimumSize, measure: measure)
@@ -175,13 +177,15 @@ public enum Installers {
}
}
- /// Why an item is left for the person to choose: it is in iCloud Drive, measuring it saw a reason, or it
- /// belongs to every account on this Mac.
+ /// Why an item is left for the person to choose: it is in iCloud Drive, measuring it saw a reason, a program
+ /// has it open, or it belongs to every account on this Mac.
private static func heldBack(
- _ url: URL, seen: HoldBack?, in folder: Folder, isInTheCloud: (URL) -> Bool
+ _ url: URL, seen: HoldBack?, in folder: Folder, isInTheCloud: (URL) -> Bool, openFiles: OpenFiles
) -> HoldBack? {
if isInTheCloud(url) { return .inTheCloud }
- return seen ?? (folder.isSharedWithEveryone ? .sharedWithEveryone : nil)
+ if let seen { return seen }
+ if !openFiles.holders(of: url).isEmpty { return .openInAProgram }
+ return folder.isSharedWithEveryone ? .sharedWithEveryone : nil
}
/// What measuring `url` gave: its size, and why what it saw leaves the item for the person to choose.
@@ -303,7 +307,8 @@ public enum Installers {
exclusions: Exclusions,
minimumSize: Int64,
measure: LeftoverScanner.Measure,
- isInTheCloud: (URL) -> Bool
+ isInTheCloud: (URL) -> Bool,
+ openFiles: OpenFiles
) async -> [InstallerItem] {
var items: [InstallerItem] = []
for folder in folders {
@@ -324,7 +329,7 @@ public enum Installers {
isReadOnly: false,
notes: version.map { [.version($0)] } ?? [],
requiresPrivileges: FileAccess.requiresPrivilegesToRemove(url),
- heldBack: heldBack(url, seen: seen, in: folder, isInTheCloud: isInTheCloud)
+ heldBack: heldBack(url, seen: seen, in: folder, isInTheCloud: isInTheCloud, openFiles: openFiles)
))
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
index dcf2e1c4..7ceac9ec 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
@@ -247,6 +247,24 @@ struct InstallersTests {
#expect(items["Install macOS Tahoe"]?.heldBack == .some(nil))
}
+ @Test func aDownloadAProgramStillHasOpenIsLeftForThePersonToChoose() async throws {
+ let directory = try TemporaryDirectory()
+ let downloading = try directory.file("Downloads/Tool-1.dmg", bytes: 400_000)
+ try directory.file("Downloads/Other-2.dmg", bytes: 400_000)
+ try directory.directory("Applications")
+ let writer = try FileHandle(forWritingTo: downloading)
+ defer { try? writer.close() }
+
+ let scan = await Installers.scan(
+ installedApps: [], home: directory.url, root: directory.url, exclusions: .none, minimumSize: 100_000,
+ measure: LeftoverScanner.walk, openFiles: OpenFiles(excluding: nil)
+ )
+
+ let heldBack = Dictionary(uniqueKeysWithValues: scan.items.map { ($0.name, $0.heldBack) })
+ #expect(heldBack["Tool-1.dmg"] == .openInAProgram)
+ #expect(heldBack["Other-2.dmg"] == .some(nil))
+ }
+
@Test func findsMacOSInstallersAndDeviceFirmware() async throws {
let directory = try TemporaryDirectory()
try directory.file("Applications/Install macOS Tahoe.app/Contents/MacOS/app", bytes: 400_000)
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index b5808af1..2f0a267d 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -210,6 +210,8 @@ extension HoldBack {
"Not selected: a report macOS wrote when the app crashed, which its developer may still ask you for."
case .inTheCloud:
"Not selected: this is in iCloud Drive, so moving it to the Trash removes it from iCloud and from your other devices."
+ case .openInAProgram:
+ "Not selected: a program has this open right now, and may still be downloading it."
}
}
}