Add a concurrency lock for download/install against the same destination

combineDirTrees' merge logic assumes it's the only thing moving files
into a given target at a time; two `vintner download`/`install` runs
racing against the same --dest could otherwise interleave os.Rename
calls and corrupt the tree instead of erroring cleanly. Take an
exclusive, non-blocking flock(2) on the destination for the duration
of each run, so a second invocation fails immediately with a clear
message instead of silently colliding with the first.
This commit is contained in:
Cheviiot
2026-07-25 18:10:56 +10:00
parent 738234186d
commit b366dfa9ac
4 changed files with 187 additions and 0 deletions
+7
View File
@@ -15,6 +15,7 @@ import (
"strings"
"github.com/Cheviiot/vintner/assets"
"github.com/Cheviiot/vintner/internal/lock"
"github.com/Cheviiot/vintner/internal/wineenv"
)
@@ -34,6 +35,12 @@ func Install(dest, selfBinary string) error {
return fmt.Errorf("destination %q is not a directory", dest)
}
unlock, err := lock.Acquire(dest)
if err != nil {
return err
}
defer unlock()
// Targets are relative so the whole installed tree stays relocatable -
// moving or renaming dest doesn't break these symlinks the way an
// absolute target baked in at install time would.