cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.67k stars 103 forks source link

OCI storage: unconditionally remove the old link when link()'ing #686

Closed edigaryev closed 7 months ago

edigaryev commented 7 months ago

The fileExists() method always resolves symbolic links and will return false even if the link itself exists:

If the final element in path specifies a symbolic link, this method traverses the link and returns true or false based on the existence of the file at the link destination.

This is an issue when tart pull detects that there isn't enough space for the new image, removes the old sha256: and then tries to create a link for the news image and fails:

Persistent worker failed to start the task: tart isolation failed: failed to create VM cloned from "ghcr.io/cirruslabs/macos-sonoma-base:latest": tart command returned non-zero exit code: "Error: The file “latest” couldn’t be saved in the folder “macos-sonoma-base” because a file with the same name already exists.”

Unfortunately, the FileManager doesn't seem to provide any alternatives that don't follow the link, so the only way is to use raw system calls 🤦

I think a more easier solution would be to simply always delete the old link and ignore the errors (e.g. when an old link doesn't exist).

Resolves PERSISTENT-WORKERS-1T.