Skip to content

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

Windows links an installer makes are left to Wine: Highball no longer turns them into Mac symlinks, and removes the ones it made (highball-db#318). The EA app's repair stopped at "Failed to remove reparse point ... EA Desktop\EA Desktop: error=145" because Highball had put a Mac symlink beside Wine's stub for that link, and Wine took the symlink for an ordinary folder that was not empty. Measured 2026-10-08 in a scratch environment on the Wine 11 engines r4 and r21: for a junction (mklink /J) and for the EA installer's relative directory link (mklink /D 'EA Desktop' '13.1\EA Desktop') Wine reads, lists and starts programs through its own stub and removes it, while with the old Mac symlink beside it rmdir fails with 'Directory is not empty', exit 145. WineReparsePoint.follow finds the real file through the stubs without writing (Pin.executableURL uses it, so installed checks, Finder, the PE check and session markers see the client), a pin behind a link is started by its Windows path (Pin.launchURL), which Wine resolves itself (the program sees itself at C:\...\EA Desktop\EA Desktop\EADesktop.exe as on Windows, its working folder is the real one), and dematerialize removes only a symlink whose target is that of the stub beside it (or set aside), putting a set-aside stub back: before and after every installer step, along a pin's path before it starts, and for 'highball run' with a Windows path. The command-line run was checked end to end against an old-style symlink: removed, the program started through Wine's link, rmdir then worked. 508 tests pass. Not merged: the EA app itself (install, sign-in window, repair) still has to be checked, which needs the installer's LET'S GO click on an unlocked screen.

Gauthier Piarrettee3060a8b73eb
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index af821be..3286fdf 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -254,6 +254,16 @@ public struct Pin: Codable, Sendable, Identifiable, Hashable {
/// Where the pin's executable actually lives for a given bottle.
public func executableURL(driveC: URL) -> URL {
+ let named = launchURL(driveC: driveC)
+ // Behind a link a Windows installer made (the EA app's EA Desktop\EA Desktop) the file is
+ // only reachable through Wine's stub; on the Mac it sits at the link's target.
+ if FileManager.default.fileExists(atPath: named.path) { return named }
+ return WineReparsePoint.follow(named, driveC: driveC) ?? named
+ }
+
+ /// The path the pin names, links and all: what Wine is given, so the program finds itself where
+ /// a Windows shortcut would start it.
+ public func launchURL(driveC: URL) -> URL {
path.hasPrefix("/") ? URL(fileURLWithPath: path) : driveC.appending(path: path)
}
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swift
index 8399fc6..6f81ff6 100644
--- a/Sources/HighballKit/Recipe.swift
+++ b/Sources/HighballKit/Recipe.swift
@@ -464,6 +464,12 @@ public struct RecipeRunner: Sendable {
} else {
file = try await downloadUnverified(url)
}
+ // A Mac symlink an older Highball made beside a Windows link stops an installer that
+ // repairs or replaces the link (the EA app's repair: "Failed to remove reparse point",
+ // error 145, highball-db#318). Wine follows its own links, so they go.
+ for link in WineReparsePoint.dematerializeTree(under: bottle.driveC, driveC: bottle.driveC) {
+ log?("[\(recipe.id)] removed the Mac link beside \(link.lastPathComponent), Wine follows the Windows link itself")
+ }
let isMSI = file.pathExtension.lowercased() == "msi" || url.lastPathComponent.lowercased().contains(".msi")
let wineArgs = isMSI ? ["msiexec", "/i", file.path, "/qn"] + arguments : [file.path] + arguments
let before = Set(ProcessTable.processes(ofPrefix: bottle.url))
@@ -517,11 +523,6 @@ public struct RecipeRunner: Sendable {
if result.exitStatus != 0 {
log?("[\(recipe.id)] \(label) exited with \(result.exitStatus)\(WineRunner.exitCodeNote(for: result.exitStatus)) — treating as done")
}
- // Junctions the installer made (EA app: EA Desktop\EA Desktop → a versioned folder)
- // are stubs nothing follows until they are host symlinks.
- for link in WineReparsePoint.materializeTree(under: bottle.driveC, driveC: bottle.driveC) {
- log?("[\(recipe.id)] linked \(link.lastPathComponent) (a Windows junction the installer made, as a symlink)")
- }
case let .registry(key, name, type, data):
try await runner.regAdd(key: key, name: name, type: type, data: data)
case let .winetricks(verbs, _):
diff --git a/Sources/HighballKit/WineReparsePoint.swift b/Sources/HighballKit/WineReparsePoint.swift
index 80734ce..ffafd88 100644
--- a/Sources/HighballKit/WineReparsePoint.swift
+++ b/Sources/HighballKit/WineReparsePoint.swift
@@ -1,21 +1,26 @@
import Foundation
import Darwin
-/// Wine's on-disk form of an NTFS reparse point, and how to make it usable.
+/// Wine's on-disk form of an NTFS reparse point, and how Highball reads through it.
///
/// When a Windows installer creates a directory junction or symbolic link, this Wine
-/// (10+, CrossOver 26) leaves an empty directory named after the link plus a trailing `?`,
-/// with the raw REPARSE_DATA_BUFFER in the `user.WINEREPARSE` extended attribute. Nothing on
-/// the host follows that, and Wine itself did not resolve it either: the EA app's installer
-/// makes one for `EA Desktop\EA Desktop`, and the client behind it was "not there" both to
-/// Highball and to programs inside the bottle. A real host symlink is followed by both, so this
-/// turns such stubs into symlinks, after installs and on demand when a path is missing.
+/// (11, CrossOver 26) leaves an empty directory named after the link plus a trailing `?`,
+/// with the raw REPARSE_DATA_BUFFER in the `user.WINEREPARSE` extended attribute. Wine follows
+/// it itself: on the Wine 11 engines r4 and r21, a program reads and lists through the link,
+/// starts a program behind it and removes it (measured 2026-10-08 with `mklink /J` and with
+/// the EA app's relative `mklink /D` layout). Nothing on the Mac follows it, so Highball's own
+/// checks go through `follow`, which writes nothing.
+///
+/// Highball used to turn such stubs into Mac symlinks of the same name. Wine then took the
+/// symlink for an ordinary folder, and removing the link failed with "Directory is not empty"
+/// (error 145): the EA app's repair stopped at "Failed to remove reparse point ... error=145"
+/// (highball-db#318). `dematerialize` takes those symlinks away again.
public enum WineReparsePoint {
public static let attribute = "user.WINEREPARSE"
/// IO_REPARSE_TAG_SYMLINK and IO_REPARSE_TAG_MOUNT_POINT (a junction).
static let symlinkTag: UInt32 = 0xA000_000C
static let mountPointTag: UInt32 = 0xA000_0003
- /// Stubs whose name is taken by the link are moved aside under this prefix.
+ /// Where an older Highball moved a stub whose name its symlink took.
static let asidePrefix = ".wine-reparse-"
public struct Decoded: Equatable, Sendable {
@@ -63,11 +68,6 @@ public enum WineReparsePoint {
return decode(Data(buffer[0..<got]))
}
- /// `EA Desktop?` → `EA Desktop`. A stub without the marker keeps its name.
- public static func linkName(forStub name: String) -> String {
- name.hasSuffix("?") ? String(name.dropLast()) : name
- }
-
/// Where the target lives on the host: relative names hang off the stub's directory,
/// absolute ones go through the bottle's drives (C: is drive_c, Z: is the host root).
public static func hostTarget(_ decoded: Decoded, stubParent: URL, driveC: URL) -> URL? {
@@ -87,50 +87,97 @@ public enum WineReparsePoint {
}
}
- // MARK: Materialising
+ // MARK: Following
+
+ /// The Mac path `url` lands on when Wine resolves it, going through the stubs on the way
+ /// (a stub named after the component plus `?`, or one standing at the component's own name),
+ /// or nil when something along it is missing. Writes nothing. Walks from the bottle's drive_c
+ /// when `url` is inside it, so a path costs a few directory reads.
+ public static func follow(_ url: URL, driveC: URL) -> URL? {
+ let fm = FileManager.default
+ if fm.fileExists(atPath: url.path) { return url }
+ let path = url.standardizedFileURL.path
+ let base = driveC.standardizedFileURL.path
+ var current: URL
+ var remaining: ArraySlice<String>
+ if path == base || path.hasPrefix(base.hasSuffix("/") ? base : base + "/") {
+ current = driveC
+ remaining = String(path.dropFirst(base.count)).split(separator: "/").map(String.init)[...]
+ } else {
+ current = URL(fileURLWithPath: "/")
+ remaining = url.standardizedFileURL.pathComponents.dropFirst()[...]
+ }
+ for component in remaining {
+ let direct = current.appending(path: component)
+ if let decoded = read(at: direct), let target = hostTarget(decoded, stubParent: current, driveC: driveC),
+ fm.fileExists(atPath: target.path) {
+ current = target
+ } else if fm.fileExists(atPath: direct.path) {
+ current = direct
+ } else if let decoded = read(at: current.appending(path: component + "?")),
+ let target = hostTarget(decoded, stubParent: current, driveC: driveC), fm.fileExists(atPath: target.path) {
+ current = target
+ } else {
+ return nil
+ }
+ }
+ return current
+ }
+
+ /// The Windows path Wine knows a Mac path inside the bottle by: drive_c is C:, anything else
+ /// goes through Z:, the Mac's root.
+ public static func windowsPath(for url: URL, driveC: URL) -> String {
+ let path = url.standardizedFileURL.path
+ let base = driveC.standardizedFileURL.path
+ if path == base || path.hasPrefix(base.hasSuffix("/") ? base : base + "/") {
+ return "C:\\" + String(path.dropFirst(base.count)).split(separator: "/").joined(separator: "\\")
+ }
+ return "Z:" + path.replacingOccurrences(of: "/", with: "\\")
+ }
+
+ // MARK: Undoing the old symlinks
- /// Turns every reparse stub directly inside `dir` into a host symlink. Returns the links made.
- /// Skips stubs whose target is not there (a link to nothing helps nobody) and names that are
- /// already taken by something other than the stub itself.
+ /// Removes the Mac symlinks an older Highball made for stubs directly inside `dir`: a symlink
+ /// whose target is the target of the stub beside it (`name?`) or of the stub it set aside
+ /// (`.wine-reparse-name`, which goes back to its name). Any other symlink is left alone.
+ /// Returns the links removed.
@discardableResult
- public static func materialize(in dir: URL, driveC: URL) -> [URL] {
+ public static func dematerialize(in dir: URL, driveC: URL) -> [URL] {
let fm = FileManager.default
guard let names = try? fm.contentsOfDirectory(atPath: dir.path) else { return [] }
- var made: [URL] = []
- for name in names where !name.hasPrefix(asidePrefix) {
- let stub = dir.appending(path: name)
- guard let decoded = read(at: stub),
- let target = hostTarget(decoded, stubParent: dir, driveC: driveC),
- fm.fileExists(atPath: target.path) else { continue }
- let linkName = linkName(forStub: name)
- let link = dir.appending(path: linkName)
- if linkName == name {
- // The stub occupies the link's name: move the (empty) stub aside first.
- let aside = dir.appending(path: asidePrefix + name)
- try? fm.removeItem(at: aside)
- guard (try? fm.moveItem(at: stub, to: aside)) != nil else { continue }
- } else if (try? fm.attributesOfItem(atPath: link.path)) != nil {
- continue // something already has that name; lstat semantics, so a dangling link counts too
+ var removed: [URL] = []
+ for name in names where !name.hasPrefix(asidePrefix) && !name.hasSuffix("?") {
+ let link = dir.appending(path: name)
+ guard (try? fm.destinationOfSymbolicLink(atPath: link.path)) != nil else { continue }
+ let landing = link.resolvingSymlinksInPath().standardizedFileURL.path
+ func pointsHere(_ stub: URL) -> Bool {
+ guard let decoded = read(at: stub), let target = hostTarget(decoded, stubParent: dir, driveC: driveC) else { return false }
+ return target.resolvingSymlinksInPath().standardizedFileURL.path == landing
}
- let destination = decoded.isRelative
- ? decoded.target.replacingOccurrences(of: "\\", with: "/")
- : relativePath(from: dir, to: target)
- if (try? fm.createSymbolicLink(atPath: link.path, withDestinationPath: destination)) != nil {
- made.append(link)
+ let marked = dir.appending(path: name + "?")
+ let aside = dir.appending(path: asidePrefix + name)
+ if pointsHere(marked) {
+ guard (try? fm.removeItem(at: link)) != nil else { continue }
+ } else if pointsHere(aside) {
+ guard (try? fm.removeItem(at: link)) != nil else { continue }
+ try? fm.moveItem(at: aside, to: link)
+ } else {
+ continue
}
+ removed.append(link)
}
- return made
+ return removed
}
- /// Materialises stubs anywhere under `root`, directories only, to a bounded depth: installers
- /// put their links a few levels under Program Files, and game trees below that are huge.
- /// `windows/` at the root is skipped.
+ /// `dematerialize` anywhere under `root`, directories only, to a bounded depth: installers put
+ /// their links a few levels under Program Files, and game trees below that are huge.
+ /// `windows/` at the root is skipped, and symlinked folders are not entered.
@discardableResult
- public static func materializeTree(under root: URL, driveC: URL, maxDepth: Int = 6) -> [URL] {
+ public static func dematerializeTree(under root: URL, driveC: URL, maxDepth: Int = 6) -> [URL] {
let fm = FileManager.default
- var made: [URL] = []
+ var removed: [URL] = []
func walk(_ dir: URL, depth: Int) {
- made += materialize(in: dir, driveC: driveC)
+ removed += dematerialize(in: dir, driveC: driveC)
guard depth < maxDepth,
let entries = try? fm.contentsOfDirectory(at: dir, includingPropertiesForKeys: [.isDirectoryKey, .isSymbolicLinkKey],
options: [.skipsHiddenFiles]) else { return }
@@ -142,47 +189,22 @@ public enum WineReparsePoint {
}
}
walk(root, depth: 0)
- return made
+ return removed
}
- /// `url` if it exists, else the same path after materialising the stubs that stood in its way,
- /// or nil when something is still missing. Walks from the bottle's drive_c when the path is
- /// inside it, so a missing pin costs a few directory reads and nothing more.
- public static func resolve(_ url: URL, driveC: URL) -> URL? {
- let fm = FileManager.default
- if fm.fileExists(atPath: url.path) { return url }
+ /// `dematerialize` in each folder along `url` inside drive_c, which is all a launch needs.
+ @discardableResult
+ public static func dematerializeAlong(_ url: URL, driveC: URL) -> [URL] {
let path = url.standardizedFileURL.path
let base = driveC.standardizedFileURL.path
- var current: URL
- var remaining: ArraySlice<String>
- if path == base || path.hasPrefix(base.hasSuffix("/") ? base : base + "/") {
- current = driveC
- remaining = String(path.dropFirst(base.count)).split(separator: "/").map(String.init)[...]
- } else {
- current = URL(fileURLWithPath: "/")
- remaining = url.standardizedFileURL.pathComponents.dropFirst()[...]
+ guard path.hasPrefix(base.hasSuffix("/") ? base : base + "/") else { return [] }
+ var current = driveC
+ var removed: [URL] = []
+ for component in String(path.dropFirst(base.count)).split(separator: "/").map(String.init).dropLast() {
+ removed += dematerialize(in: current, driveC: driveC)
+ current = current.appending(path: component)
}
- for component in remaining {
- let next = current.appending(path: component)
- if !fm.fileExists(atPath: next.path) {
- materialize(in: current, driveC: driveC)
- guard fm.fileExists(atPath: next.path) else { return nil }
- }
- current = next
- }
- return current
- }
-
- /// A relative symlink destination from `dir` to `target` (`../13.783.0.6296/EA Desktop`),
- /// so the link survives the bottle being moved or renamed.
- static func relativePath(from dir: URL, to target: URL) -> String {
- let from = dir.standardizedFileURL.pathComponents
- let to = target.standardizedFileURL.pathComponents
- var common = 0
- while common < from.count, common < to.count, from[common] == to[common] { common += 1 }
- let ups = Array(repeating: "..", count: from.count - common)
- let rest = Array(to[common...])
- let parts = ups + rest
- return parts.isEmpty ? "." : parts.joined(separator: "/")
+ removed += dematerialize(in: current, driveC: driveC)
+ return removed
}
}
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index f23d527..90585d3 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -283,7 +283,9 @@ public struct WineRunner: Sendable {
/// Runs the executable directly under `wine` (not `start /unix`) so the process stays attached and
/// everything it and its children print lands in the log. The call returns when the program exits.
@discardableResult
- public func start(_ executable: URL, arguments: [String] = [], renderer: Renderer? = nil, extraEnvironment: [String: String] = [:], workingDirectory: URL? = nil, headerNote: String? = nil, onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
+ /// `program` replaces the executable's Mac path on Wine's command line (a Windows path through
+ /// a link the Mac does not see), while `executable` still names the log and the checks.
+ public func start(_ executable: URL, arguments: [String] = [], renderer: Renderer? = nil, extraEnvironment: [String: String] = [:], workingDirectory: URL? = nil, headerNote: String? = nil, program: String? = nil, onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
await syncMacFontSubstitutes()
await syncDllOverridesRegistry()
await syncEngineAppDefaults()
@@ -313,7 +315,7 @@ public struct WineRunner: Sendable {
onOutput?("note: \(rebooted)")
note = [note, rebooted].compactMap { $0 }.joined(separator: "; ")
}
- return try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, headerNote: note, onOutput: onOutput)
+ return try await run([program ?? executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, headerNote: note, onOutput: onOutput)
}
/// Restarts the environment's Wine server before a program launch when the server, and so
@@ -349,10 +351,12 @@ public struct WineRunner: Sendable {
/// Runs the pinned program, honouring its own renderer/env/args.
@discardableResult
public func start(pin: Pin, extraEnvironment: [String: String] = [:], onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
- // A path behind a Windows junction the installer made (EA app) exists only once the
- // junction stub is turned into a host symlink; do that before judging it missing.
- let exe = WineReparsePoint.resolve(pin.executableURL(driveC: bottle.driveC), driveC: bottle.driveC)
- ?? pin.executableURL(driveC: bottle.driveC)
+ // A program behind a link a Windows installer made (the EA app) is found through Wine's
+ // stub. A Mac symlink an older Highball made beside the stub goes first: Wine took it for a
+ // folder and could not remove the link, which stopped the EA app's repair (highball-db#318).
+ let named = pin.launchURL(driveC: bottle.driveC)
+ WineReparsePoint.dematerializeAlong(named, driveC: bottle.driveC)
+ let exe = pin.executableURL(driveC: bottle.driveC)
// A pin whose target no longer exists otherwise dies deep in Wine with an opaque
// c0000135 ("failed to open"). Catch it here with a message the user can act on.
// Pins written before 0.7.6 stored only a filename, so old entries resolve to a
@@ -370,8 +374,11 @@ public struct WineRunner: Sendable {
renderer = nil
}
// cwd = the exe's folder, as a Windows shortcut would — games with relative asset paths need it.
+ // Wine gets the path through the link by its Windows name, since that path has no Mac side.
+ let throughLink = exe.standardizedFileURL.path != named.standardizedFileURL.path
return try await start(exe, arguments: pin.arguments, renderer: renderer, extraEnvironment: env,
- workingDirectory: exe.deletingLastPathComponent(), onOutput: onOutput)
+ workingDirectory: exe.deletingLastPathComponent(),
+ program: throughLink ? WineReparsePoint.windowsPath(for: named, driveC: bottle.driveC) : nil, onOutput: onOutput)
}
/// Steam's first self-update sometimes dies at a known Wine WoW64 spot and resumes cleanly
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 98d8de0..e0390b1 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -442,9 +442,12 @@ struct Run: AsyncParsableCommand {
result = try await runner.start(pin: p, onOutput: out)
}
} else if program.contains(":") || program.contains("\\") {
- let exe = WineReparsePoint.resolve(b.resolve(windowsPath: program), driveC: b.driveC) ?? b.resolve(windowsPath: program)
+ let named = b.resolve(windowsPath: program)
+ WineReparsePoint.dematerializeAlong(named, driveC: b.driveC)
+ let exe = WineReparsePoint.follow(named, driveC: b.driveC) ?? named
result = try await runner.start(exe, arguments: arguments, renderer: renderer, extraEnvironment: scoped,
- workingDirectory: exe.deletingLastPathComponent(), onOutput: out)
+ workingDirectory: exe.deletingLastPathComponent(),
+ program: exe.standardizedFileURL.path == named.standardizedFileURL.path ? nil : program, onOutput: out)
} else if FileManager.default.fileExists(atPath: program) {
let exe = URL(fileURLWithPath: program)
result = try await runner.start(exe, arguments: arguments, renderer: renderer,
diff --git a/Tests/HighballKitTests/WineReparsePointTests.swift b/Tests/HighballKitTests/WineReparsePointTests.swift
index 3258341..76a0d0d 100644
--- a/Tests/HighballKitTests/WineReparsePointTests.swift
+++ b/Tests/HighballKitTests/WineReparsePointTests.swift
@@ -88,78 +88,101 @@ final class WineReparsePointTests: XCTestCase {
let z = WineReparsePoint.hostTarget(.init(tag: 0, target: "Z:\\Users\\me\\x", isRelative: false), stubParent: parent, driveC: driveC)
XCTAssertEqual(z?.path, "/Users/me/x")
XCTAssertNil(WineReparsePoint.hostTarget(.init(tag: 0, target: "D:\\x", isRelative: false), stubParent: parent, driveC: driveC), "no such drive in a bottle")
- XCTAssertEqual(WineReparsePoint.linkName(forStub: "EA Desktop?"), "EA Desktop")
- XCTAssertEqual(WineReparsePoint.linkName(forStub: "plain"), "plain")
}
- // MARK: Materialising
+ // MARK: Following
- func testStubBecomesARelativeHostSymlinkTheClientIsReachableThrough() throws {
+ func testFollowReachesTheClientThroughTheStubAndWritesNothing() throws {
let driveC = root.appending(path: "drive_c")
- let (dir, _) = try makeEAInstall(under: driveC)
- let made = WineReparsePoint.materialize(in: dir, driveC: driveC)
- XCTAssertEqual(made.map(\.lastPathComponent), ["EA Desktop"])
- let link = dir.appending(path: "EA Desktop")
- XCTAssertEqual(try FileManager.default.destinationOfSymbolicLink(atPath: link.path), "13.783.0.6296/EA Desktop", "relative, so a moved bottle keeps working")
- XCTAssertTrue(FileManager.default.fileExists(atPath: link.appending(path: "EADesktop.exe").path))
- XCTAssertTrue(FileManager.default.fileExists(atPath: dir.appending(path: "EA Desktop?").path), "the stub is left for Wine")
- XCTAssertEqual(WineReparsePoint.materialize(in: dir, driveC: driveC), [], "second pass: nothing left to do")
+ let (dir, exe) = try makeEAInstall(under: driveC)
+ let named = dir.appending(path: "EA Desktop/EADesktop.exe")
+ XCTAssertEqual(WineReparsePoint.follow(named, driveC: driveC)?.path, exe.standardizedFileURL.path)
+ XCTAssertNil(try? FileManager.default.attributesOfItem(atPath: dir.appending(path: "EA Desktop").path), "no Mac link is made")
+ XCTAssertNotNil(WineReparsePoint.read(at: dir.appending(path: "EA Desktop?")), "the stub stays for Wine")
+ XCTAssertNil(WineReparsePoint.follow(dir.appending(path: "EA Desktop/Missing.exe"), driveC: driveC))
+ XCTAssertNil(WineReparsePoint.follow(root.appending(path: "outside/nothing"), driveC: driveC))
}
- func testStubWithoutTheMarkerIsMovedAsideForTheLink() throws {
+ func testFollowGoesThroughAStubWithoutTheMarkerAndAnAbsoluteJunction() throws {
let driveC = root.appending(path: "drive_c")
- let (dir, _) = try makeEAInstall(under: driveC, stubName: "EA Desktop")
- XCTAssertEqual(WineReparsePoint.materialize(in: dir, driveC: driveC).map(\.lastPathComponent), ["EA Desktop"])
- XCTAssertTrue(FileManager.default.fileExists(atPath: dir.appending(path: "EA Desktop/EADesktop.exe").path))
- XCTAssertNotNil(WineReparsePoint.read(at: dir.appending(path: ".wine-reparse-EA Desktop")), "the stub survives, aside")
+ let (dir, exe) = try makeEAInstall(under: driveC, stubName: "EA Desktop")
+ XCTAssertEqual(WineReparsePoint.follow(dir.appending(path: "EA Desktop/EADesktop.exe"), driveC: driveC)?.path, exe.standardizedFileURL.path)
+ let vendor = driveC.appending(path: "Program Files/Vendor")
+ try FileManager.default.createDirectory(at: driveC.appending(path: "ProgramData/Vendor/1.0"), withIntermediateDirectories: true)
+ try Data("x".utf8).write(to: driveC.appending(path: "ProgramData/Vendor/1.0/app.exe"))
+ try FileManager.default.createDirectory(at: vendor, withIntermediateDirectories: true)
+ try makeStub(in: vendor, name: "Current?", data: Self.blob(tag: 0xA000_0003, substitute: "\\??\\C:\\ProgramData\\Vendor\\1.0", relative: false))
+ XCTAssertEqual(WineReparsePoint.follow(vendor.appending(path: "Current/app.exe"), driveC: driveC)?.path,
+ driveC.appending(path: "ProgramData/Vendor/1.0/app.exe").standardizedFileURL.path)
+ try makeStub(in: vendor, name: "Nowhere?", data: Self.blob(tag: 0xA000_000C, substitute: "no\\such", relative: true))
+ XCTAssertNil(WineReparsePoint.follow(vendor.appending(path: "Nowhere/app.exe"), driveC: driveC))
}
- func testStubToNothingAndTakenNamesAreLeftAlone() throws {
+ func testWindowsPaths() {
let driveC = root.appending(path: "drive_c")
- let dir = driveC.appending(path: "Program Files/Vendor")
- try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
- try makeStub(in: dir, name: "Gone?", data: Self.blob(tag: 0xA000_000C, substitute: "9.9\\Gone", relative: true))
- try makeStub(in: dir, name: "Taken?", data: Self.blob(tag: 0xA000_000C, substitute: "9.9\\Gone", relative: true))
- try FileManager.default.createDirectory(at: dir.appending(path: "9.9/Gone"), withIntermediateDirectories: true)
- try Data().write(to: dir.appending(path: "Taken"))
- try makeStub(in: dir, name: "Nowhere?", data: Self.blob(tag: 0xA000_000C, substitute: "no\\such", relative: true))
- let made = WineReparsePoint.materialize(in: dir, driveC: driveC)
- XCTAssertEqual(made.map(\.lastPathComponent), ["Gone"])
- XCTAssertEqual(try Data(contentsOf: dir.appending(path: "Taken")), Data(), "an existing file is never replaced")
- XCTAssertNil(try? FileManager.default.destinationOfSymbolicLink(atPath: dir.appending(path: "Nowhere").path))
- }
-
- func testAbsoluteJunctionGetsARelativeLink() throws {
+ XCTAssertEqual(WineReparsePoint.windowsPath(for: driveC.appending(path: "Program Files/Electronic Arts/EA Desktop/EA Desktop/EADesktop.exe"), driveC: driveC),
+ "C:\\Program Files\\Electronic Arts\\EA Desktop\\EA Desktop\\EADesktop.exe")
+ XCTAssertEqual(WineReparsePoint.windowsPath(for: URL(fileURLWithPath: "/Volumes/Games/x.exe"), driveC: driveC), "Z:\\Volumes\\Games\\x.exe")
+ }
+
+ func testAPinBehindALinkIsFoundOnTheMacAndLaunchedByItsOwnPath() throws {
let driveC = root.appending(path: "drive_c")
- let dir = driveC.appending(path: "Program Files/Vendor")
- try FileManager.default.createDirectory(at: driveC.appending(path: "ProgramData/Vendor/1.0"), withIntermediateDirectories: true)
- try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
- try makeStub(in: dir, name: "Current?", data: Self.blob(tag: 0xA000_0003, substitute: "\\??\\C:\\ProgramData\\Vendor\\1.0", relative: false))
- XCTAssertEqual(WineReparsePoint.materialize(in: dir, driveC: driveC).count, 1)
- XCTAssertEqual(try FileManager.default.destinationOfSymbolicLink(atPath: dir.appending(path: "Current").path), "../../ProgramData/Vendor/1.0")
+ let (_, exe) = try makeEAInstall(under: driveC)
+ let pin = Pin(name: "EA app", path: "Program Files/Electronic Arts/EA Desktop/EA Desktop/EADesktop.exe")
+ XCTAssertEqual(pin.executableURL(driveC: driveC).path, exe.standardizedFileURL.path, "checks, Finder and the PE read see the real file")
+ XCTAssertEqual(pin.launchURL(driveC: driveC).path, driveC.appending(path: pin.path).path, "Wine gets the path through the link")
+ let plain = Pin(name: "Notepad", path: "windows/notepad.exe")
+ XCTAssertEqual(plain.executableURL(driveC: driveC), plain.launchURL(driveC: driveC), "an ordinary pin is unchanged")
+ }
+
+ // MARK: Undoing the old symlinks
+
+ /// What an older Highball left: a relative Mac symlink at the link's name, beside the stub.
+ func makeOldLink(in dir: URL, name: String = "EA Desktop", to destination: String = "13.783.0.6296/EA Desktop") throws {
+ try FileManager.default.createSymbolicLink(atPath: dir.appending(path: name).path, withDestinationPath: destination)
+ }
+
+ func testDematerializeRemovesTheOldLinkAndNothingElse() throws {
+ let driveC = root.appending(path: "drive_c")
+ let (dir, exe) = try makeEAInstall(under: driveC)
+ try makeOldLink(in: dir)
+ try FileManager.default.createSymbolicLink(atPath: dir.appending(path: "Shortcut").path, withDestinationPath: "13.783.0.6296/EA Desktop")
+ try makeStub(in: dir, name: "Other?", data: Self.blob(tag: 0xA000_000C, substitute: "13.783.0.6296", relative: true))
+ try makeOldLink(in: dir, name: "Other", to: "13.783.0.6296/EA Desktop")
+ let removed = WineReparsePoint.dematerialize(in: dir, driveC: driveC)
+ XCTAssertEqual(removed.map(\.lastPathComponent), ["EA Desktop"])
+ XCTAssertNotNil(try? FileManager.default.destinationOfSymbolicLink(atPath: dir.appending(path: "Shortcut").path), "a symlink with no stub beside it stays")
+ XCTAssertNotNil(try? FileManager.default.destinationOfSymbolicLink(atPath: dir.appending(path: "Other").path), "a symlink pointing elsewhere than its stub stays")
+ XCTAssertNotNil(WineReparsePoint.read(at: dir.appending(path: "EA Desktop?")))
+ XCTAssertTrue(FileManager.default.fileExists(atPath: exe.path), "the files behind the link are untouched")
+ XCTAssertEqual(WineReparsePoint.dematerialize(in: dir, driveC: driveC), [], "second pass: nothing left")
}
- func testResolveMaterialisesWhatStandsInThePathsWay() throws {
+ func testDematerializePutsAStubSetAsideBack() throws {
let driveC = root.appending(path: "drive_c")
- let (dir, _) = try makeEAInstall(under: driveC)
- let pinned = dir.appending(path: "EA Desktop/EADesktop.exe")
- XCTAssertFalse(FileManager.default.fileExists(atPath: pinned.path))
- XCTAssertEqual(WineReparsePoint.resolve(pinned, driveC: driveC)?.path, pinned.path)
- XCTAssertTrue(FileManager.default.fileExists(atPath: pinned.path))
- XCTAssertNil(WineReparsePoint.resolve(dir.appending(path: "EA Desktop/Missing.exe"), driveC: driveC))
- XCTAssertNil(WineReparsePoint.resolve(root.appending(path: "outside/nothing"), driveC: driveC))
+ let (dir, _) = try makeEAInstall(under: driveC, stubName: ".wine-reparse-EA Desktop")
+ try makeOldLink(in: dir)
+ XCTAssertEqual(WineReparsePoint.dematerialize(in: dir, driveC: driveC).map(\.lastPathComponent), ["EA Desktop"])
+ XCTAssertNil(try? FileManager.default.destinationOfSymbolicLink(atPath: dir.appending(path: "EA Desktop").path))
+ XCTAssertNotNil(WineReparsePoint.read(at: dir.appending(path: "EA Desktop")), "the stub is back at its own name")
+ XCTAssertNil(try? FileManager.default.attributesOfItem(atPath: dir.appending(path: ".wine-reparse-EA Desktop").path))
}
- func testTreeWalkFindsStubsAFewLevelsDownAndStopsAtTheDepthCap() throws {
+ func testDematerializeAlongAPathAndThroughATree() throws {
let driveC = root.appending(path: "drive_c")
- let (dir, _) = try makeEAInstall(under: driveC)
+ let (dir, exe) = try makeEAInstall(under: driveC)
+ try makeOldLink(in: dir)
+ let named = dir.appending(path: "EA Desktop/EADesktop.exe")
+ XCTAssertEqual(WineReparsePoint.dematerializeAlong(named, driveC: driveC).map(\.lastPathComponent), ["EA Desktop"])
+ XCTAssertEqual(WineReparsePoint.follow(named, driveC: driveC)?.path, exe.standardizedFileURL.path, "still reachable through the stub")
+ try makeOldLink(in: dir)
try FileManager.default.createDirectory(at: driveC.appending(path: "windows/system32"), withIntermediateDirectories: true)
let deep = driveC.appending(path: "a/b/c/d/e/f/g/h")
try FileManager.default.createDirectory(at: deep.appending(path: "1.0/X"), withIntermediateDirectories: true)
try makeStub(in: deep, name: "X?", data: Self.blob(tag: 0xA000_000C, substitute: "1.0\\X", relative: true))
- let made = WineReparsePoint.materializeTree(under: driveC, driveC: driveC)
- XCTAssertEqual(made.map(\.lastPathComponent), ["EA Desktop"], "depth 3 is found, depth 8 is beyond the cap")
- XCTAssertTrue(FileManager.default.fileExists(atPath: dir.appending(path: "EA Desktop/EADesktop.exe").path))
- XCTAssertEqual(WineReparsePoint.materializeTree(under: driveC, driveC: driveC, maxDepth: 10).map(\.lastPathComponent), ["X"])
+ try makeOldLink(in: deep, name: "X", to: "1.0/X")
+ XCTAssertEqual(WineReparsePoint.dematerializeTree(under: driveC, driveC: driveC).map(\.lastPathComponent), ["EA Desktop"],
+ "depth 3 is found, depth 8 is beyond the cap")
+ XCTAssertEqual(WineReparsePoint.dematerializeTree(under: driveC, driveC: driveC, maxDepth: 10).map(\.lastPathComponent), ["X"])
}
}