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
Size File Search's files by what moving them frees
Țugui Dragoșd44558be78d5
diff --git a/GUIDE.md b/GUIDE.mdindex 947b52c3..2b2a9e8d 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -149,7 +149,8 @@ Space shows what fills your disk, area by area, and what each area is.file in a Library folder, an app's working data, is listed last and never recommended, and one that needs anadministrator stays where it is. The page says how many files Spotlight found that it doesn't list, and why: whatsyncs to your other devices, what you excluded, what sits where Peel never moves anything, and what macOS didn't let- Peel look at.+ Peel look at. A file's size is what moving it frees, the list goes by it, and a file that frees less than its length,+ such as a copy that shares its storage, says so.<details><summary>Developer, Build Artifacts, and Space, in detail</summary>diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 1aff3289..f4ebdb12 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -90559,6 +90559,113 @@}}},+ "Moving this frees less than its length of %@: another file shares its storage, or it takes less space than that." : {+ "comment" : "A note beside a file in File Search, and in its details. %@ is the file's length, as Finder shows it, such as 10 GB; Peel shows what moving the file would free, which is less: a copy may share its storage, another name may keep it, or it may take less space on the disk than its length.",+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Přesunutím tohoto souboru se uvolní méně, než kolik činí jeho délka %@: sdílí místo na disku s jiným souborem, nebo zabírá méně místa, než odpovídá jeho délce."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Das Verschieben dieser Datei gibt weniger als ihre Größe von %@ frei: Eine andere Datei teilt sich Speicherplatz mit ihr, oder sie belegt weniger Platz, als ihre Größe angibt."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Trasladar esto libera menos que su tamaño (%@): otro archivo comparte su almacenamiento, u ocupa en el disco menos espacio que eso."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Déplacer ce fichier libère moins que sa taille de %@ : un autre fichier partage son stockage, ou il occupe moins d’espace que cela."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Spostare questo file libera meno della sua dimensione di %@: lo spazio che occupa è condiviso con un altro file, oppure è inferiore a quella dimensione."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "これをゴミ箱に入れても、解放される容量はファイルサイズの%@より少なくなります。ほかのファイルとストレージを共有しているか、ディスク上で実際に使用している領域がそれより少ないためです。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "이 파일을 이동하면 파일 크기인 %@보다 적은 공간이 확보됩니다. 다른 파일이 이 파일의 저장 공간을 공유하거나, 이 파일이 디스크에서 그보다 적은 공간을 차지하기 때문입니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Als je dit verplaatst, komt er minder ruimte vrij dan de bestandsgrootte van %@: een ander bestand deelt de opslag ervan, of het neemt minder ruimte in dan dat."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Przeniesienie tego pliku zwolni mniej miejsca niż jego wielkość (%@): inny plik współdzieli z nim miejsce albo sam plik zajmuje na dysku mniej miejsca."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Mover este arquivo libera menos que %@, o tamanho dele: ele compartilha o armazenamento com outro arquivo ou ocupa menos espaço que isso."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Mutarea acestui fișier eliberează mai puțin decât lungimea sa de %@: un alt fișier îi partajează spațiul de stocare sau fișierul ocupă mai puțin spațiu decât atât."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Перемещение этого файла освободит меньше, чем его длина в %@: другой файл использует с ним общее пространство на диске, или файл занимает на диске меньше места."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Om du flyttar den här filen frigörs mindre än dess storlek på %@: en annan fil delar dess lagringsutrymme, eller så tar den mindre plats än så."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bunu taşımak, %@ olan büyüklüğünden daha az yer boşaltır: başka bir dosya onunla aynı saklama alanını paylaşıyor veya dosya diskte bu kadar yer kaplamıyor."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Переміщення цього файлу звільнить менше місця, ніж його розмір (%@): інший файл спільно використовує з ним сховище, або на диску він займає менше."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "移动此文件所释放的空间会小于它的大小%@:另一个文件与它共享储存空间,或者它在磁盘上实际占用的空间更小。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "移動此檔案所釋放的空間會少於其長度%@:另一個檔案與它共用儲存空間,或它佔用的空間比這還少。"+ }+ }+ }+ },"Muted Updates" : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swiftindex a474ba2c..73c9a835 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift@@ -969,7 +969,10 @@ struct SearchCommand: AsyncParsableCommand {private struct Record: Encodable {let path: String+ /// What moving the file would free.let size: Int64+ /// Its length, which `--min-size` reads.+ let length: Int64let modificationDate: Date}@@ -1008,7 +1011,10 @@ struct SearchCommand: AsyncParsableCommand {if output.json {try Output.json(results.files.map {- Record(path: Output.path($0.url), size: $0.size, modificationDate: $0.modificationDate)+ Record(+ path: Output.path($0.url), size: $0.size, length: $0.length,+ modificationDate: $0.modificationDate+ )})} else if results.files.isEmpty {diff --git a/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift b/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swiftindex d6e30e80..111515f1 100644--- a/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift+++ b/Packages/PeelCore/Sources/PeelCore/Search/FileSearch.swift@@ -45,7 +45,10 @@ public struct FileSearchCriteria: Sendable, Hashable {public struct FoundFile: Sendable, Hashable, Identifiable {public let url: URL+ /// What moving the file would free (`ReclaimableSpace.of`).public let size: Int64+ /// Its length, as Finder shows it and the search's size reads it.+ public let length: Int64public let modificationDate: Datepublic let requiresPrivileges: Bool/// True when the file sits in a Library folder, so it is an app's working data rather than something the user@@ -56,6 +59,10 @@ public struct FoundFile: Sendable, Hashable, Identifiable {public var identity: FileIdentity?public var id: URL { url }++ /// True when moving the file frees less than its length: another file shares its storage, or it takes less+ /// space than its length.+ public var freesLessThanItsLength: Bool { size < length }}public struct FileSearchResults: Sendable {@@ -194,7 +201,7 @@ public enum FileSearch {if $0.belongsToAnApp != $1.belongsToAnApp { return !$0.belongsToAnApp }return $0.info.st_size != $1.info.st_size ? $0.info.st_size > $1.info.st_size : $0.path < $1.path}- for candidate in candidates {+ listing: for candidate in candidates {let url = URL(filePath: candidate.path)let hasRoom = results.files.count < maximumResultslet judgment = judge(@@ -209,11 +216,12 @@ public enum FileSearch {case .listed:guard hasRoom else {results.isTruncated = true- return results+ break listing}results.files.append(FoundFile(url: url,- size: Int64(candidate.info.st_size),+ size: ReclaimableSpace.of(url),+ length: Int64(candidate.info.st_size),modificationDate: Date(timeIntervalSince1970: TimeInterval(candidate.info.st_mtimespec.tv_sec)),requiresPrivileges: FileAccess.requiresPrivilegesToRemove(url),belongsToAnApp: candidate.belongsToAnApp,@@ -221,6 +229,13 @@ public enum FileSearch {))}}+ // The longest made the list, which then goes by what moving each file frees.+ results.files.sort {+ if $0.belongsToAnApp != $1.belongsToAnApp { return !$0.belongsToAnApp }+ if $0.size != $1.size { return $0.size > $1.size }+ return $0.length != $1.length+ ? $0.length > $1.length : $0.url.path(percentEncoded: false) < $1.url.path(percentEncoded: false)+ }return results}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swiftindex 4538754d..4fdc9046 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/FileSearchTests.swift@@ -327,6 +327,33 @@ struct FileSearchTests {/// The guard is asked only about the files that can make the list: the largest first, and no further once/// the list is full and one more file shows it had to be cut.+ /// A file's size is what moving it frees, never its length, and the list goes by it: two clones keep the same+ /// blocks, so moving either frees nothing while the other stays.+ @Test func sizesEachFileByWhatMovingItFrees() throws {+ let directory = try TemporaryDirectory()+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)+ let random = { (count: Int) in Data((0..<count).map { _ in UInt8.random(in: 0...255) }) }+ let original = try directory.file("home/Documents/original.mov", contents: random(1_048_576))+ let handle = try FileHandle(forWritingTo: original)+ try handle.synchronize()+ try handle.close()+ let clone = home.appending(path: "Documents/clone.mov")+ try #require(clonefile(original.path(percentEncoded: false), clone.path(percentEncoded: false), 0) == 0)+ let small = try directory.file("home/Documents/small.mov", contents: random(200_000))++ let results = FileSearch.results(+ from: [original, clone, small].map { $0.path(percentEncoded: false) },+ environment: SearchEnvironment(homeDirectory: home, rootDirectory: directory.url)+ )++ let files = Dictionary(uniqueKeysWithValues: results.files.map { ($0.url.lastPathComponent, $0) })+ #expect(files["clone.mov"]?.length == 1_048_576)+ #expect(try #require(files["clone.mov"]?.size) < 1_048_576 / 2)+ #expect(files["clone.mov"]?.freesLessThanItsLength == true)+ #expect(files["small.mov"]?.freesLessThanItsLength == false)+ #expect(results.files.first?.url.lastPathComponent == "small.mov")+ }+@Test func asksTheGuardOnlyAboutFilesThatCanMakeTheList() throws {let directory = try TemporaryDirectory()let home = directory.url.appending(path: "home", directoryHint: .isDirectory)@@ -347,7 +374,7 @@ struct FileSearchTests {#expect(results.files.count == FileSearch.maximumResults)#expect(results.isTruncated)- #expect(results.files.first?.size == Int64(FileSearch.maximumResults + 50))+ #expect(results.files.first?.length == Int64(FileSearch.maximumResults + 50))#expect(asked.withLock { $0 } == FileSearch.maximumResults + 1)}@@ -375,7 +402,8 @@ struct FileSearchTests {let second = try directory.file("home/Documents/second.txt")let files = [first, second].map {FoundFile(- url: $0, size: 16, modificationDate: .now, requiresPrivileges: false, identity: FileIdentity.of($0)+ url: $0, size: 16, length: 16, modificationDate: .now, requiresPrivileges: false,+ identity: FileIdentity.of($0))}let journal = RemovalJournal(beside: home.appending(path: "removals.json"))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SearchingTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SearchingTests.swiftindex e8244542..dcce4897 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/SearchingTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/SearchingTests.swift@@ -123,6 +123,7 @@ struct SearchingTests {let listed = FoundFile(url: url,size: 1_000,+ length: 1_000,modificationDate: .distantPast,requiresPrivileges: false,identity: FileIdentity.of(url)diff --git a/Peel/Views/FileSearch/FileSearchFileView.swift b/Peel/Views/FileSearch/FileSearchFileView.swiftindex 57c10e48..514b786b 100644--- a/Peel/Views/FileSearch/FileSearchFileView.swift+++ b/Peel/Views/FileSearch/FileSearchFileView.swift@@ -44,6 +44,11 @@ struct FileSearchFileView: View {.font(.callout).foregroundStyle(.secondary)}+ if file.freesLessThanItsLength {+ Text("Moving this frees less than its length of \(file.length.byteCount): another file shares its storage, or it takes less space than that.")+ .font(.callout)+ .foregroundStyle(.secondary)+ }} header: {Text("Details")}diff --git a/Peel/Views/FileSearch/FileSearchList.swift b/Peel/Views/FileSearch/FileSearchList.swiftindex 0ac83cc1..960f0ff0 100644--- a/Peel/Views/FileSearch/FileSearchList.swift+++ b/Peel/Views/FileSearch/FileSearchList.swift@@ -187,6 +187,9 @@ struct FileSearchList: View {file.belongsToAnApp? String(localized: "An app keeps this in its Library folder, and may be using it right now."): nil,+ file.freesLessThanItsLength+ ? String(localized: "Moving this frees less than its length of \(file.length.byteCount): another file shares its storage, or it takes less space than that.")+ : nil,].compactMap(\.self)return lines.isEmpty ? nil : lines.joined(separator: "\n\n")}diff --git a/PeelTests/FileSearchLibraryTests.swift b/PeelTests/FileSearchLibraryTests.swiftindex 05647f6e..b6d10e5f 100644--- a/PeelTests/FileSearchLibraryTests.swift+++ b/PeelTests/FileSearchLibraryTests.swift@@ -14,7 +14,9 @@ struct FileSearchLibraryTests {let (started, starting) = AsyncStream<Int>.makeStream()let calls = OSAllocatedUnfairLock(initialState: 0)let found = FileSearchResults(files: [- FoundFile(url: invoice, size: 4_096, modificationDate: .distantPast, requiresPrivileges: false)+ FoundFile(+ url: invoice, size: 4_096, length: 4_096, modificationDate: .distantPast, requiresPrivileges: false+ )])let library = FileSearchLibrary { _, _ inlet call = calls.withLock { $0 += 1; return $0 }