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.

A move refused because the item is locked says so

Țugui Dragoșbcc90bde2fac
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 5f432e67..4f54e5fa 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -49480,6 +49480,112 @@
}
}
},
+ "It is locked. In Finder, choose File > Get Info and deselect Locked, then try again." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Je zamčená. Ve Finderu zvolte Soubor > Informace, zrušte zaškrtnutí políčka Zamčeno a zkuste to znovu."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Es ist geschützt. Wähle im Finder „Ablage“ > „Informationen“, deaktiviere „Geschützt“ und versuche es dann erneut."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Está bloqueado. En el Finder, elige Archivo > Obtener información, anula la selección de “Bloquear” y vuelve a intentarlo."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il est verrouillé. Dans le Finder, choisissez Fichier > Lire les informations, désélectionnez « Verrouillé », puis réessayez."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "È bloccato. Nel Finder, scegli File > Ottieni informazioni, deseleziona Bloccato e riprova."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "ロックされています。Finderで“ファイル”>“情報を見る”と選択し、“ロック”を選択解除してから、やり直してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "잠겨 있습니다. Finder에서 파일 > 정보 가져오기를 선택하고, ‘잠금’을 선택 해제한 다음 다시 시도하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het is beveiligd. Kies in Finder Archief > Toon info, deselecteer 'Beveiligd' en probeer het opnieuw."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Jest zablokowane. W Finderze wybierz polecenie Plik > Informacje, usuń zaznaczenie pola Zablokowany i spróbuj ponownie."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Está bloqueado. No Finder, escolha Arquivo > Obter Informações, desmarque a opção “Bloqueado” e tente novamente."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Este blocat. În Finder, alegeți Fișier > Obțineți informații și deselectați „Blocat”, apoi încercați din nou."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Объект защищен. В Finder выберите «Файл» > «Свойства», снимите флажок «Защита», а затем повторите попытку."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det är låst. Välj Arkiv > Visa info i Finder, avmarkera Låst och försök sedan igen."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kilitli. Finder’da Dosya > Bilgi Ver komutunu seçin, Kilitli onay kutusunun seçimini kaldırın ve yeniden deneyin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Елемент замкнено. У Finder виберіть Файл > Досьє, зніміть прапорець «Замкнено» і спробуйте ще раз."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它已被锁定。请在“访达”中选取“文件”>“显示简介”,取消选择“已锁定”,然后重试。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它已鎖定。請在Finder中選擇「檔案」>「取得資訊」,取消勾選「已鎖定」,然後再試一次。"
+ }
+ }
+ }
+ },
"It is no longer in the Trash, so there is nothing to put back." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 024bb853..0e3c0a95 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -380,6 +380,7 @@ extension TrashFailure.Reason {
case .claimedSinceScan: "claimed by an app that is installed now"
case .lastCopy: "last copy"
case .notPermitted: "not permitted"
+ case .locked: "locked; unlock it in Finder's Get Info"
case .needsHelper: "needs administrator access"
case .movedWithoutATrace: "in the Trash where macOS didn't say, so only Finder can put it back"
case .somethingElseMoved(let name): "something else was at that path; it is in the Trash as \(Output.plain(name))"
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index 09476050..b80c4cbe 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -68,6 +68,8 @@ public struct TrashFailure: Sendable, Hashable {
case claimedSinceScan
case lastCopy
case notPermitted
+ /// It is locked, as Finder's Get Info locks an item, so it cannot move until the lock is taken off.
+ case locked
/// It needs administrator rights, and the helper that has them is not installed or not allowed.
case needsHelper
/// It is in the Trash, but macOS did not say where and Peel could not find it, so only Finder can put it back.
@@ -100,6 +102,7 @@ extension TrashFailure.Reason {
case .claimedSinceScan: "claimed-since-scan"
case .lastCopy: "last-copy"
case .notPermitted: "not-permitted"
+ case .locked: "locked"
case .needsHelper: "needs-helper"
case .movedWithoutATrace: "moved-without-a-trace"
case .somethingElseMoved: "something-else-moved"
@@ -130,6 +133,7 @@ extension TrashFailure.Reason {
case "claimed-since-scan": self = .claimedSinceScan
case "last-copy": self = .lastCopy
case "not-permitted": self = .notPermitted
+ case "locked": self = .locked
case "needs-helper": self = .needsHelper
case "moved-without-a-trace": self = .movedWithoutATrace
case "something-else-moved": self = .somethingElseMoved(named: detail ?? "")
@@ -314,7 +318,9 @@ public struct TrashService: Sendable {
moved.add(path)
MoveCount.current?.add(1)
} catch {
- result.failures.append(TrashFailure(url: url, reason: Self.reason(for: error)))
+ let reason = Self.reason(for: error)
+ let isLocked = reason == .notPermitted && FileAccess.isLockedInFinder(url)
+ result.failures.append(TrashFailure(url: url, reason: isLocked ? .locked : reason))
}
}
ownMoves.ended(landedAt: result.trashed.map(\.trashedURL))
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift
index 2a4a5397..cf3e8458 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileAccess.swift
@@ -5,4 +5,12 @@ public enum FileAccess {
public static func requiresPrivilegesToRemove(_ url: URL) -> Bool {
ParentAccess(url.deletingLastPathComponent()).requiresPrivileges(toRemove: url)
}
+
+ /// True when `url` itself is locked as Finder's Get Info locks it (`UF_IMMUTABLE`, `chflags(2)`): the file
+ /// may not be changed until its owner takes the lock off.
+ static func isLockedInFinder(_ url: URL) -> Bool {
+ var info = stat()
+ guard lstat(url.path(percentEncoded: false), &info) == 0 else { return false }
+ return info.st_flags & UInt32(UF_IMMUTABLE) != 0
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
index 3e8466e9..dd3edf7c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/TrashServiceTests.swift
@@ -282,6 +282,20 @@ struct TrashServiceTests {
#expect(await service.restore(planted) == .notAllowed)
}
+ @Test func aMoveRefusedForAnItemLockedInFinderSaysItIsLocked() async throws {
+ let directory = try TemporaryDirectory()
+ let locked = try directory.file("home/Library/Preferences/org.example.locked.plist")
+ let path = locked.path(percentEncoded: false)
+ try FileManager.default.setAttributes([.immutable: true], ofItemAtPath: path)
+ defer { try? FileManager.default.setAttributes([.immutable: false], ofItemAtPath: path) }
+ let service = try service(in: directory)
+
+ let result = await service.trash([locked])
+
+ #expect(result.trashed.isEmpty)
+ #expect(result.failures.map(\.reason) == [.locked])
+ }
+
/// Once the Trash is emptied, another item of the same name can land where an old record's item was. It is not
/// that item: History no longer counts the old record as in the Trash, and Put Back leaves the new one where it is.
@Test func anItemLandingLaterWhereAnotherWasIsNotTakenForIt() async throws {
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 638f4ea4..db1bb2fa 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -133,6 +133,7 @@ extension TrashFailure.Reason {
case .claimedSinceScan: String(localized: "Peel couldn’t confirm it is still nobody’s: an installed app may claim it now. Scan again to review it.")
case .lastCopy: String(localized: "The copy Peel was keeping has changed or moved since the scan, so this one may be the last.")
case .notPermitted: String(localized: "macOS didn’t allow it.")
+ case .locked: String(localized: "It is locked. In Finder, choose File > Get Info and deselect Locked, then try again.")
case .needsHelper: String(localized: "It needs administrator access, which Peel’s helper provides.")
case .movedWithoutATrace: String(localized: "It is in the Trash, but macOS didn’t say where, so it can only be put back from Finder.")
case .somethingElseMoved(let name): String(localized: "Something else was at that path by the time it moved. It is in the Trash as \(name), and Finder can put it back.")