Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/hugofs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-19 12:39:36 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-19 19:14:35 +0300
commit0b96aba022d51cf9939605c029bb8dba806653a1 (patch)
treef7d2883a6ea85546e4e9536f6ccfb184bc4293af /hugofs
parentfa520a2d983b982394ad10088393fb303e48980a (diff)
commands: Add "hugo mod verify"
See #6907
Diffstat (limited to 'hugofs')
-rw-r--r--hugofs/fs.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/hugofs/fs.go b/hugofs/fs.go
index 163807704..c8c4c8afd 100644
--- a/hugofs/fs.go
+++ b/hugofs/fs.go
@@ -16,6 +16,7 @@ package hugofs
import (
"os"
+ "strings"
"github.com/gohugoio/hugo/config"
"github.com/spf13/afero"
@@ -88,3 +89,27 @@ func getWorkingDirFs(base afero.Fs, cfg config.Provider) *afero.BasePathFs {
func isWrite(flag int) bool {
return flag&os.O_RDWR != 0 || flag&os.O_WRONLY != 0
}
+
+// MakeReadableAndRemoveAllModulePkgDir makes any subdir in dir readable and then
+// removes the root.
+// TODO(bep) move this to a more suitable place.
+//
+func MakeReadableAndRemoveAllModulePkgDir(fs afero.Fs, dir string) (int, error) {
+ // Safe guard
+ if !strings.Contains(dir, "pkg") {
+ panic("invalid dir")
+ }
+
+ counter := 0
+ afero.Walk(fs, dir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ return nil
+ }
+ if info.IsDir() {
+ counter++
+ fs.Chmod(path, 0777)
+ }
+ return nil
+ })
+ return counter, fs.RemoveAll(dir)
+}