summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-19 10:39:36 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-19 17:14:35 +0100
commit0b96aba022d51cf9939605c029bb8dba806653a1 (patch)
treef7d2883a6ea85546e4e9536f6ccfb184bc4293af /modules
parentfa520a2d983b982394ad10088393fb303e48980a (diff)
commands: Add "hugo mod verify"
See #6907
Diffstat (limited to 'modules')
-rw-r--r--modules/client.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/client.go b/modules/client.go
index 8ea8b1794..601b5e109 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -24,6 +24,9 @@ import (
"os"
"os/exec"
"path/filepath"
+ "regexp"
+
+ "github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugofs/files"
@@ -308,6 +311,38 @@ func (c *Client) Init(path string) error {
return nil
}
+var verifyErrorDirRe = regexp.MustCompile(`dir has been modified \((.*?)\)`)
+
+// Verify checks that the dependencies of the current module,
+// which are stored in a local downloaded source cache, have not been
+// modified since being downloaded.
+func (c *Client) Verify(clean bool) error {
+ // TODO1 add path to mod clean
+ err := c.runVerify()
+
+ if err != nil {
+ if clean {
+ m := verifyErrorDirRe.FindAllStringSubmatch(err.Error(), -1)
+ if m != nil {
+ for i := 0; i < len(m); i++ {
+ c, err := hugofs.MakeReadableAndRemoveAllModulePkgDir(c.fs, m[i][1])
+ if err != nil {
+ return err
+ }
+ fmt.Println("Cleaned", c)
+ }
+ }
+ // Try to verify it again.
+ err = c.runVerify()
+ }
+ }
+ return err
+}
+
+func (c *Client) runVerify() error {
+ return c.runGo(context.Background(), ioutil.Discard, "mod", "verify")
+}
+
func isProbablyModule(path string) bool {
return module.CheckPath(path) == nil
}