Skip to content

Commit

Permalink
bb: use new lockfile package.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugelgupf committed Oct 15, 2018
1 parent a1f2f47 commit af815e6
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions pkg/uroot/builder/bb/bb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,36 @@ import (
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/imports"

"github.com/nightlyone/lockfile"
"github.com/u-root/u-root/pkg/golang"
"github.com/u-root/u-root/pkg/lockfile"
)

// Commands to skip building in bb mode.
var skip = map[string]struct{}{
"bb": {},
}

func getBBLock(bblock string) (lockfile.Lockfile, error) {
func getBBLock(bblock string) (*lockfile.Lockfile, error) {
secondsTimeout := 60
timer := time.After(time.Duration(secondsTimeout) * time.Second)
lock, err := lockfile.New(bblock)
if err != nil {
return lockfile.Lockfile(""), err
}
lock := lockfile.New(bblock)
for {
select {
case <-timer:
return lockfile.Lockfile(""), fmt.Errorf("could not acquire bblock file %q: %d second deadline expired", bblock, secondsTimeout)
return nil, fmt.Errorf("could not acquire bblock file %q: %d second deadline expired", bblock, secondsTimeout)
default:
}

switch err := lock.TryLock(); err {
case nil:
return lock, nil

case lockfile.ErrBusy, lockfile.ErrNotExist:
case lockfile.ErrBusy:
// This sucks. Use inotify.
time.Sleep(100 * time.Millisecond)

default:
return lockfile.Lockfile(""), err
return nil, err
}
}
}
Expand Down

0 comments on commit af815e6

Please sign in to comment.