Shadow the flock pkg & add a noop filelock so that at least the solaris binary can be built

Without this the following error occurs:

$ GOOS=solaris go build .
# github.com/hashicorp/packer/vendor/github.com/gofrs/flock
vendor/github.com/gofrs/flock/flock_unix.go:28:22: undefined: syscall.LOCK_EX
vendor/github.com/gofrs/flock/flock_unix.go:39:22: undefined: syscall.LOCK_SH
vendor/github.com/gofrs/flock/flock_unix.go:56:12: undefined: syscall.Flock
vendor/github.com/gofrs/flock/flock_unix.go:66:12: undefined: syscall.Flock
vendor/github.com/gofrs/flock/flock_unix.go:96:12: undefined: syscall.Flock
vendor/github.com/gofrs/flock/flock_unix.go:96:42: undefined: syscall.LOCK_UN
vendor/github.com/gofrs/flock/flock_unix.go:118:21: undefined: syscall.LOCK_EX
vendor/github.com/gofrs/flock/flock_unix.go:130:21: undefined: syscall.LOCK_SH
vendor/github.com/gofrs/flock/flock_unix.go:149:9: undefined: syscall.Flock
vendor/github.com/gofrs/flock/flock_unix.go:149:44: undefined: syscall.LOCK_NB
vendor/github.com/gofrs/flock/flock_unix.go:149:44: too many errors
This commit is contained in:
Adrien Delorme 2019-04-30 16:01:23 +02:00
parent 5d9d43c01d
commit d9e5145de9
5 changed files with 35 additions and 6 deletions

View File

@ -0,0 +1,11 @@
// +build !solaris
package filelock
import "github.com/gofrs/flock"
type Flock = flock.Flock
func New(path string) *Flock {
return flock.New(path)
}

View File

@ -0,0 +1,11 @@
// build solaris
package filelock
// Flock is a noop on solaris for now.
// TODO(azr): PR github.com/gofrs/flock for this.
type Flock = Noop
func New(string) *Flock {
return &Flock{}
}

8
common/filelock/noop.go Normal file
View File

@ -0,0 +1,8 @@
package filelock
// this lock does nothing
type Noop struct{}
func (_ *Noop) Lock() (bool, error) { return true, nil }
func (_ *Noop) TryLock() (bool, error) { return true, nil }
func (_ *Noop) Unlock() error { return nil }

View File

@ -8,8 +8,7 @@ import (
"net"
"strconv"
"github.com/gofrs/flock"
"github.com/hashicorp/packer/common/filelock"
"github.com/hashicorp/packer/packer"
)
@ -26,7 +25,7 @@ type Listener struct {
net.Listener
Port int
Address string
lock *flock.Flock
lock *filelock.Flock
}
func (l *Listener) Close() error {
@ -70,7 +69,7 @@ func (lc ListenRangeConfig) Listen(ctx context.Context) (*Listener, error) {
return nil, err
}
lock := flock.New(lockFilePath)
lock := filelock.New(lockFilePath)
locked, err := lock.TryLock()
if err != nil {
return nil, err

View File

@ -10,9 +10,9 @@ import (
"runtime"
"strings"
"github.com/gofrs/flock"
getter "github.com/hashicorp/go-getter"
urlhelper "github.com/hashicorp/go-getter/helper/url"
"github.com/hashicorp/packer/common/filelock"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
@ -146,7 +146,7 @@ func (s *StepDownload) download(ctx context.Context, ui packer.Ui, source string
lockFile := targetPath + ".lock"
log.Printf("Acquiring lock for: %s (%s)", u.String(), lockFile)
lock := flock.New(lockFile)
lock := filelock.New(lockFile)
lock.Lock()
defer lock.Unlock()