Skip to content

Commit

Permalink
Fix sporadic errors when Tuist tries to preserve the SPM lockfile acr…
Browse files Browse the repository at this point in the history
…oss project generations (tuist#6394)

* package-race-cond

* Some fixes

* Fix tests
  • Loading branch information
pepicrft authored Jun 12, 2024
1 parent 2fd3481 commit 72e7657
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Sources/TuistGenerator/Utils/SwiftPackageManagerInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ public class SwiftPackageManagerInteractor: SwiftPackageManagerInteracting {
.appending(try RelativePath(validating: "\(workspaceName)/xcshareddata/swiftpm"))
let workspacePackageResolvedPath = workspacePackageResolvedFolderPath.appending(component: "Package.resolved")

if fileHandler.exists(rootPackageResolvedPath) {
try fileHandler.createFolder(workspacePackageResolvedFolderPath)
if fileHandler.exists(workspacePackageResolvedPath) {
try fileHandler.delete(workspacePackageResolvedPath)
if fileHandler.exists(rootPackageResolvedPath), !fileHandler.exists(workspacePackageResolvedPath) {
if !fileHandler.exists(workspacePackageResolvedPath.parentDirectory) {
try fileHandler.createFolder(workspacePackageResolvedPath.parentDirectory)
}
try fileHandler.copy(from: rootPackageResolvedPath, to: workspacePackageResolvedPath)
try fileHandler.linkFile(atPath: rootPackageResolvedPath, toPath: workspacePackageResolvedPath)
}

let workspacePath = path.appending(component: workspaceName)
Expand Down Expand Up @@ -98,10 +97,11 @@ public class SwiftPackageManagerInteractor: SwiftPackageManagerInteracting {
})
)

if fileHandler.exists(rootPackageResolvedPath) {
try fileHandler.delete(rootPackageResolvedPath)
if !fileHandler.exists(rootPackageResolvedPath), fileHandler.exists(workspacePackageResolvedPath) {
try fileHandler.copy(from: workspacePackageResolvedPath, to: rootPackageResolvedPath)
if !fileHandler.exists(workspacePackageResolvedPath) {
try fileHandler.linkFile(atPath: rootPackageResolvedPath, toPath: workspacePackageResolvedPath)
}
}

try fileHandler.linkFile(atPath: workspacePackageResolvedPath, toPath: rootPackageResolvedPath)
}
}

0 comments on commit 72e7657

Please sign in to comment.