Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

Bottles: remove the last path-based remover, and stop hiding linked bottles (#38)

Gauthier Piarrette90abd7fc54a2
diff --git a/Sources/HighballKit/BottleStore.swift b/Sources/HighballKit/BottleStore.swift
index e343c65..dcf2793 100644
--- a/Sources/HighballKit/BottleStore.swift
+++ b/Sources/HighballKit/BottleStore.swift
@@ -8,17 +8,18 @@ public struct BottleStore: Sendable {
guard FileManager.default.fileExists(atPath: paths.bottles.path) else { return [] }
return try FileManager.default.contentsOfDirectory(at: paths.bottles, includingPropertiesForKeys: nil)
.compactMap { url -> Bottle? in
- // Real directories only. Listing used to reconcile the name of a symlinked entry
- // by writing bottle.json through the link, mutating a file outside bottles/.
- var st = stat()
- guard lstat(url.path, &st) == 0, (st.st_mode & S_IFMT) == S_IFDIR else { return nil }
guard var b = try? Bottle.load(url) else { return nil }
// The folder is the bottle's identity (get/delete resolve by folder). A copied
// folder keeps the old internal name, which crashed the app and confused lookups
// (issue #13) — reconcile so "play copy" is simply a bottle called "play copy".
if b.settings.name != url.lastPathComponent {
b.settings.name = url.lastPathComponent
- try? b.save()
+ // Reconcile in memory always, but persist only into a real directory: saving
+ // through a symlinked entry rewrites a bottle.json outside bottles/ as a side
+ // effect of merely listing. Skipping such entries entirely would be worse —
+ // a bottle deliberately linked to another disk would vanish from the list.
+ var st = stat()
+ if lstat(url.path, &st) == 0, (st.st_mode & S_IFMT) == S_IFDIR { try? b.save() }
}
return b
}
diff --git a/Sources/HighballKit/Purge.swift b/Sources/HighballKit/Purge.swift
index 97ea046..7aab854 100644
--- a/Sources/HighballKit/Purge.swift
+++ b/Sources/HighballKit/Purge.swift
@@ -79,16 +79,13 @@ public enum Purge {
remove(in: parent, named: name, at: url.path, &failures)
close(parent)
- // Last resort for whatever the walk could not finish — a depth past even the raised
- // file limit, most realistically. rm walks with fts, which recycles descriptors and does
- // not follow symlinks, so it is safe to point at a tree already isolated inside .trash.
- if !failures.isEmpty {
- var probe = stat()
- if lstat(url.path, &probe) == 0 {
- _ = run("/bin/rm", ["-rf", url.path])
- if lstat(url.path, &probe) != 0 { return [] }
- }
- }
+ // Deliberately no `rm -rf` last resort either. It was added here as belt and braces for a
+ // depth past the raised file limit, with a comment asserting rm does not follow symlinks.
+ // That is true of its traversal and false of the path it is handed: measured, it followed
+ // a swap out of the tree in 22 of 40 rounds — a bigger hole than the removeItem fast path
+ // it sat next to, and it fired precisely when the walk had reported failures, which is
+ // exactly when something is still fighting the delete. raiseFileLimit covers the depth
+ // case; anything the walk genuinely cannot remove is reported rather than forced.
// Never report an all-clear we have not verified. A silently stranded prefix is how the
// original bug hid: the caller believed the delete had finished.