mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
25
hugofs/fs.go
25
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user