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
Read a ZIP's names folder by folder, by the slash byte
Țugui Dragoșa0cf84572fe5
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swiftindex 20e86a9c..e2c21153 100644--- a/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift+++ b/Packages/PeelCore/Sources/PeelCore/Space/Installers.swift@@ -1,5 +1,6 @@import AppKitpublic import Foundation+internal import PeelPrivileged/// A large installer or backup that is easy to forget: an app's disk image, package, or archive, a macOS/// installer, device firmware, or a backup of an iPhone or iPad.@@ -320,14 +321,17 @@ public enum Installers {guard let names = ZipDirectory.names(at: url) else { return nil }var inside: String?for name in names {- let first = String(name.prefix { $0 != "/" })+ guard let first = PathComponents.of(name).first else { continue }if first == "__MACOSX" || first.hasPrefix("._") { continue }guard inside == nil || inside == first else { return nil }inside = first}guard let inside, inside.count > 4 else { return nil }let suffix = (inside as NSString).pathExtension.lowercased()- let isAnApp = suffix == "app" && names.contains { $0.count > inside.count + 1 && $0.hasPrefix(inside + "/") }+ let isAnApp = suffix == "app" && names.contains { name in+ let parts = PathComponents.of(name)+ return parts.count > 1 && parts[0] == inside+ }guard isAnApp || installerExtensions.contains(suffix) else { return nil }return (inside as NSString).deletingPathExtension}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swiftindex db11a064..35373b0e 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/InstallersTests.swift@@ -125,6 +125,17 @@ struct InstallersTests {#expect(ZipDirectory.names(at: text) == nil)}+ @Test func aCombiningMarkAfterASlashInAZipHidesNoFolder() throws {+ let directory = try TemporaryDirectory()+ let build = directory.url.appending(path: "Build", directoryHint: .isDirectory)+ try directory.file("Build/Example.app/\u{301}x", contents: randomData(count: 1_000))+ try run("/usr/bin/zip", ["-qr", "../example.zip", "Example.app"], in: build)+ let archive = directory.url.appending(path: "example.zip")++ #expect(ZipDirectory.names(at: archive)?.contains("Example.app/\u{301}x") == true)+ #expect(Installers.installerInside(zip: archive) == "Example")+ }+@Test func findsBigInstallersAndSaysWhichAppIsAlreadyInstalled() async throws {let directory = try TemporaryDirectory()try directory.file("Downloads/VisualStudioCode-1.99.0.dmg", bytes: 400_000)