Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Find Homebrew's cache where HOMEBREW_CACHE moves it
Țugui Dragoș81c010e13783
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 74013363..f5aaaf12 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -398,17 +398,17 @@ macOS asks the user to approve it once. It talks to the app over XPC.program has open or is mounted, what syncs to other devices, and what is in `/Users/Shared`.- **Developer.** `DeveloperCaches.definitions` names each tool's folders, under the home folder, the account's cachefolder, or its temporary folder, each with what it holds (`ContentKind`) and where the tool documents it, a page or- a file in its repository at a commit, which the tests hold. Only what one tool owns outright is listed: no- toolchain or tool version in use, nothing holding an account or a token, and of a folder that keeps work beside a- cache only the cache. A folder a tool's configuration moved is found where it went (`Relocation`, read by- `ToolSettings` from the file the tool's `config set` writes, never by running the tool), the apps built on Electron- by a rule over the installed apps (`electronDefinitions`), and some folders are listed entry by entry: each- workspace Xcode built in DerivedData, each archive, an editor's state for a project that is gone, and the versions- an installer keeps beside the one it runs. `Location.isRecommended` is what Peel suggests: build data, downloads,- caches, and logs, once measured and not held back (a secret inside, a clone of another repository, a recent write- where a server may still use it, a workspace that may still be in use), and `peel caches` gives each other row's- reason by the same rule. Nothing moves while one of the tool's apps runs (`runningApp`), and a folder in the- temporary folder that a program holds open isn't listed.+ a file in its repository at a commit, which the tests hold. Only what one tool owns outright is listed: no toolchain+ or tool version in use, nothing holding an account or a token, and of a folder that keeps work beside a cache only+ the cache. A folder a tool's configuration moved is found where it went (`Relocation`, read by `ToolSettings` from+ the file the tool's `config set` writes, or from Homebrew's `brew.env` files, never by running the tool), the apps+ built on Electron by a rule over the installed apps (`electronDefinitions`), and some folders are listed entry by+ entry: each workspace Xcode built in DerivedData, each archive, an editor's state for a project that is gone, and+ the versions an installer keeps beside the one it runs. `Location.isRecommended` is what Peel suggests: build data,+ downloads, caches, and logs, once measured and not held back (a secret inside, a clone of another repository, a+ recent write where a server may still use it, a workspace that may still be in use), and `peel caches` gives each+ other row's reason by the same rule. Nothing moves while one of the tool's apps runs (`runningApp`), and a folder in+ the temporary folder that a program holds open isn't listed.- **Background Items.** `BackgroundItems.scan` reads the job files in `~/Library/LaunchAgents`,`/Library/LaunchAgents`, and `/Library/LaunchDaemons`, and asks launchd which jobs are loaded, in the GUI domain, theuser's own, and the system's, and which it keeps disabled (`launchctl print-disabled`). A loaded job no file therediff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swiftindex a11c8c8f..cfa26c99 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift@@ -355,7 +355,7 @@ public enum DeveloperCaches {struct FoldersLeftToDeveloper {private let folders: [(path: [String], own: [[String]])]- init(home: URL, userCache: URL? = nil) {+ init(home: URL, userCache: URL? = nil, root: URL = URL(filePath: "/", directoryHint: .isDirectory)) {// Not through `comparablePath`: standardizing drops `/private` only from a path that exists, and most// paths in the table don't.let names = { (url: URL) in PathComponents.of(PathPattern.canonical(url).path(percentEncoded: false)) }@@ -363,7 +363,7 @@ public enum DeveloperCaches {let userCacheNames = userCache.map(names)// A tool's configuration can move a cache into a place Space shows, and the folder it names is the// tool's own there.- let settings = ToolSettings(home: home)+ let settings = ToolSettings(home: home, root: root)folders = DeveloperCaches.definitions.flatMap { definition inlet own = definition.ownFolders.map { homeNames + PathComponents.of($0) }let usual = definition.folders.compactMap { folder -> ([String], [[String]])? in@@ -461,13 +461,13 @@ public enum DeveloperCaches {Folder("Library/Caches/org.carthage.CarthageKit", .downloads, source: "https://github.com/Carthage/Carthage/blob/e33e133a5427129b38bfb1ae18d8f56b29a93204/Source/CarthageKit/Constants.swift#L31"),]),Definition(id: "homebrew", name: "Homebrew", systemImage: "mug", appBundleIdentifiers: [], folders: [- Folder("Library/Caches/Homebrew/downloads", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/download_strategy/abstract_file_download_strategy.rb#L42"),- Folder("Library/Caches/Homebrew/Cask", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/cask/cache.rb#L9"),- Folder("Library/Caches/Homebrew/bootsnap", .cache, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/startup/bootsnap.rb#L45"),- Folder("Library/Caches/Homebrew/*_cache", .cache, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/package_manager_cache.rb#L8-L27"),- Folder("Library/Caches/Homebrew/glide_home", .cache, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/package_manager_cache.rb#L15"),- Folder("Library/Caches/Homebrew/api-source", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/api.rb#L26"),- Folder("Library/Caches/Homebrew/gh-actions-artifact", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/utils/github/artifacts/github_artifact_download_strategy.rb#L9"),+ Folder("Library/Caches/Homebrew/downloads", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/download_strategy/abstract_file_download_strategy.rb#L42", movedBy: .homebrewCache(inside: "downloads")),+ Folder("Library/Caches/Homebrew/Cask", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/cask/cache.rb#L9", movedBy: .homebrewCache(inside: "Cask")),+ Folder("Library/Caches/Homebrew/bootsnap", .cache, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/startup/bootsnap.rb#L45", movedBy: .homebrewCache(inside: "bootsnap")),+ Folder("Library/Caches/Homebrew/*_cache", .cache, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/package_manager_cache.rb#L8-L27", movedBy: .homebrewCache(inside: "*_cache")),+ Folder("Library/Caches/Homebrew/glide_home", .cache, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/package_manager_cache.rb#L15", movedBy: .homebrewCache(inside: "glide_home")),+ Folder("Library/Caches/Homebrew/api-source", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/api.rb#L26", movedBy: .homebrewCache(inside: "api-source")),+ Folder("Library/Caches/Homebrew/gh-actions-artifact", .downloads, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/utils/github/artifacts/github_artifact_download_strategy.rb#L9", movedBy: .homebrewCache(inside: "gh-actions-artifact")),Folder("Library/Logs/Homebrew", .logs, source: "https://github.com/Homebrew/brew/blob/1299da92f98e1284cc762977c0e2de31dbb5854c/Library/Homebrew/utils/os.sh#L55-L56"),]),Definition(id: "swiftlint", name: "SwiftLint", systemImage: "swift", appBundleIdentifiers: [], folders: [@@ -1459,7 +1459,8 @@ public enum DeveloperCaches {return await scan(definitions + electron, homeDirectory: environment.homeDirectory,userCacheDirectory: environment.userCacheDirectory,- userTemporaryDirectory: environment.userTemporaryDirectory, exclusions: exclusions+ userTemporaryDirectory: environment.userTemporaryDirectory, rootDirectory: environment.rootDirectory,+ exclusions: exclusions)}@@ -1480,7 +1481,8 @@ public enum DeveloperCaches {return await scan(models, homeDirectory: environment.homeDirectory,userCacheDirectory: environment.userCacheDirectory,- userTemporaryDirectory: environment.userTemporaryDirectory, exclusions: exclusions+ userTemporaryDirectory: environment.userTemporaryDirectory, rootDirectory: environment.rootDirectory,+ exclusions: exclusions).flatMap(\.locations)}@@ -1586,12 +1588,13 @@ public enum DeveloperCaches {homeDirectory: URL,userCacheDirectory: URL? = nil,userTemporaryDirectory: URL? = nil,+ rootDirectory: URL = URL(filePath: "/", directoryHint: .isDirectory),exclusions: Exclusions = .none,measure: @escaping LeftoverScanner.Measure = LeftoverScanner.walk,preference: @escaping @Sendable (String) -> String? = Self.xcodePreference,openFiles: OpenFiles = OpenFiles()) async -> [DeveloperEnvironment] {- let settings = ToolSettings(home: homeDirectory)+ let settings = ToolSettings(home: homeDirectory, root: rootDirectory)let listening = definitions.contains { $0.folders.contains(where: \.namesItsPort) }? ListeningPorts.ofThisAccount() : []// Four tools at a time: measured all at once, their big folders would share the disk and each run out ofdiff --git a/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift b/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swiftindex 9b52a4d6..c435bb63 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift@@ -18,6 +18,9 @@ extension DeveloperCaches {case goModuleCache(inside: String)/// Go's build cache, which holds the `README` Go writes in it.case goBuildCache+ /// Homebrew's cache, with the folders inside it named by a pattern such as `*_cache`. It counts only while it+ /// holds the `api` folder Homebrew keeps its definitions in, since the setting can name any folder.+ case homebrewCache(inside: String)/// Where the tool says which file holds the setting and where the setting puts the folder.var sources: [String] {@@ -49,6 +52,12 @@ extension DeveloperCaches {"https://github.com/golang/go/blob/a90c4a7a586c70f0de61f5507d5c347702432e39/src/cmd/go/internal/cfg/cfg.go#L347-L363","https://github.com/golang/go/blob/a90c4a7a586c70f0de61f5507d5c347702432e39/src/cmd/go/internal/cache/default.go#L25-L31",]+ case .homebrewCache: [+ "https://github.com/Homebrew/brew/blob/3073d6a8c34f71da054b000cfdbb62594a07c969/bin/brew#L127-L181",+ "https://github.com/Homebrew/brew/blob/3073d6a8c34f71da054b000cfdbb62594a07c969/Library/Homebrew/brew.sh#L58",+ "https://github.com/Homebrew/brew/blob/3073d6a8c34f71da054b000cfdbb62594a07c969/Library/Homebrew/startup/config.rb#L22",+ "https://github.com/Homebrew/brew/blob/3073d6a8c34f71da054b000cfdbb62594a07c969/Library/Homebrew/api.rb#L25",+ ]}}@@ -76,6 +85,9 @@ extension DeveloperCaches {settings.goModuleCache.map { [($0.appending(path: inside, directoryHint: .isDirectory), $0)] } ?? []case .goBuildCache:settings.goBuildCache.flatMap { Self.holdsGosReadme($0) ? [($0, $0)] : nil } ?? []+ case .homebrewCache(let inside):+ settings.homebrewCaches.filter { $0.appending(path: "api", directoryHint: .isDirectory).isRealFolder }+ .flatMap { cache in Self.entries(of: cache, named: inside).map { ($0, cache) } }}return found.map { (Self.entry($0.place), Self.entry($0.named)) }.filter(\.place.isRealFolder)}@@ -92,6 +104,13 @@ extension DeveloperCaches {return names.filter(isAVersion).sorted().map { root.appending(path: $0, directoryHint: .isDirectory) }}+ /// The entries of `folder` whose names, as the disk writes them, match `pattern`, a hidden one only by name.+ private static func entries(of folder: URL, named pattern: String) -> [URL] {+ let names = (try? FileManager.default.contentsOfDirectory(atPath: folder.path(percentEncoded: false))) ?? []+ return names.filter { fnmatch(pattern, $0, FNM_PERIOD) == 0 }.sorted()+ .map { folder.appending(path: $0, directoryHint: .isDirectory) }+ }+private static func isAVersion(_ name: String) -> Bool {name.count > 1 && name.first == "v" && name.dropFirst().allSatisfy { $0.isASCII && $0.isNumber }}diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swiftindex 6222f197..75d5fa8a 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift@@ -19,8 +19,11 @@ struct ToolSettings: Sendable {let goModuleCache: URL?/// Go's build cache: `GOCACHE` in the same file.let goBuildCache: URL?+ /// Homebrew's caches: `HOMEBREW_CACHE` in the `brew.env` files `bin/brew` reads.+ let homebrewCaches: [URL]- init(home: URL) {+ /// The settings of the tools of `home`, with Homebrew's files for everyone read from `root`.+ init(home: URL, root: URL = URL(filePath: "/", directoryHint: .isDirectory)) {let npmrc = Self.text(at: home.appending(path: ".npmrc"))let yarnrc = Self.text(at: home.appending(path: ".yarnrc"))let pnpm = home.appending(path: "Library/Preferences/pnpm", directoryHint: .isDirectory)@@ -58,6 +61,30 @@ struct ToolSettings: Sendable {.flatMap { $0.isEmpty ? nil : String($0) + "/pkg/mod" }goModuleCache = (goValue("GOMODCACHE") ?? goPath).flatMap(Self.absolute)goBuildCache = goValue("GOCACHE").flatMap(Self.absolute)+ homebrewCaches = Self.homebrewCaches(home: home, root: root)+ }++ /// Every place `HOMEBREW_CACHE` names in the `brew.env` files, for each prefix Homebrew may be in and each folder+ /// the person's own file may be in: `~/.homebrew`, or `~/.config/homebrew` for a shell that sets+ /// `XDG_CONFIG_HOME` there. Homebrew takes the value as written, so only an absolute path names a place.+ private static func homebrewCaches(home: URL, root: URL) -> [URL] {+ let chosen = HomebrewChoice(url: HomebrewChoice.url(inHome: home)).load()+ .map { $0.deletingLastPathComponent().deletingLastPathComponent() }+ let prefixes = [chosen].compactMap(\.self)+ + Homebrew.usualPrefixes.map { root.appending(path: $0, directoryHint: .isDirectory) }+ let ownFolders = [".homebrew", ".config/homebrew"].map { home.appending(path: $0, directoryHint: .isDirectory) }+ let system = root.appending(path: "etc/homebrew/brew.env")+ var caches: [URL] = []+ for prefix in prefixes {+ for folder in ownFolders {+ let files = Homebrew.settingsFiles(system: system, prefix: prefix, userConfiguration: folder)+ guard let cache = Homebrew.setting("HOMEBREW_CACHE", in: files).flatMap(absolute),+ !caches.contains(cache)+ else { continue }+ caches.append(cache)+ }+ }+ return caches}/// A configuration file is a few lines; a megabyte is far beyond any real one.diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swiftindex fea16fa6..8b6c294f 100644--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift@@ -549,7 +549,10 @@ public enum Homebrew {executable(chosen: HomebrewChoice().load())}- static let usualPlaces = ["/opt/homebrew/bin/brew", "/usr/local/bin/brew"].map { URL(filePath: $0) }+ /// The prefixes Homebrew installs itself in by default, from the root of the disk.+ static let usualPrefixes = ["opt/homebrew", "usr/local"]++ static let usualPlaces = usualPrefixes.map { URL(filePath: "/\($0)/bin/brew") }/// A `brew` in a usual place runs by the rule a chosen one does: this account's or root's, and nobody else can/// change it, since its code runs as this account whenever Peel asks Homebrew something.@@ -639,7 +642,7 @@ public enum Homebrew {/// The value the last line of `files` gives `name`, read as `bin/brew` reads them (`read -r`): a line counts only/// once it ends, trimmed of spaces and tabs, and the value is what follows the equals sign.- private static func setting(_ name: String, in files: [URL]) -> String? {+ static func setting(_ name: String, in files: [URL]) -> String? {var value: String?for file in files {guard let data = BoundedRead.data(at: file, maximum: 64 * 1_024) else { continue }diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swiftindex 325201f7..2a72e034 100644--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/HomebrewChoice.swift@@ -26,7 +26,11 @@ public struct HomebrewChoice: Sendable {}public static var defaultURL: URL {- PeelFolder.url.appending(path: "homebrew.json")+ url(inHome: .homeDirectory)+ }++ static func url(inHome home: URL) -> URL {+ PeelFolder.url(inHome: home).appending(path: "homebrew.json")}/// The chosen `brew`, or nil when none was chosen. It stays chosen when it can no longer be run, so Peel runsdiff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swiftindex a7981d87..be24253f 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift@@ -268,7 +268,7 @@ public enum SpaceRemoval {}}let developerFolders = DeveloperCaches.FoldersLeftToDeveloper(- home: environment.homeDirectory, userCache: environment.userCacheDirectory+ home: environment.homeDirectory, userCache: environment.userCacheDirectory, root: environment.rootDirectory)for url in item.urls {// Everything in an app's container is that app's, whatever its name.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swiftindex c1f67465..2e5bbd53 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift@@ -528,6 +528,28 @@ struct DeveloperCachesTests {#expect(chat.locations.map(\.url.lastPathComponent) == ["GPUCache"])}+ /// Homebrew's cache, moved by `HOMEBREW_CACHE`, is found where it went by the names Homebrew gives its folders+ /// there, and only where Homebrew keeps its definitions: the setting can name any folder.+ @Test func findsHomebrewsCacheWhereItsSettingsMoveIt() async throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let moved = directory.url.appending(path: "Fast/Homebrew").path(percentEncoded: false)+ let other = directory.url.appending(path: "Fast/Other").path(percentEncoded: false)+ try directory.file("home/.homebrew/brew.env", contents: Data("HOMEBREW_CACHE=\(moved)\n".utf8))+ try directory.file("home/.config/homebrew/brew.env", contents: Data("HOMEBREW_CACHE=\(other)\n".utf8))+ try directory.directory("Fast/Homebrew/api")+ for path in ["downloads/0a1b--tool.tar.gz", "Cask/app--1.0.dmg", "go_cache/entry", ".x_cache/a", "Music/a.m4a"] {+ try directory.file("Fast/Homebrew/\(path)", bytes: 4_096)+ }+ try directory.file("Fast/Other/downloads/0a1b--tool.tar.gz", bytes: 4_096)+ let homebrew = DeveloperCaches.definitions.filter { $0.id == "homebrew" }++ let found = await DeveloperCaches.scan(homebrew, homeDirectory: home, rootDirectory: directory.url)++ let listed = Set(found.flatMap(\.locations).map { $0.url.path(percentEncoded: false) })+ #expect(listed == Set(["Cask", "downloads", "go_cache"].map { "\(moved)/\($0)" }))+ }+/// A large `DerivedData`, or a Gradle cache on a cold disk, may not be measured in time. Such a folder is not/// read as empty: it is listed first, with no size, and never selected for the user.@Test func aFolderThatDidNotAnswerInTimeIsNotReadAsEmpty() async throws {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swiftindex aea4312c..55decbb9 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift@@ -172,6 +172,45 @@ struct ToolSettingsTests {#expect(left.inside(home.appending(path: "Library/Caches", directoryHint: .isDirectory)).contains(["npm"]))}+ /// `bin/brew` reads the system's file, its prefix's, then the person's, the last line that sets a variable+ /// winning, and the system's once more when it says so. Each prefix and each place the person's file may be in+ /// gives a place, and a value names one only as an absolute path, since Homebrew takes it as written.+ @Test func findsHomebrewsCacheWhereItsSettingsFilesMoveIt() throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let write = { (path: String, text: String) throws in _ = try directory.file(path, contents: Data(text.utf8)) }+ try write("etc/homebrew/brew.env", "HOMEBREW_CACHE=/for/everyone\n")+ try write("usr/local/etc/homebrew/brew.env", "HOMEBREW_CACHE=/for/intel\n")+ try write("home/.homebrew/brew.env", "HOMEBREW_CACHE=/own\n HOMEBREW_CACHE=/own/last\n")+ try write("home/.config/homebrew/brew.env", "HOMEBREW_CACHE=/unfinished")+ let caches = { ToolSettings(home: home, root: directory.url).homebrewCaches.map { Self.path($0) } }++ #expect(caches() == ["/own/last", "/for/everyone", "/for/intel"])++ try write("etc/homebrew/brew.env", "HOMEBREW_CACHE=/for/everyone\nHOMEBREW_SYSTEM_ENV_TAKES_PRIORITY=1\n")+ #expect(caches() == ["/for/everyone"], "the system's file is read again last")++ try write("etc/homebrew/brew.env", "")+ try write("usr/local/etc/homebrew/brew.env", "HOMEBREW_CACHE=\n")+ try write("home/.homebrew/brew.env", "HOMEBREW_CACHE=\"/quoted\"\n")+ try write("home/.config/homebrew/brew.env", "HOMEBREW_CACHE=~/Caches\nHOMEBREW_CACHE=$HOME/Caches\n")+ #expect(caches().isEmpty, "a value taken as written names no place")+ }++ /// Space leaves to Developer the folder Homebrew's settings for everyone moved its cache into.+ @Test func spaceLeavesToDeveloperHomebrewsCacheMovedIntoItsCaches() throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let moved = home.appending(path: "Library/Caches/brew").path(percentEncoded: false)+ try directory.file("etc/homebrew/brew.env", contents: Data("HOMEBREW_CACHE=\(moved)\n".utf8))+ try directory.directory("home/Library/Caches/brew/api")+ try directory.file("home/Library/Caches/brew/downloads/0a1b--tool.tar.gz")++ let left = DeveloperCaches.FoldersLeftToDeveloper(home: home, root: directory.url)++ #expect(left.inside(home.appending(path: "Library/Caches", directoryHint: .isDirectory)).contains(["brew"]))+ }+private static func path(_ url: URL?) -> String? {url.map { $0.path(percentEncoded: false) }.map { $0.count > 1 && $0.hasSuffix("/") ? String($0.dropLast()) : $0 }}