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 Build Artifacts away from what every account shares, and say why

Țugui Dragoș1a8e56c217b8
diff --git a/GUIDE.md b/GUIDE.md
index 097ab223..70191dc3 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -176,7 +176,8 @@ package, belongs to the project above it: the nearest folder holding a repositor
or whose last change Peel couldn't tell, installed packages (a Python environment, `vendor`, Terraform's
`.terraform`), a folder like `target` whose name says nothing on its own, a Meson build folder, which also keeps the
options its build was set up with, a folder Git tracks files in, such as a `Pods` folder kept in the repository, which
-is part of the project, a folder with a repository, a wallet, or a key inside, and one Peel couldn't measure or read.
+is part of the project, a folder with a repository, a wallet, or a key inside, one Peel couldn't measure or read, and
+one in `/Users/Shared`, which belongs to every account.
Until you choose a folder, Peel offers `~/Developer`, `~/Projects`, `~/Code`, or `~/src` when you have one, and adds
it only when you say so. A chosen folder Peel can't search, such as one on a disk that isn't connected, is named at
the top of the page with the reason, never taken for one with nothing built in it. Peel never searches a hidden
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 922a1678..b9809389 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -65203,6 +65203,112 @@
}
}
},
+ "It is a folder that macOS or every account uses, not a folder of projects. Choose the folder your projects are in." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Je to složka, kterou používá systém macOS nebo všechny účty, ne složka s projekty. Zvolte složku, ve které máte projekty."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dies ist ein Ordner, den macOS oder jeder Benutzeraccount verwendet, kein Ordner mit Projekten. Wähle den Ordner, in dem deine Projekte liegen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Es una carpeta que usa macOS o que usan todas las cuentas, no una carpeta de proyectos. Elige la carpeta donde están tus proyectos."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "C’est un dossier que macOS ou tous les comptes utilisent, et non un dossier de projets. Choisissez le dossier qui contient vos projets."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "È una cartella usata da macOS o da tutti gli account, non una cartella di progetti. Scegli la cartella in cui si trovano i tuoi progetti."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "これはmacOSまたはすべてのアカウントが使用するフォルダで、プロジェクトのフォルダではありません。プロジェクトが入っているフォルダを選択してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "macOS나 모든 계정이 사용하는 폴더이며, 프로젝트가 들어 있는 폴더가 아닙니다. 프로젝트가 있는 폴더를 선택하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het is een map die macOS of elke account gebruikt, geen map met projecten. Kies de map waarin je projecten staan."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "To folder, którego używa macOS lub każde konto, a nie folder z projektami. Wybierz folder, w którym są Twoje projekty."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "É uma pasta que o macOS ou todas as contas usam, não uma pasta de projetos. Escolha a pasta em que estão os seus projetos."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Este un dosar folosit de macOS sau de toate conturile, nu un dosar de proiecte. Alegeți dosarul în care se află proiectele dvs."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Это папка, которую использует macOS или все учетные записи, а не папка с проектами. Выберите папку, где находятся Ваши проекты."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Det är en mapp som macOS eller alla konton använder, inte en mapp med projekt. Välj mappen som dina projekt ligger i."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bu, projelerin bulunduğu bir klasör değil; macOS’in veya her hesabın kullandığı bir klasör. Projelerinizin bulunduğu klasörü seçin."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Це папка, якою користуються macOS або всі облікові записи, а не папка з проєктами. Виберіть папку, у якій лежать ваші проєкти."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它是macOS或所有账户都会使用的文件夹,而不是存放项目的文件夹。请选取你的项目所在的文件夹。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "這是macOS或所有帳號都會使用的檔案夾,而不是存放計畫案的檔案夾。請選擇你的計畫案所在的檔案夾。"
+ }
+ }
+ }
+ },
"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" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index 8164a27f..ae649f02 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -407,6 +407,7 @@ extension ProjectArtifacts.Refusal {
var summary: String {
switch self {
case .tooBroad: "a whole home folder or disk is too much to search"
+ case .systemFolder: "it is a folder that macOS or every account uses, not a folder of projects"
case .inTheCloud: "it is in a folder that syncs to your other devices through iCloud or another app, which Peel leaves to that app"
case .notAFolder: "it isn't a folder Peel can reach"
case .inAPackage: "it is an app or another package, or inside one, and what is inside belongs to it"
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index 34e24437..9d35d9ce 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -898,7 +898,8 @@ public enum ProjectArtifacts {
}
}
return Scan(
- artifacts: await holdingBackWhatGitTracks(found).sorted { SizeTotal([$0.size]) > SizeTotal([$1.size]) },
+ artifacts: holdingBackWhatIsShared(await holdingBackWhatGitTracks(found))
+ .sorted { SizeTotal([$0.size]) > SizeTotal([$1.size]) },
wasCutShort: wasCutShort,
unreadableLocations: unreadable.sorted {
PathPattern.comparablePath(of: $0) < PathPattern.comparablePath(of: $1)
@@ -911,6 +912,21 @@ public enum ProjectArtifacts {
/// Holds back each artifact Git tracks files in, which is part of the project rather than something a build makes
/// again, and each in a repository whose index can't be read. What the walk saw inside comes first.
+ /// Holds back each artifact in `/Users/Shared`, which belongs to every account on the Mac, once nothing found
+ /// inside it says more.
+ static func holdingBackWhatIsShared(_ artifacts: [ProjectArtifact]) -> [ProjectArtifact] {
+ artifacts.map { artifact in
+ let path = PathPattern.comparablePath(of: artifact.url).lowercased()
+ let isShared = ["/users/shared", "/system/volumes/data/users/shared"].contains {
+ PathComponents.isPath(path, atOrInside: $0)
+ }
+ guard artifact.heldBack == nil, isShared else { return artifact }
+ var held = artifact
+ held.heldBack = .sharedWithEveryone
+ return held
+ }
+ }
+
static func holdingBackWhatGitTracks(_ artifacts: [ProjectArtifact]) async -> [ProjectArtifact] {
var result = artifacts
var indexes: [GitIndex.Repository: GitIndex?] = [:]
@@ -952,6 +968,8 @@ public enum ProjectArtifacts {
public enum Refusal: Sendable, Hashable {
case tooBroad
+ /// A folder macOS or every account uses, such as `/Applications`, `/opt`, or `/Users/Shared`.
+ case systemFolder
case inTheCloud
case notAFolder
/// An app or another package, or a folder inside one: what is inside belongs to it.
@@ -991,11 +1009,14 @@ public enum ProjectArtifacts {
folder == "library" && ["mobile documents", "cloudstorage"].contains(inside)
}
if isInACloudFolder { return .inTheCloud }
+ if homes.contains(path) { return .tooBroad }
+ // The data volume's own path reaches the same folders as the path without it.
+ let names = components.starts(with: ["system", "volumes", "data"]) ? Array(components.dropFirst(3)) : components
+ if names.isEmpty { return .tooBroad }
+ if names.count == 1 { return .systemFolder }
// A home folder and a volume root both have two components, so they are recognized by name.
- if components.count < 2 || homes.contains(path) { return .tooBroad }
- if components.count == 2, ["users", "volumes"].contains(components[0]) { return .tooBroad }
- if path == "/system/volumes/data" { return .tooBroad }
- if components.count == 5, components.starts(with: ["system", "volumes", "data", "users"]) { return .tooBroad }
+ if names.count == 2, names[0] == "volumes" { return .tooBroad }
+ if names.count == 2, names[0] == "users" { return names[1] == "shared" ? .systemFolder : .tooBroad }
}
var isDirectory: ObjCBool = false
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index e238239e..71513043 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -1355,9 +1355,44 @@ struct ProjectArtifactsTests {
#expect(ProjectArtifacts.refusal(for: app.appending(path: "Contents/Resources/app"), home: home) == .inAPackage)
}
+ @Test func namesAFolderThatMacOSOrEveryAccountUsesForWhatItIs() {
+ let home = URL(filePath: "/Users/x", directoryHint: .isDirectory)
+ let folders = [
+ "/Applications", "/Library", "/opt", "/Users", "/Users/Shared", "/users/shared",
+ "/System/Volumes/Data/Users/Shared", "/System/Volumes/Data/Applications",
+ ]
+
+ for folder in folders {
+ #expect(ProjectArtifacts.refusal(for: URL(filePath: folder), home: home) == .systemFolder, "\(folder)")
+ }
+ #expect(ProjectArtifacts.refusal(for: URL(filePath: "/"), home: home) == .tooBroad)
+ #expect(ProjectArtifacts.refusal(for: URL(filePath: "/Users/someone"), home: home) == .tooBroad)
+ #expect(ProjectArtifacts.refusal(for: URL(filePath: "/System/Volumes/Data/Users/x"), home: home) == .tooBroad)
+ }
+
+ @Test func holdsBackWhatIsInTheFolderEveryAccountShares() {
+ func artifact(_ path: String, heldBack: HoldBack? = nil) -> ProjectArtifact {
+ let url = URL(filePath: path, directoryHint: .isDirectory)
+ return ProjectArtifact(
+ url: url, project: url.deletingLastPathComponent(), name: url.lastPathComponent, tool: "npm", size: 20,
+ lastActivity: nil, hasGenericName: false, isEnvironment: false, heldBack: heldBack
+ )
+ }
+ let artifacts = [
+ artifact("/Users/Shared/Projects/app/node_modules"),
+ artifact("/System/Volumes/Data/Users/Shared/Projects/web/node_modules"),
+ artifact("/Users/x/Code/app/node_modules"),
+ artifact("/Users/Shared/Projects/kit/Pods", heldBack: .trackedByGit),
+ ]
+
+ let held = ProjectArtifacts.holdingBackWhatIsShared(artifacts).map(\.heldBack)
+
+ #expect(held == [.sharedWithEveryone, .sharedWithEveryone, nil, .trackedByGit])
+ }
+
@Test func refusesRootsThatAreTooBroadOrNotOurs() {
#expect(ProjectArtifacts.refusal(for: URL(filePath: "/")) == .tooBroad)
- #expect(ProjectArtifacts.refusal(for: URL(filePath: "/Users")) == .tooBroad)
+ #expect(ProjectArtifacts.refusal(for: URL(filePath: "/Users")) == .systemFolder)
#expect(ProjectArtifacts.refusal(for: URL(filePath: "/Users/x/Library/Mobile Documents/com~apple~Pages")) == .inTheCloud)
#expect(ProjectArtifacts.refusal(for: URL(filePath: "/Users/x/Library/CloudStorage/Dropbox")) == .inTheCloud)
#expect(ProjectArtifacts.refusal(for: URL(filePath: "/Users/x/does-not-exist")) == .notAFolder)
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 97b1afb6..a839e0d1 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -225,6 +225,7 @@ extension ProjectArtifacts.Refusal {
var explanation: String {
switch self {
case .tooBroad: String(localized: "A whole home folder or disk is too much to search. Choose the folder your projects are in.")
+ case .systemFolder: String(localized: "It is a folder that macOS or every account uses, not a folder of projects. Choose the folder your projects are in.")
case .inTheCloud: String(localized: "It is in a folder that syncs to your other devices through iCloud or another app, which Peel leaves to that app.")
case .notAFolder: String(localized: "It isn’t a folder Peel can reach. A disk that isn’t connected looks like this too.")
case .inAPackage: String(localized: "It is an app or another package, or inside one, and what is inside belongs to it.")