diff --git a/common/filelock/filelock.go b/common/filelock/filelock.go new file mode 100644 index 000000000..c83816ee6 --- /dev/null +++ b/common/filelock/filelock.go @@ -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) +} diff --git a/common/filelock/filelock_solaris.go b/common/filelock/filelock_solaris.go new file mode 100644 index 000000000..06685254c --- /dev/null +++ b/common/filelock/filelock_solaris.go @@ -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{} +} diff --git a/common/filelock/noop.go b/common/filelock/noop.go new file mode 100644 index 000000000..ebf8f1967 --- /dev/null +++ b/common/filelock/noop.go @@ -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 } diff --git a/common/net/configure_port.go b/common/net/configure_port.go index 51765fda6..cdc0a9168 100644 --- a/common/net/configure_port.go +++ b/common/net/configure_port.go @@ -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 diff --git a/common/step_download.go b/common/step_download.go index e562b619c..af7708e6e 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -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()