Create shared fn to read a lockfile
diff --git a/action/install.go b/action/install.go
index 3deb9d2..bf17caa 100644
--- a/action/install.go
+++ b/action/install.go
@@ -1,7 +1,6 @@
package action
import (
- "io/ioutil"
"path/filepath"
"github.com/Masterminds/glide/cache"
@@ -31,10 +30,17 @@
return
}
// Load lockfile
- lock, err := LoadLockfile(base, conf)
+ lock, err := cfg.ReadLockFile(filepath.Join(base, gpath.LockFile))
if err != nil {
msg.Die("Could not load lockfile.")
}
+ // Verify lockfile hasn't changed
+ hash, err := conf.Hash()
+ if err != nil {
+ msg.Die("Could not load lockfile.")
+ } else if hash != lock.Hash {
+ msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
+ }
// Delete unused packages
if installer.DeleteUnused {
@@ -77,28 +83,3 @@
}
}
}
-
-// LoadLockfile loads the contents of a glide.lock file.
-//
-// TODO: This should go in another package.
-func LoadLockfile(base string, conf *cfg.Config) (*cfg.Lockfile, error) {
- yml, err := ioutil.ReadFile(filepath.Join(base, gpath.LockFile))
- if err != nil {
- return nil, err
- }
- lock, err := cfg.LockfileFromYaml(yml)
- if err != nil {
- return nil, err
- }
-
- hash, err := conf.Hash()
- if err != nil {
- return nil, err
- }
-
- if hash != lock.Hash {
- msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
- }
-
- return lock, nil
-}
diff --git a/cfg/lock.go b/cfg/lock.go
index 3a157d0..215483c 100644
--- a/cfg/lock.go
+++ b/cfg/lock.go
@@ -72,6 +72,19 @@
return sha256.Sum256(yml), nil
}
+// ReadLockFile loads the contents of a glide.lock file.
+func ReadLockFile(lockpath string) (*Lockfile, error) {
+ yml, err := ioutil.ReadFile(lockpath)
+ if err != nil {
+ return nil, err
+ }
+ lock, err := LockfileFromYaml(yml)
+ if err != nil {
+ return nil, err
+ }
+ return lock, nil
+}
+
// Locks is a slice of locked dependencies.
type Locks []*Lock