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.

Say that the folder an item goes back to is gone

Țugui Dragoș71a275e0a6f4
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 7db95d80..8746866a 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -170558,6 +170558,112 @@
}
}
},
+ "The folder it goes back to isn’t there anymore. Put that folder back first, or drag this out of the Trash in Finder." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Složka, do které se to má vrátit, už neexistuje. Nejprve vraťte zpět tuto složku, nebo to ve Finderu přetáhněte z koše ven."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Der Ordner, in den es zurückgelegt wird, ist nicht mehr vorhanden. Lege zuerst diesen Ordner zurück oder ziehe dieses Objekt im Finder aus dem Papierkorb."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La carpeta a la que vuelve ya no está. Restaura primero esa carpeta, o saca esto de la papelera arrastrándolo en el Finder."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Le dossier où il doit retourner n’existe plus. Remettez d’abord ce dossier en place, ou sortez cet élément de la corbeille dans le Finder, en le faisant glisser."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "La cartella in cui deve tornare non c’è più. Prima ripristina quella cartella, oppure trascina questo elemento fuori dal Cestino nel Finder."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "戻し先のフォルダがもうありません。先にそのフォルダを戻すか、Finderでこれをゴミ箱からドラッグして取り出してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "되돌아갈 폴더가 더 이상 없습니다. 먼저 해당 폴더를 되돌려 놓거나, Finder에서 이 항목을 휴지통 밖으로 드래그하여 꺼내십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "De map waarin het wordt teruggezet, bestaat niet meer. Zet die map eerst terug, of sleep dit in Finder uit de prullenmand."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Folderu, do którego ta rzecz ma wrócić, już nie ma. Najpierw przywróć ten folder albo przeciągnij tę rzecz z Kosza w Finderze."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "A pasta para onde ele volta não existe mais. Coloque essa pasta de volta primeiro, ou arraste isto para fora do Lixo no Finder."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dosarul în care trebuie să revină nu mai există. Mai întâi puneți înapoi acel dosar sau, în Finder, trageți acest articol afară din Coș."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Папки, в которую возвращается объект, больше нет. Сначала восстановите эту папку или перетащите объект из Корзины в Finder."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mappen som det ska tillbaka till finns inte längre. Lägg tillbaka den mappen först, eller dra ut det här ur papperskorgen i Finder."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geri döneceği klasör artık yok. Önce o klasörü yerine koyun veya bunu Finder’da sürükleyerek Çöp Sepeti’nden çıkarın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Папки, куди його треба повернути, уже немає. Спершу поверніть цю папку або перетягніть цей елемент у Finder зі Смітника."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它要放回的文件夹已不存在。请先将该文件夹放回原处,或者在“访达”中将此项从废纸篓中拖出来。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它要還原到的檔案夾已不存在。請先還原該檔案夾,或在Finder中將此項目從「垃圾桶」拖出來。"
+ }
+ }
+ }
+ },
"The folder it’s in couldn’t be found." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index b4cfe9b1..65a26460 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -241,6 +241,8 @@ extension RestoreFailure {
case .notInATrash: "it isn't in the Trash where Peel put it"
case .locked: "it is locked; unlock it in Finder's Get Info"
case .folderLocked: "the folder it goes back to is locked; unlock it in Finder's Get Info"
+ case .folderGone:
+ "the folder it goes back to isn't there anymore; put that folder back first, or drag it out of the Trash in Finder"
case .needsAppManagement:
"macOS lets your terminal app put back another developer's app only with App Management; allow it in System Settings > Privacy & Security > App Management, or put it back with the Peel app"
case .notPermitted: "macOS didn't allow it"
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 4162dec0..ce019454 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -207,6 +207,7 @@ public enum RestoreFailure: Sendable, Hashable {
/// It is locked in the Trash, as Finder's Get Info locks it.
case locked
case folderLocked
+ case folderGone
/// Another developer's app, which macOS lets Peel change only with App Management.
case needsAppManagement
/// macOS's privacy protection refused it.
@@ -217,7 +218,9 @@ public enum RestoreFailure: Sendable, Hashable {
public var isFinal: Bool {
switch self {
case .missingFromTrash, .notAllowed, .notInATrash: true
- case .alreadyThere, .needsHelper, .locked, .folderLocked, .needsAppManagement, .notPermitted, .failed: false
+ case .alreadyThere, .needsHelper, .locked, .folderLocked, .folderGone, .needsAppManagement, .notPermitted,
+ .failed:
+ false
}
}
}
@@ -769,6 +772,7 @@ public struct TrashService: Sendable {
if FileAccess.isLockedInFinder(item.trashedURL) { return .locked }
if FileAccess.isLockedInFinder(URL(filePath: Self.folder(puttingBack: item))) { return .folderLocked }
if Self.needsTheHelper(toPutBack: item) {
+ if Self.isFolderGone(puttingBack: item) { return .folderGone }
let reach = HelperReach(environment: environment)
if let rejection = reach.refusal(ofPuttingBack: item.trashedURL, at: item.originalURL) {
return .failed(rejection.explanation)
@@ -788,6 +792,16 @@ public struct TrashService: Sendable {
return ancestor
}
+ /// Whether the folder `item` goes back into is gone, which the helper doesn't make again. A folder this process
+ /// can't look into isn't known to be gone.
+ static func isFolderGone(puttingBack item: TrashedItem) -> Bool {
+ var info = stat()
+ guard lstat(item.originalURL.deletingLastPathComponent().path(percentEncoded: false), &info) != 0 else {
+ return false
+ }
+ return errno == ENOENT || errno == ENOTDIR
+ }
+
/// Whether putting `item` back is the helper's to do: the person can't write to the folder it goes back into.
static func needsTheHelper(toPutBack item: TrashedItem) -> Bool {
!FileManager.default.isWritableFile(atPath: folder(puttingBack: item))
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index 58552ca3..2e522bb0 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -627,6 +627,25 @@ struct TrashServiceTests {
#expect(lockedFolder == .folderLocked)
}
+ @Test(.permissionsHold) func saysWhenTheFolderAnItemGoesBackToIsGoneAndOnlyTheHelperCouldMakeIt() throws {
+ let directory = try TemporaryDirectory()
+ let support = try directory.directory("root/Library/Application Support")
+ let trashed = try directory.file("home/.Trash/item.txt", bytes: 1)
+ let service = TrashService(
+ environment: SearchEnvironment(
+ homeDirectory: directory.url.appending(path: "home"),
+ rootDirectory: directory.url.appending(path: "root")
+ )
+ ) { $0 }
+ let item = TrashedItem(
+ originalURL: support.appending(path: "Vendor/Product/item.txt"), trashedURL: trashed, date: .now
+ )
+ try directory.setPermissions(0o555, of: support)
+ defer { try? directory.setPermissions(0o755, of: support) }
+
+ #expect(service.refusal(ofPuttingBack: item, canUseHelper: true) == .folderGone)
+ }
+
@Test(.permissionsHold) func leavesToTheHelperAWayBackOnlyRootCanLookInto() throws {
let directory = try TemporaryDirectory()
let vendor = try directory.directory("root/Library/Application Support/Vendor")
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 4283c5d6..873e02c0 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -256,6 +256,8 @@ extension RestoreFailure {
case .locked: String(localized: "It is locked. In Finder, choose File > Get Info and deselect Locked, then try again.")
case .folderLocked:
String(localized: "The folder it goes back to is locked. In Finder, choose File > Get Info for that folder and deselect Locked, then try again.")
+ case .folderGone:
+ String(localized: "The folder it goes back to isn’t there anymore. Put that folder back first, or drag this out of the Trash in Finder.")
case .needsAppManagement:
String(localized: "macOS lets Peel put back another developer’s app only with App Management. Allow Peel in System Settings > Privacy & Security > App Management, then try again.")
case .notPermitted: String(localized: "macOS didn’t allow it.")