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.

A leftover whose name starts with a combining mark keeps it

Țugui Dragoș4fdf47fa7e05
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index 7464352f..57c77b67 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -135,18 +135,20 @@ public struct Uninstallation: Sendable {
/// location, the kind is `.elsewhere`.
static func place(of url: URL, in environment: SearchEnvironment) -> (kind: SearchLocation.Kind, components: [String]) {
let path = PathPattern.comparablePath(of: url)
+ let names = PathComponents.of(path)
let inside = environment.locations
.map { (kind: $0.kind, root: PathPattern.comparablePath(of: $0.url)) }
.filter { PathComponents.isPath(path, inside: $0.root) }
+ .map { (kind: $0.kind, root: $0.root, below: Array(names.dropFirst(PathComponents.of($0.root).count))) }
// Two locations can share a root, like the hidden and plain halves of the home folder. The one that
// considers this name is the one that would have found it.
.filter { location in
- guard let first = PathComponents.of(path.dropFirst(location.root.count + 1)).first else { return false }
+ guard let first = location.below.first else { return false }
return location.kind.considers(fileName: first)
}
.max { $0.root.count < $1.root.count }
guard let inside else { return (.elsewhere, [url.lastPathComponent]) }
- let components = PathComponents.of(path.dropFirst(inside.root.count + 1))
+ let components = inside.below
// The home folder is a location only for what sits directly in it; below that is the user's own.
guard inside.root != PathPattern.comparablePath(of: environment.homeDirectory) || components.count == 1 else {
return (.elsewhere, [url.lastPathComponent])
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
index 03b54cbf..48a14e0e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
@@ -384,6 +384,20 @@ struct UninstallationTests {
#expect(place("/Users/me/Library/Thunderbird/profile") == .library)
}
+ /// A name that starts with a combining mark is read whole: split by Swift's characters, the slash before it
+ /// and the mark are one, and the mark would be lost.
+ @Test func readsANameThatStartsWithACombiningMarkWhole() {
+ let home = URL(filePath: "/Users/me", directoryHint: .isDirectory)
+ let root = URL(filePath: "/", directoryHint: .isDirectory)
+ let environment = SearchEnvironment(homeDirectory: home, rootDirectory: root)
+ let caches = PathPattern.comparablePath(of: home.appending(path: "Library/Caches"))
+
+ let place = Uninstallation.place(of: URL(filePath: caches + "/\u{301}Foo/cache.db"), in: environment)
+
+ #expect(place.kind == .caches)
+ #expect(place.components == ["\u{301}Foo", "cache.db"])
+ }
+
@Test func movesLeftoversBeforeTheApp() {
let first = leftover("first")
let second = leftover("second")