Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Keep template cleanup under the installation lock
NotProtonNot734e4d56716a
diff --git a/app/Sources/NotProtonApp/SystemStatus.swift b/app/Sources/NotProtonApp/SystemStatus.swiftindex d593318..cd18e12 100644--- a/app/Sources/NotProtonApp/SystemStatus.swift+++ b/app/Sources/NotProtonApp/SystemStatus.swift@@ -588,16 +588,22 @@ final class SystemStatus {func refreshRunnerStorage(runners: URL = SupportPaths.runners, libraries: [SteamLibrary] = PrefixStore.libraries(),- cleanTemplates: Bool = true+ cleanTemplates: Bool = true,+ acquireInstallationLock: @escaping @Sendable () throws -> DeploymentContent.InstallationLock = {+ try DeploymentContent.acquireInstallationLock()+ }) async {let known = runnerSizeslet measured = await Task.detached(priority: .utility) {- if cleanTemplates, let lock = try? DeploymentContent.acquireInstallationLock() {+ let failures: [StepFailure]+ if cleanTemplates, let lock = try? acquireInstallationLock() {+ defer { lock.release() }RunnerInstaller.removeLeftoverRemovals(runners: runners)- lock.release()+ failures = RunnerInstaller.removeStalePrefixTemplates(+ runners: runners, libraries: libraries, reportBusy: false)+ } else {+ failures = []}- let failures = cleanTemplates- ? RunnerInstaller.removeStalePrefixTemplates(runners: runners, libraries: libraries, reportBusy: false) : []var sizes: [String: Int64] = [:]var templates: [String: [CompatTool.Flavor: Int64]] = [:]let bridgeCopies = libraries.reduce(Int64(0)) { total, library indiff --git a/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift b/app/Tests/NotProtonAppTests/TemplateCleanupTests.swiftindex 932c17e..d3d908f 100644--- a/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift+++ b/app/Tests/NotProtonAppTests/TemplateCleanupTests.swift@@ -293,6 +293,61 @@ struct TemplateCleanupTests {#expect(try #require(sizes[.rosetta]) < 2 << 20)}+ @MainActor+ @Test("Refresh keeps a reinstalling build's templates while the installation lock is held")+ func refreshDuringRunnerReplacement() async throws {+ let layout = try Layout()+ defer { try? FileManager.default.removeItem(at: layout.root) }+ let fm = FileManager.default+ let replacing = "27.0.0.41069-fex"+ let other = "27.0.0.41073-fex"+ for build in [replacing, other] {+ try fm.createDirectory(+ at: SupportPaths.clonedRoot(forBuild: build, runners: layout.runners).appending(path: "lib/wine"),+ withIntermediateDirectories: true)+ for template in SupportPaths.prefixTemplates(forBuild: build, in: layout.library) {+ try fm.createDirectory(at: template, withIntermediateDirectories: true)+ try Data(repeating: 7, count: 65536).write(to: template.appending(path: "system.reg"))+ }+ }+ let target = SupportPaths.runnerRoot(forBuild: replacing, runners: layout.runners)+ let staging = layout.runners.appending(path: ".crossover-\(replacing).new")+ let lock = try DeploymentContent.acquireInstallationLock(in: layout.root, steamFolder: nil)+ var held = true+ defer { if held { lock.release() } }+ try fm.moveItem(at: target, to: staging)+ let status = SystemStatus()++ await status.refreshRunnerStorage(runners: layout.runners, libraries: [layout.library],+ acquireInstallationLock: {+ try DeploymentContent.acquireInstallationLock(in: layout.root, steamFolder: nil)+ })++ #expect(status.templateCleanupFailure == nil)+ #expect(status.runnerSizes[other] != nil)+ for flavor in CompatTool.Flavor.allCases {+ #expect(fm.fileExists(atPath: SupportPaths.prefixTemplate(+ forBuild: replacing, flavor: flavor, in: layout.library).path))+ #expect(try #require(status.templateSizes[other]?[flavor]) >= 65536)+ }++ try fm.moveItem(at: staging, to: target)+ lock.release()+ held = false+ await status.refreshRunnerStorage(runners: layout.runners, libraries: [layout.library],+ acquireInstallationLock: {+ try DeploymentContent.acquireInstallationLock(in: layout.root, steamFolder: nil)+ })++ #expect(status.templateCleanupFailure == nil)+ #expect(!fm.fileExists(atPath: layout.template.path))+ for build in [replacing, other] {+ for flavor in CompatTool.Flavor.allCases {+ #expect(try #require(status.templateSizes[build]?[flavor]) >= 65536)+ }+ }+ }+@Test("The size line names each tool's templates only when a build has more than one tool")func sizeTextNamesTools() {func labels(_ templates: [CompatTool.Flavor: Int64], _ flavors: [CompatTool.Flavor]) -> [String] {