Skip to content

Commit

Permalink
Merge branch 'main' into fix-deps-check
Browse files Browse the repository at this point in the history
  • Loading branch information
retr0h authored May 24, 2024
2 parents 66f62cd + 2e2bb20 commit ff2dd1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"log/slog"
"strconv"
"time"

"github.com/avfs/avfs/vfs/osfs"
"github.com/danjacques/gofslock/fslock"
Expand Down Expand Up @@ -105,13 +106,16 @@ func (r *Repositories) withLock(fn func() error) error {
return err
}

blocker := func() error {
time.Sleep(time.Millisecond)
return nil
}
lockFile := r.appFs.Join(lockDir, "gilt.lock")
r.logger.Info(
"acquiring lock",
slog.String("lockfile", lockFile),
)

err = fslock.With(lockFile, fn)
err = fslock.WithBlocking(lockFile, blocker, fn)
if err != nil {
if errors.Is(err, fslock.ErrLockHeld) {
return fmt.Errorf("could not acquire lock on %s: %s", lockFile, err)
Expand Down
5 changes: 5 additions & 0 deletions test/integration/test_cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,8 @@ teardown() {
run stat /tmp/initGiltfile.yaml
[ "$status" = 0 ]
}

@test "concurrent gilt overlay will block/wait" {
run bash -c "cd ${GILT_TEST_BASE_TMP_DIR}; (for x in {1..8}; do go run ${GILT_PROGRAM} overlay & done ; wait) 2>&1 | grep ERR"
[ "$status" -eq 1 ]
}

0 comments on commit ff2dd1f

Please sign in to comment.