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.

Keep a disk image that is open right now from being suggested or moved

Țugui Dragoșa4b66a578673
diff --git a/GUIDE.md b/GUIDE.md
index c0099ebb..19038438 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -130,8 +130,8 @@ Space shows what fills your disk, area by area, and what each area is.
or device firmware. It passes by an encrypted disk image, an installer elsewhere that is no installed app's, a package
an app keeps for itself, a download that changed in the last day, a `.part` file no browser left, which a torrent
client or another program that resumes downloads may still finish, an update whose app is open, and anything in
- Shared, open in a program, or syncing to your other devices. A disk image can also be one you made to keep files in,
- so look before you select it.
+ Shared, open in a program, open as a disk image, or syncing to your other devices. A disk image can also be one you
+ made to keep files in, so look before you select it.
- **iCloud Drive:** files already safe in iCloud that are also downloaded to this Mac, as Finder shows them: what is in
iCloud Drive and each app's documents, never an app's own data. Downloads are listed in the folders Finder shows
them in, named as Finder names them, the biggest first, and a folder's checkbox selects every file in it; a file
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 512997e2..c29d8c79 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -63909,6 +63909,112 @@
}
}
},
+ "It is a disk image that is open right now. Eject it, then try again." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Je to obraz disku, který je právě otevřený. Vysuňte ho a zkuste to znovu."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dies ist eine Image-Datei, die gerade geöffnet ist. Wirf sie aus und versuche es dann erneut."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Es una imagen de disco que está abierta ahora mismo. Expúlsala y vuelve a intentarlo."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il s’agit d’une image disque actuellement ouverte. Éjectez-la, puis réessayez."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "È un’immagine disco aperta in questo momento. Espellila, poi riprova."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "現在開いているディスクイメージです。取り出してから、やり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "지금 열려 있는 디스크 이미지입니다. 추출한 다음 다시 시도하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het is een schijfkopie die op dit moment is geopend. Verwijder de bijbehorende schijf in Finder en probeer het opnieuw."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "To obraz dysku, który jest teraz otwarty. Wysuń go i spróbuj ponownie."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "É uma imagem de disco que está aberta neste momento. Ejete-a e tente novamente."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Este o imagine de disc deschisă chiar acum. Ejectați‑o, apoi încercați din nou."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Это образ диска, который сейчас подключен. Извлеките его, а затем повторите попытку."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det är en skivavbild som är öppen just nu. Mata ut den och försök sedan igen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu, şu anda açık olan bir disk görüntüsü. Onu çıkarın, ardından yeniden deneyin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Це образ диска, який саме зараз відкрито. Вийміть його та спробуйте ще раз."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它是当前已打开的磁盘映像。请推出它,然后重试。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它是目前已打開的磁碟映像檔。請將它退出,然後再試一次。"
+ }
+ }
+ }
+ },
"It is a hidden folder, a Library, or a folder a tool fills, such as node_modules, or it sits inside one. Apps and tools keep what they install there, so Peel doesn’t look for projects in it." : {
"localizations" : {
"cs" : {
@@ -99157,6 +99263,112 @@
}
}
},
+ "Not selected: this disk image is open right now. Eject it first." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nevybráno: tento obraz disku je právě otevřený. Nejprve ho vysuňte."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nicht ausgewählt: Diese Image-Datei ist gerade geöffnet. Wirf sie zuerst aus."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sin seleccionar: esta imagen de disco está abierta ahora mismo. Expúlsala primero."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non sélectionné : cette image disque est ouverte en ce moment. Éjectez-la d’abord."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non selezionato: questa immagine disco è aperta in questo momento. Prima espellila."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選択: このディスクイメージは現在開いています。先に取り出してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "선택되지 않음: 이 디스크 이미지는 지금 열려 있습니다. 먼저 추출하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niet geselecteerd: deze schijfkopie is op dit moment geopend. Verwijder eerst de bijbehorende schijf in Finder."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie zaznaczono: ten obraz dysku jest teraz otwarty. Najpierw go wysuń."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não selecionado: esta imagem de disco está aberta neste momento. Ejete-a primeiro."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neselectat: această imagine de disc este deschisă chiar acum. Mai întâi ejectați‑o."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не выбрано: этот образ диска сейчас подключен. Сначала извлеките его."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inte markerad: den här skivavbilden är öppen just nu. Mata ut den först."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seçilmedi: bu disk görüntüsü şu anda açık. Önce onu çıkarın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вибрано: цей образ диска саме зараз відкрито. Спершу вийміть його."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未选择:此磁盘映像当前已打开。请先推出它。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選取:此磁碟映像檔目前已打開。請先將它退出。"
+ }
+ }
+ }
+ },
"Not selected: this folder is in a Git repository whose list of tracked files Peel couldn’t read, so it may be part of the project." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index cbf8f302..b53a690d 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -389,6 +389,7 @@ extension HoldBack {
case .crashReport: "a crash report, which the app's developer may still ask for"
case .inTheCloud: "syncs to your other devices through iCloud or another app, so moving it would remove it from them too"
case .openInAProgram: "open in a program right now, which may still be downloading it"
+ case .attachedDiskImage: "a disk image open right now; eject it first"
case .changedRecently: "changed in the last day, so it may still be downloading"
case .mayStillBeResumed: "a program that resumes downloads, such as a torrent client, may still finish it"
case .writtenRecently: "written to in the last 15 minutes, so a program may still be using it"
@@ -482,6 +483,7 @@ extension TrashFailure.Reason {
case .heldByABuildTool(let tools):
"in use by \(tools.map(Output.plain).joined(separator: ", ")); run \(BuildDaemon.stopCommands(for: tools).map { "`\($0)`" }.joined(separator: " and ")), then try again"
case .inUseByMacOS(let processes): "in use by macOS (\(processes.map(Output.plain).joined(separator: ", ")))"
+ case .attachedDiskImage: "a disk image open right now; eject it, then try again"
case .failed(let message): Output.plain(message)
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index cc16370d..b19e2315 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -134,6 +134,8 @@ public enum HoldBack: String, Sendable, Hashable {
case inTheCloud
/// A file a program has open right now, which may still be downloading it.
case openInAProgram
+ /// A disk image attached right now, which macOS holds open until it is ejected.
+ case attachedDiskImage
/// A download that changed within the last day, which may still be going.
case changedRecently
/// A `.part` file no browser left, which a program that resumes downloads, such as a torrent client, may still
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
index 95668dbe..ba4ad863 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/OpenFiles.swift
@@ -20,11 +20,15 @@ struct OpenFiles {
private let programs: [pid_t: String]
/// The program the excluded process runs. Its open files are no hold, but where it runs from is.
private let excludedProgram: [String]?
+ private let attachedImages: [[String]]
/// Each regular file held open for reading or writing, and the program each process runs, which it holds as long
/// as it runs. A watch (`O_EVTONLY`, as Finder keeps on what it shows) and a folder are no hold on what is inside.
- init(excluding excluded: pid_t? = getpid()) {
+ init(excluding excluded: pid_t? = getpid(), attachedImages: [String] = []) {
excludedProgram = excluded.flatMap(RunningProgram.path(of:)).map(PathComponents.of)
+ self.attachedImages = attachedImages.map {
+ PathComponents.of(PathPattern.canonical(URL(filePath: $0)).path(percentEncoded: false))
+ }
var pids = [pid_t](repeating: 0, count: 8_192)
let count = Int(proc_listallpids(&pids, Int32(pids.count * MemoryLayout<pid_t>.size)))
var files: [File] = []
@@ -52,12 +56,18 @@ struct OpenFiles {
/// A reading of the open files that is made again once it is older than `lifetime`.
struct Fresh {
- private var reading = OpenFiles()
+ private let attachedImages: [String]
+ private var reading: OpenFiles
private var read = ContinuousClock.now
+ init(attachedImages: [String] = []) {
+ self.attachedImages = attachedImages
+ reading = OpenFiles(attachedImages: attachedImages)
+ }
+
mutating func refusal(of url: URL, lettingItsProgramsRun: Bool) -> TrashFailure.Reason? {
if ContinuousClock.now - read > OpenFiles.lifetime {
- reading = OpenFiles()
+ reading = OpenFiles(attachedImages: attachedImages)
read = .now
}
return reading.refusal(of: url, lettingItsProgramsRun: lettingItsProgramsRun)
@@ -70,6 +80,10 @@ struct OpenFiles {
Set(holding(url, lettingItsProgramsRun: lettingItsProgramsRun).map(\.process)).sorted()
}
+ func isAttachedDiskImage(_ url: URL) -> Bool {
+ attachedImages.contains(PathComponents.of(PathPattern.canonical(url).path(percentEncoded: false)))
+ }
+
func processes(holding url: URL, lettingItsProgramsRun: Bool = false) -> Set<pid_t> {
Set(holding(url, lettingItsProgramsRun: lettingItsProgramsRun).map(\.pid))
}
@@ -78,6 +92,7 @@ struct OpenFiles {
func refusal(of url: URL, lettingItsProgramsRun: Bool) -> TrashFailure.Reason? {
let names = PathComponents.of(PathPattern.canonical(url).path(percentEncoded: false))
if !lettingItsProgramsRun, let excludedProgram, excludedProgram.starts(with: names) { return .peelRunsFromIt }
+ if attachedImages.contains(where: { $0.starts(with: names) }) { return .attachedDiskImage }
return Self.refusal(heldBy: holding(url, lettingItsProgramsRun: lettingItsProgramsRun).map { file in
Holder(
process: file.process, owner: file.owner,
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 2808f01f..ae53cace 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -96,6 +96,8 @@ public struct TrashFailure: Sendable, Hashable {
case heldByABuildTool(by: [String])
/// Only macOS's own programs hold it, and nobody quits those.
case inUseByMacOS(by: [String])
+ /// It is a disk image attached right now, or a folder holding one, which macOS holds open until it is ejected.
+ case attachedDiskImage
case failed(String)
}
@@ -116,7 +118,7 @@ extension TrashFailure.Reason {
case .historyUnreadable, .historyCannotBeWritten, .needsHelper: false
case .guarded, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .locked, .movedWithoutATrace,
.somethingElseMoved, .heldOpen, .peelRunsFromIt, .heldByAnotherAccount, .openForAnotherUser,
- .heldByABuildTool, .inUseByMacOS, .failed: true
+ .heldByABuildTool, .inUseByMacOS, .attachedDiskImage, .failed: true
}
}
@@ -148,6 +150,7 @@ extension TrashFailure.Reason {
case .openForAnotherUser: "open-for-another-user"
case .heldByABuildTool: "held-by-a-build-tool"
case .inUseByMacOS: "in-use-by-macos"
+ case .attachedDiskImage: "attached-disk-image"
case .failed: "failed"
}
}
@@ -190,6 +193,7 @@ extension TrashFailure.Reason {
case "held-by-a-build-tool":
self = .heldByABuildTool(by: (detail ?? "").split(separator: "\n").map(String.init))
case "in-use-by-macos": self = .inUseByMacOS(by: (detail ?? "").split(separator: "\n").map(String.init))
+ case "attached-disk-image": self = .attachedDiskImage
case "failed": self = .failed(detail ?? "")
default: return nil
}
@@ -463,7 +467,7 @@ public struct TrashService: Sendable {
// The guard reads the disk, so it is asked once for each item.
let refusals = urls.reduce(into: [URL: GuardRefusal]()) { $0[$1] = removalGuard.refusal(of: $1) }
let allowed = urls.filter { refusals[$0] == nil }
- var openFiles = OpenFiles.Fresh()
+ var openFiles = OpenFiles.Fresh(attachedImages: await AttachedDiskImages.paths() ?? [])
// Read before the move, while the files are still there to say which jobs they declare.
let jobs = LaunchdCleanup.jobs(for: allowed, environment: environment)
@@ -675,7 +679,7 @@ public struct TrashService: Sendable {
// answer that never comes can affect. The helper reads no open files, so they are read right before each
// request, and again once the last reading is older than `OpenFiles.lifetime`.
let limit = HelperRequest.maximumItems
- var openFiles = OpenFiles.Fresh()
+ var openFiles = OpenFiles.Fresh(attachedImages: await AttachedDiskImages.paths() ?? [])
for batch in [allowed.filter { !links.contains($0) }, allowed.filter(links.contains)] {
for start in stride(from: 0, to: batch.count, by: limit) {
var request: [URL] = []
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
index 50d530cf..64e06b62 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift
@@ -111,13 +111,15 @@ public enum Installers {
exclusions: Exclusions = .none,
minimumSize: Int64 = Installers.minimumSize
) async -> InstallerScan {
- await scan(
+ let attached = await AttachedDiskImages.paths() ?? []
+ return await scan(
installedApps: installedApps,
home: home,
root: root,
exclusions: exclusions,
minimumSize: minimumSize,
- measure: LeftoverScanner.walk
+ measure: LeftoverScanner.walk,
+ openFiles: OpenFiles(attachedImages: attached)
)
}
@@ -267,6 +269,7 @@ public enum Installers {
) -> HoldBack? {
if syncsToOtherDevices(url) { return .inTheCloud }
if let seen { return seen }
+ if openFiles.isAttachedDiskImage(url) { return .attachedDiskImage }
if !openFiles.holders(of: url).isEmpty { return .openInAProgram }
return folder.isSharedWithEveryone ? .sharedWithEveryone : nil
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/AttachedDiskImages.swift b/Packages/PeelCore/Sources/PeelCore/Support/AttachedDiskImages.swift
new file mode 100644
index 00000000..8cd00a00
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Support/AttachedDiskImages.swift
@@ -0,0 +1,17 @@
+import Foundation
+internal import PeelPrivileged
+
+/// The disk images attached right now, which `hdiutil info` names (`man hdiutil`). macOS's newer disk image service
+/// holds one open under an account of its own, so the open files Peel reads can't show that it is in use.
+enum AttachedDiskImages {
+ /// The path of each, or nil when `hdiutil` didn't answer.
+ @concurrent
+ static func paths() async -> [String]? {
+ guard case .success(let output) = await Subprocess.run("/usr/bin/hdiutil", ["info", "-plist"], timeout: 10),
+ output.status == 0,
+ let plist = try? PropertyListSerialization.propertyList(from: output.standardOutput, format: nil),
+ let images = (plist as? [String: Any])?["images"] as? [[String: Any]]
+ else { return nil }
+ return images.compactMap { $0["image-path"] as? String }
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttachedImage.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttachedImage.swift
new file mode 100644
index 00000000..de7f0494
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttachedImage.swift
@@ -0,0 +1,45 @@
+import Foundation
+
+/// A disk image made for a test and attached as Finder opens one through macOS's newer disk image service, whose
+/// process belongs to another account, with nothing mounted. It is detached when the test lets go of it.
+final class AttachedImage {
+ let url: URL
+ private var device: String?
+
+ init(at url: URL) throws {
+ self.url = url
+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
+ _ = try Self.run("/usr/bin/hdiutil", "create", "-quiet", "-size", "1m", "-fs", "APFS", "-volname", "Probe", url.path)
+ let answer = try Self.run(
+ "/usr/sbin/diskutil", "image", "attach", "--plist", "--readOnly", "--nobrowse", "--noMount", url.path
+ )
+ let plist = try PropertyListSerialization.propertyList(from: answer, format: nil) as? [String: Any]
+ let entities = plist?["system-entities"] as? [[String: Any]] ?? []
+ device = entities.compactMap { $0["dev-entry"] as? String }.first
+ }
+
+ deinit {
+ detach()
+ }
+
+ func detach() {
+ guard let device else { return }
+ _ = try? Self.run("/usr/bin/hdiutil", "detach", "-quiet", "-force", "/dev/" + device)
+ self.device = nil
+ }
+
+ private static func run(_ executable: String, _ arguments: String...) throws -> Data {
+ let process = Process()
+ process.executableURL = URL(filePath: executable)
+ process.arguments = arguments
+ let output = Pipe()
+ process.standardOutput = output
+ try process.run()
+ let data = output.fileHandleForReading.readDataToEndOfFile()
+ process.waitUntilExit()
+ guard process.terminationStatus == 0 else {
+ throw CocoaError(.fileWriteUnknown, userInfo: [NSLocalizedDescriptionKey: arguments.joined(separator: " ")])
+ }
+ return data
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
index 7a217893..04e5526e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift
@@ -627,6 +627,22 @@ struct InstallersTests {
#expect(measured.withLock { $0 } == 1, "it went on measuring after it was canceled")
}
+ @Test func aDiskImageOpenRightNowIsNotSuggested() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.directory("Applications")
+ let image = try AttachedImage(at: directory.url.appending(path: "Downloads/Tool.dmg"))
+ try directory.file("Downloads/Other.dmg", bytes: 400_000)
+
+ let scan = await Installers.scan(
+ installedApps: [], home: directory.url, root: directory.url, minimumSize: 100_000
+ )
+ image.detach()
+
+ let heldBack = Dictionary(uniqueKeysWithValues: scan.items.map { ($0.name, $0.heldBack) })
+ #expect(heldBack["Tool.dmg"] == .attachedDiskImage)
+ #expect(heldBack["Other.dmg"] == .some(nil))
+ }
+
@Test func aScanCanceledWhileMacOSAsksAsksNothingMore() async throws {
let directory = try TemporaryDirectory()
try directory.directory("Applications")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index 2008db13..584c349d 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -943,6 +943,19 @@ struct TrashServiceTests {
#expect(caches.appending(path: "Vendor.real/x.pdf").isThere)
}
+ @Test func refusesADiskImageOpenRightNowAndTheFolderItIsIn() async throws {
+ let directory = try TemporaryDirectory()
+ let service = try service(in: directory)
+ let image = try AttachedImage(at: directory.url.appending(path: "home/Downloads/Tool/Tool.dmg"))
+ let folder = image.url.deletingLastPathComponent()
+
+ let result = await service.trash([image.url, folder])
+ image.detach()
+
+ #expect(result.trashed.isEmpty)
+ #expect(result.failures.map(\.reason) == [.attachedDiskImage, .attachedDiskImage])
+ }
+
@Test func readsTheOpenFilesAgainWhileAMoveGoesOn() async throws {
let directory = try TemporaryDirectory()
let service = try service(in: directory)
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 16daf72a..4d47be87 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -197,6 +197,8 @@ extension TrashFailure.Reason {
String(localized: "It is in use by \(tools.formatted(.list(type: .and))). Run \(BuildDaemon.stopCommands(for: tools).map { "`\($0)`" }.formatted(.list(type: .and))), then try again.", bundle: bundle)
case .inUseByMacOS(let processes):
String(localized: "macOS is using it right now, through \(processes.formatted(.list(type: .and))), so it stays where it is.", bundle: bundle)
+ case .attachedDiskImage:
+ String(localized: "It is a disk image that is open right now. Eject it, then try again.", bundle: bundle)
case .failed(let message): FixedSentence.translated(message, in: bundle)
}
}
@@ -395,6 +397,8 @@ extension HoldBack {
"Left alone: this syncs to your other devices through iCloud or another app, and moving it to the Trash would also remove it from them."
case .openInAProgram:
"Not selected: a program has this open right now, and may still be downloading it."
+ case .attachedDiskImage:
+ "Not selected: this disk image is open right now. Eject it first."
case .changedRecently:
"Not selected: this changed in the last day, so it may still be downloading."
case .mayStillBeResumed:
diff --git a/SAFETY.md b/SAFETY.md
index 0a5b9d03..005471e7 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -179,7 +179,9 @@ programs that run as another account or as root, macOS's own among them, only th
files it holds open, which is why Space also leaves macOS's own caches unselected, and in the Library at the top of
the disk, where those programs keep theirs, does not list them at all. Neither you nor Peel can quit such a program,
so Peel never asks you to: what it runs from stays, and says so, until it is stopped in Background Items or by the
-app's own uninstaller, or, for an app another user of this Mac has open, until it is quit in that user's account.
+app's own uninstaller, or, for an app another user of this Mac has open, until it is quit in that user's account. A
+disk image that is open right now, which macOS's disk image service holds under an account of its own, is known from
+`hdiutil info`: it stays, and so does a folder holding it, until it is ejected.
The folder your account's crash reports are saved in, `~/Library/Logs/DiagnosticReports`, never moves: macOS's
analytics helper can't make it again once it is gone, and crash reports would stop being saved. Space offers only
@@ -401,7 +403,7 @@ Never selected for you, even when found:
them. When you uninstall Xcode, the simulators it made in your home folder are listed too, with the apps installed in
them and their data, and never selected.
- A copy Mail keeps of an attachment you opened, which you may have changed.
-- A file a program has open right now.
+- A file a program has open right now, and a disk image that is open right now.
- An installer package an app keeps in Application Support, which the app may still need, and an update whose app is
running, which may install it when the app quits.
- An encrypted disk image, and a disk image, package, or archive outside Downloads that isn't an installed app's