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
What is measured counts by its own name too
Țugui Dragoșfa33b7e15951
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift b/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swiftindex 3144d1c6..f3192e1b 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/FileSize.swift@@ -105,7 +105,8 @@ public enum FileSize {let values = try url.resourceValues(forKeys: [.totalFileAllocatedSizeKey, .contentModificationDateKey])return FolderContents(size: Int64(values.totalFileAllocatedSize ?? 0),- holdsRepository: url.lastPathComponent == ".git",+ holdsRepository: repositoryMarkers.contains(url.lastPathComponent),+ holdsWallet: isWallet(url.lastPathComponent),newestChange: values.contentModificationDate)} catch CocoaError.fileReadNoSuchFile {@@ -145,8 +146,9 @@ public enum FileSize {) else { return FolderContents(size: 0, holdsRepository: false, couldNotBeRead: true) }var total: Int64 = 0- var holdsRepository = false- var holdsWallet = false+ // The folder's own name counts as its entries' do: a `keystore` or a `.git` measured on its own.+ var holdsRepository = repositoryMarkers.contains(url.lastPathComponent)+ var holdsWallet = isWallet(url.lastPathComponent)var newestChange: Date?// A file with several hard links takes its space once. Counting it once per name would overstate what// emptying the folder frees.diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swiftindex af2f8a35..67899336 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSizeTests.swift@@ -5,6 +5,23 @@ import Testingstruct FileSizeTests {/// A file with several names is one file on the disk, so it is counted once. Adding up every name would/// report more than emptying the folder could ever free.+ /// What is measured is looked at by its own name as well as by what is inside it: a wallet's file measured on+ /// its own, a `keystore` folder, and a repository's own folder.+ @Test func theMeasuredItemsOwnNameCounts() async throws {+ let directory = try TemporaryDirectory()+ let wallet = try directory.file("SomeCoin/wallet.dat", bytes: 100)+ let keys = try directory.file("Monero/mine.keys", bytes: 100)+ let keystore = try directory.file("Ethereum/keystore/key", bytes: 100).deletingLastPathComponent()+ let repository = try directory.file("project/.hg/store/data", bytes: 100).deletingLastPathComponent().deletingLastPathComponent()+ let plain = try directory.file("Notes/notes.txt", bytes: 100)++ #expect(await FileSize.contents(of: wallet)?.holdsWallet == true)+ #expect(await FileSize.contents(of: keys)?.holdsWallet == true)+ #expect(await FileSize.contents(of: keystore)?.holdsWallet == true)+ #expect(await FileSize.contents(of: repository)?.holdsRepository == true)+ #expect(await FileSize.contents(of: plain).map { $0.holdsWallet || $0.holdsRepository } == false)+ }+@Test func countsAFileWithSeveralNamesOnce() async throws {let directory = try TemporaryDirectory()let folder = try directory.directory("tree")