Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(runner): don't replace a runner a game is using

kevicebryan355cbe327824
diff --git a/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift b/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift
index b4561f6..cfde42c 100644
--- a/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift
+++ b/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift
@@ -10,7 +10,8 @@ enum RunnerInstaller {
static func clone(
from install: CrossOverInstall,
replacingExisting: Bool = false,
- runners: URL = SupportPaths.runners
+ runners: URL = SupportPaths.runners,
+ running: (URL) -> Bool = { RunnerInstaller.isRunning(from: $0) }
) throws -> RunnerBuild {
guard case .supported(let build) = install.support else {
throw StepFailure(
@@ -32,10 +33,28 @@ enum RunnerInstaller {
defer { try? fm.removeItem(at: staging) }
try copyPayload(from: install.crossOverRoot, to: staging)
try verifyClone(build: build, root: staging.appending(path: "CrossOver"))
- if occupied {
- try fm.removeItem(at: target)
+ guard occupied else {
+ try fm.moveItem(at: staging, to: target)
+ return build
+ }
+ // Callers check for a running game before the engine download, which can take
+ // minutes, so a game started since then is caught here.
+ guard !running(target) else {
+ throw StepFailure(
+ step: step,
+ detail: String(localized: "A game or Wine tool is still running on build \(build.id). Quit it first.")
+ )
+ }
+ let old = target.deletingLastPathComponent().appending(path: ".\(target.lastPathComponent).removing")
+ try? fm.removeItem(at: old)
+ try fm.moveItem(at: target, to: old)
+ do {
+ try fm.moveItem(at: staging, to: target)
+ } catch {
+ try? fm.moveItem(at: old, to: target)
+ throw error
}
- try fm.moveItem(at: staging, to: target)
+ try? fm.removeItem(at: old)
return build
}
diff --git a/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift b/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift
index 3b2d119..a167188 100644
--- a/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift
+++ b/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift
@@ -227,6 +227,44 @@ struct RunnerInstallerTests {
runners.appending(path: ".crossover-\(build.id).new").path(percentEncoded: false)))
}
+ @Test("A runner a game is using is not replaced")
+ func runningRunnerIsNotReplaced() throws {
+ let runners = try makeRunners()
+ defer { try? FileManager.default.removeItem(at: runners) }
+ let (install, build) = try makeSupportedInstall(in: runners)
+ _ = try RunnerInstaller.clone(from: install, runners: runners)
+ let installed = SupportPaths.clonedRoot(forBuild: build.id, runners: runners)
+ let marker = installed.appending(path: "in-use")
+ try Data().write(to: marker)
+
+ let failure = #expect(throws: StepFailure.self) {
+ try RunnerInstaller.clone(from: install, replacingExisting: true, runners: runners, running: { _ in true })
+ }
+ #expect(failure?.detail.contains("still running") == true)
+ #expect(FileManager.default.fileExists(atPath: marker.path(percentEncoded: false)))
+ for leftover in [".new", ".removing"] {
+ #expect(!FileManager.default.fileExists(atPath:
+ runners.appending(path: ".crossover-\(build.id)\(leftover)").path(percentEncoded: false)))
+ }
+ }
+
+ @Test("An idle runner is replaced and the old copy removed")
+ func idleRunnerIsReplaced() throws {
+ let runners = try makeRunners()
+ defer { try? FileManager.default.removeItem(at: runners) }
+ let (install, build) = try makeSupportedInstall(in: runners)
+ _ = try RunnerInstaller.clone(from: install, runners: runners)
+ let installed = SupportPaths.clonedRoot(forBuild: build.id, runners: runners)
+ let marker = installed.appending(path: "old-copy")
+ try Data().write(to: marker)
+
+ _ = try RunnerInstaller.clone(from: install, replacingExisting: true, runners: runners, running: { _ in false })
+ #expect(!FileManager.default.fileExists(atPath: marker.path(percentEncoded: false)))
+ try RunnerInstaller.verifyClone(build: build, root: installed)
+ #expect(!FileManager.default.fileExists(atPath:
+ runners.appending(path: ".crossover-\(build.id).removing").path(percentEncoded: false)))
+ }
+
@Test("A rejected first copy is not left installed")
func rejectedFirstCopyIsNotInstalled() throws {
let runners = try makeRunners()