Add lock to ensure only one Swiftly process is running at any point
Running two swiftly processes at the same produces undefined results. We should add a file lock to ensure only one swiftly process is touching the swiftly folder structure at any one point
I encountered this also while running swiftly update simultaneously in two different terminal sessions. The command was installing the same toolchain version in both instances.
@adam-fowler Can I work on this issue?
I'm not really that involved in the swiftly project anymore. @cmcgee1024 can make a call on that.
@roulpriya I don't think that anyone else is working on this at the moment. I'm assigning this to you to indicate that you're taking a look at it right now.
@cmcgee1024 I came across how SwiftPM implements locking.
When we try to execute multiple instances of SwiftPM we get a log like
Another instance of SwiftPM is already running using '/Users/priyaroul/Code/swiftly/.build', waiting ...
In Swiftly, should we wait to acquire the lock or print an error and exit?
In my opinion lock acquisition should exit immediately with a specific exit code that scripts (or VSCode) can check and decide on their polling, and/or timeout strategy. Those things will have a better understanding of their environment, and the constraints.
The proxies, and swift run should not be interrupted by a lock since they have no good way to communicate the lock acquisition failure, limited by the behaviour of the commands that they proxy. They can be optimistic about presence of the config.json, and the selected toolchain. Uninstallation of a toolchain is also likely a relatively rare operation.
This work is complete with the linked PR's.