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.

Point to Full Disk Access only when privacy, not permissions, kept Peel out

Țugui Dragoș6d112c832a5b
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 9b89e006..22ca001b 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -97923,6 +97923,112 @@
}
}
},
+ "Not selected: its permissions keep Peel out, so what is in there isn’t known. Full Disk Access doesn’t open it." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nevybráno: oprávnění této složky nepustí Peel dovnitř, takže není známo, co tam je. Plný přístup k disku ji neotevře."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nicht ausgewählt: Die Zugriffsrechte dieses Ordners sperren Peel aus, daher ist nicht bekannt, was darin liegt. Auch Festplattenvollzugriff öffnet ihn nicht."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sin seleccionar: sus permisos no dejan entrar a Peel, así que no se sabe qué hay dentro. Con acceso total al disco tampoco se puede abrir."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non sélectionné : ses permissions empêchent Peel d’y accéder, son contenu est donc inconnu. L’accès complet au disque ne permet pas de l’ouvrir."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non selezionato: i suoi permessi impediscono a Peel di accedervi, quindi non si sa cosa contiene. Nemmeno l’accesso completo al disco consente di aprirlo."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選択: アクセス権によってPeelが中に入れないため、中に何があるかわかりません。フルディスクアクセスがあっても開けません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "선택되지 않음: 이 항목의 권한 때문에 Peel이 들어갈 수 없으므로 안에 무엇이 있는지 알 수 없습니다. 전체 디스크 접근 권한으로도 열 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niet geselecteerd: de bevoegdheden ervan houden Peel buiten, dus het is niet bekend wat erin zit. Ook met volledige schijftoegang kan Peel er niet in."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie zaznaczono: uprawnienia tego folderu nie dają aplikacji Peel dostępu, więc nie wiadomo, co jest w środku. Pełny dostęp do dysku tego nie zmienia."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não selecionado: as permissões deste item não deixam o Peel entrar, então não se sabe o que há ali. Nem o Acesso Total ao Disco permite abri-lo."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neselectat: permisiunile sale nu permit accesul aplicației Peel, așa că nu se știe ce conține. Nici Acces complet la disc nu îl deschide."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не выбрано: права доступа не пускают Peel внутрь, поэтому содержимое неизвестно. Полный доступ к диску его не открывает."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inte markerad: dess behörigheter stänger ute Peel, så det är inte känt vad som finns där inne. Full skivtillgång ger inte åtkomst till den."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seçilmedi: izinleri Peel’in içeri girmesini engelliyor, bu yüzden içinde ne olduğu bilinmiyor. Tam Disk Erişimi de onu açmaz."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вибрано: привілеї цієї папки не пускають Peel усередину, тож невідомо, що в ній. Повний доступ до диска її не відкриває."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未选择:它的权限设置不允许Peel进入,因此无法知道里面有什么。完全磁盘访问权限也无法打开它。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選取:它的權限不允許Peel進入,因此無法得知其中有什麼。「完全取用磁碟」權限也無法讓Peel進入。"
+ }
+ }
+ }
+ },
"Not selected: macOS keeps this for its own services, which may be using it right now." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 6adae526..0ef23b73 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -349,6 +349,7 @@ extension HoldBack {
case .holdsAnExclusion: "holds something you excluded"
case .notMeasured: "not measured in time"
case .couldNotBeRead: "macOS wouldn't let Peel read inside"
+ case .closedByPermissions: "its permissions keep Peel out"
case .couldNotLookInside: "macOS wouldn't let Peel look inside to make sure nothing Peel protects is there"
case .holdsDocuments: "holds the app's documents"
case .holdsALibrary: "holds a photo, music, or video library"
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index 948f88a6..852743e3 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -59,6 +59,8 @@ public struct DeveloperEnvironment: Sendable, Hashable, Identifiable {
public let source: String
/// True when macOS would not let Peel open the folder, rather than it not answering in time.
public var couldNotBeRead = false
+ /// True when what couldn't be opened was closed by its permissions, which Full Disk Access doesn't open.
+ public var closedByPermissions = false
public var archive: Archive?
public var workspace: Workspace?
/// The name of the project an editor kept this for, which is no longer on this Mac.
@@ -1596,6 +1598,7 @@ public enum DeveloperCaches {
size: contents.flatMap { $0.couldNotBeRead ? nil : $0.size },
source: folder.source,
couldNotBeRead: contents?.couldNotBeRead == true,
+ closedByPermissions: contents?.closedByPermissions == true,
archive: folder.kind == .archives ? Self.archive(at: url) : nil,
workspace: derived?.workspace,
project: project,
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index c98015c7..cc16370d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -67,6 +67,9 @@ public enum HoldBack: String, Sendable, Hashable {
/// macOS refused to let Peel read inside, so what the folder holds is not known, and zero would be a wrong
/// size. From macOS 27, another team's container is refused outright rather than prompted for.
case couldNotBeRead
+ /// Its permissions kept Peel from reading inside, as with a folder only root may open, so what it holds is not
+ /// known. Full Disk Access doesn't open such a folder.
+ case closedByPermissions
/// macOS would not let Peel list a folder inside it, so `RemovalGuard` refuses to move it as the person: what it
/// never moves may be in there (`GuardRefusal.couldNotLookInside`).
case couldNotLookInside
@@ -163,10 +166,15 @@ public enum HoldBack: String, Sendable, Hashable {
/// exist nowhere else, and a folder the walk could not see into is not known to be empty.
static func seen(in contents: FolderContents?) -> HoldBack? {
guard let contents else { return .notMeasured }
- if contents.couldNotBeRead { return .couldNotBeRead }
+ if contents.couldNotBeRead { return unread(contents) }
return secret(in: contents) ?? (contents.holdsRepository ? .holdsRepository : nil)
}
+ /// Why a folder the walk couldn't see all through is held back: closed by its permissions, or refused otherwise.
+ static func unread(_ contents: FolderContents) -> HoldBack {
+ contents.closedByPermissions ? .closedByPermissions : .couldNotBeRead
+ }
+
/// A wallet, a signing key, or a password database seen inside.
static func secret(in contents: FolderContents) -> HoldBack? {
if contents.holdsWallet { return .holdsAWallet }
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index 91fda49d..0d3f94d4 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -410,8 +410,8 @@ public struct LeftoverScanner: Sendable {
.inTheCloud
} else if let keptOnlyHere = KeptOnlyHere.reason(for: path, home: home, root: root) {
keptOnlyHere
- } else if contents?.couldNotBeRead == true {
- .couldNotBeRead
+ } else if let contents, contents.couldNotBeRead {
+ HoldBack.unread(contents)
} else if let contents {
heldBack(match, at: url, in: kind, contents: contents, foldersAbove: foldersAbove)
} else {
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift
index b74f250f..7a88ce4b 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift
@@ -24,6 +24,8 @@ public struct FolderContents: Sendable, Hashable {
/// then counts only what was, which must never be read as the folder's size. From macOS 27, another team's
/// container is refused outright.
public let couldNotBeRead: Bool
+ /// True when all that couldn't be opened was closed by its permissions, which Full Disk Access doesn't open.
+ public let closedByPermissions: Bool
/// The space the folder takes on disk, each file once whatever its names: more than `size` when files share
/// their blocks with APFS clones elsewhere.
public let taken: Int64
@@ -40,6 +42,7 @@ public struct FolderContents: Sendable, Hashable {
holdsBackups: Bool = false,
newestChange: Date? = nil,
couldNotBeRead: Bool = false,
+ closedByPermissions: Bool = false,
taken: Int64? = nil
) {
self.size = size
@@ -50,6 +53,7 @@ public struct FolderContents: Sendable, Hashable {
self.holdsBackups = holdsBackups
self.newestChange = newestChange
self.couldNotBeRead = couldNotBeRead
+ self.closedByPermissions = closedByPermissions
}
}
@@ -168,7 +172,9 @@ public enum FileSize {
return FolderContents(size: 0, holdsRepository: false)
} catch {
// macOS would not say what the item is (a folder around it cannot be searched), so its size is not known.
- return FolderContents(size: 0, holdsRepository: false, couldNotBeRead: true)
+ return FolderContents(
+ size: 0, holdsRepository: false, couldNotBeRead: true, closedByPermissions: isClosedByPermissions(error)
+ )
}
}
@@ -197,7 +203,7 @@ public enum FileSize {
includingPropertiesForKeys: Array(fileKeys),
options: [],
errorHandler: { _, error in
- if (error as? CocoaError)?.code != .fileReadNoSuchFile { refused.note() }
+ if (error as? CocoaError)?.code != .fileReadNoSuchFile { refused.note(error) }
return true
}
) else { return FolderContents(size: 0, holdsRepository: false, couldNotBeRead: true) }
@@ -264,6 +270,7 @@ public enum FileSize {
holdsBackups: holdsBackups,
newestChange: newestChange,
couldNotBeRead: refused.happened,
+ closedByPermissions: refused.closedByPermissions,
taken: taken
)
}
@@ -281,15 +288,27 @@ public enum FileSize {
/// Whether a folder of the walk refused to open. Set by the enumerator's error handler on the walking thread,
/// and read once the walk ends.
private final class Refused: Sendable {
- private let state = Mutex(false)
+ private let state = Mutex((happened: false, otherThanByPermissions: false))
- var happened: Bool { state.withLock { $0 } }
+ var happened: Bool { state.withLock { $0.happened } }
+ var closedByPermissions: Bool { state.withLock { $0.happened && !$0.otherThanByPermissions } }
- func note() {
- state.withLock { $0 = true }
+ func note(_ error: any Error) {
+ let byPermissions = isClosedByPermissions(error)
+ state.withLock {
+ $0.happened = true
+ if !byPermissions { $0.otherThanByPermissions = true }
+ }
}
}
+ /// Whether a read failed on ordinary permissions (`EACCES`), which Full Disk Access doesn't lift, rather than on
+ /// macOS's privacy protection (`EPERM`) or for another reason.
+ static func isClosedByPermissions(_ error: any Error) -> Bool {
+ guard let cause = (error as NSError).userInfo[NSUnderlyingErrorKey] as? NSError else { return false }
+ return cause.domain == NSPOSIXErrorDomain && cause.code == Int(EACCES)
+ }
+
static let repositoryMarkers: Set<String> = [".git", ".hg", ".svn", ".jj", ".pijul", "_darcs"]
/// True for the names wallets and their keys go by, as each project's own documentation or source gives them:
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift
index e8ceda3c..e95608af 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift
@@ -171,6 +171,23 @@ struct FileSizeTests {
#expect(await FileSize.reclaimableSize(of: folder) == nil)
}
+ @Test(.permissionsHold) func tellsAFolderClosedByItsPermissionsApart() async throws {
+ let directory = try TemporaryDirectory()
+ let folder = try directory.directory("Vendor")
+ try directory.file("Vendor/settings.plist", bytes: 100)
+ try directory.file("Vendor/rootonly/state", bytes: 100)
+ try directory.setPermissions(0, of: "Vendor/rootonly")
+ defer { try? directory.setPermissions(0o755, of: "Vendor/rootonly") }
+
+ let contents = try #require(await FileSize.contents(of: folder))
+
+ #expect(contents.couldNotBeRead)
+ #expect(contents.closedByPermissions, "Full Disk Access doesn't open a folder its permissions close")
+ #expect(HoldBack.seen(in: contents) == .closedByPermissions)
+ let refusedOtherwise = FolderContents(size: 0, holdsRepository: false, couldNotBeRead: true)
+ #expect(HoldBack.seen(in: refusedOtherwise) == .couldNotBeRead)
+ }
+
/// A folder that goes away while the walk goes on holds nothing any more, which is no reason to doubt the rest:
/// an app that makes and removes folders in its cache as it runs would otherwise leave that cache never known.
@Test func aFolderThatGoesAwayDuringTheWalkLeavesTheRestKnown() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 6b6ac9ef..22ed8d60 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -1119,7 +1119,8 @@ struct LeftoverScannerTests {
)
let found = try #require(scan.leftovers.first { $0.url.lastPathComponent == "net.example.client" })
- #expect(found.match.heldBack == .couldNotBeRead, "a folder nothing could be read from was taken for an empty one")
+ // Closed here by its permissions; a privacy refusal, as macOS 27's for a container, reads `.couldNotBeRead`.
+ #expect(found.match.heldBack == .closedByPermissions, "a folder nothing could be read from was taken for an empty one")
#expect(!found.match.isRecommended)
#expect(!found.isMeasured)
}
diff --git a/Peel/Views/Developer/DeveloperDetailView.swift b/Peel/Views/Developer/DeveloperDetailView.swift
index 489001fc..d0d78ee9 100644
--- a/Peel/Views/Developer/DeveloperDetailView.swift
+++ b/Peel/Views/Developer/DeveloperDetailView.swift
@@ -86,7 +86,7 @@ struct DeveloperDetailView: View {
if location.size == nil {
return String(
localized: location.couldNotBeRead
- ? HoldBack.couldNotBeRead.explanation
+ ? (location.closedByPermissions ? HoldBack.closedByPermissions : .couldNotBeRead).explanation
: HoldBack.notMeasured.explanation
)
}
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index e7d05063..16daf72a 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -337,6 +337,8 @@ extension HoldBack {
"Not selected: this folder took too long to measure, so Peel doesn’t know how big it is or what is inside."
case .couldNotBeRead:
"Not selected: macOS wouldn’t let Peel read inside, so what is in there isn’t known. If Peel doesn’t have Full Disk Access yet, giving it in System Settings may let it see."
+ case .closedByPermissions:
+ "Not selected: its permissions keep Peel out, so what is in there isn’t known. Full Disk Access doesn’t open it."
case .couldNotLookInside:
"Left alone: macOS wouldn’t let Peel look inside to make sure nothing Peel protects, such as a library or a wallet, is there. If Peel doesn’t have Full Disk Access yet, giving it in System Settings may let it see."
case .holdsDocuments: