chore(deps): bump github.com/spf13/afero from 1.9.2 to 1.9.5 (#2448)

Bumps [github.com/spf13/afero](https://github.com/spf13/afero) from 1.9.2 to 1.9.5.
- [Release notes](https://github.com/spf13/afero/releases)
- [Commits](https://github.com/spf13/afero/compare/v1.9.2...v1.9.5)

---
updated-dependencies:
- dependency-name: github.com/spf13/afero
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
dependabot[bot] 2023-05-10 16:41:13 -07:00 committed by GitHub
parent 74fc5403c3
commit 0514e4df6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 53 additions and 31 deletions

2
go.mod
View File

@ -23,7 +23,7 @@ require (
github.com/otiai10/copy v1.7.0 github.com/otiai10/copy v1.7.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0
github.com/spf13/afero v1.9.2 github.com/spf13/afero v1.9.5
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
golang.org/x/net v0.9.0 golang.org/x/net v0.9.0

3
go.sum
View File

@ -2282,8 +2282,9 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw=
github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.1/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=

View File

@ -97,7 +97,7 @@ type Fs interface {
// Chown changes the uid and gid of the named file. // Chown changes the uid and gid of the named file.
Chown(name string, uid, gid int) error Chown(name string, uid, gid int) error
//Chtimes changes the access and modification times of the named file // Chtimes changes the access and modification times of the named file
Chtimes(name string, atime time.Time, mtime time.Time) error Chtimes(name string, atime time.Time, mtime time.Time) error
} }

View File

@ -40,7 +40,6 @@ func (f *BasePathFile) Name() string {
func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error) { func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error) {
if rdf, ok := f.File.(fs.ReadDirFile); ok { if rdf, ok := f.File.(fs.ReadDirFile); ok {
return rdf.ReadDir(n) return rdf.ReadDir(n)
} }
return readDirFile{f.File}.ReadDir(n) return readDirFile{f.File}.ReadDir(n)
} }

View File

@ -223,7 +223,7 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File,
return nil, err return nil, err
} }
if isaDir { if isaDir {
if err = u.layer.MkdirAll(dir, 0777); err != nil { if err = u.layer.MkdirAll(dir, 0o777); err != nil {
return nil, err return nil, err
} }
return u.layer.OpenFile(name, flag, perm) return u.layer.OpenFile(name, flag, perm)
@ -247,8 +247,9 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File,
// This function handles the 9 different possibilities caused // This function handles the 9 different possibilities caused
// by the union which are the intersection of the following... // by the union which are the intersection of the following...
// layer: doesn't exist, exists as a file, and exists as a directory //
// base: doesn't exist, exists as a file, and exists as a directory // layer: doesn't exist, exists as a file, and exists as a directory
// base: doesn't exist, exists as a file, and exists as a directory
func (u *CopyOnWriteFs) Open(name string) (File, error) { func (u *CopyOnWriteFs) Open(name string) (File, error) {
// Since the overlay overrides the base we check that first // Since the overlay overrides the base we check that first
b, err := u.isBaseFile(name) b, err := u.isBaseFile(name)
@ -322,5 +323,5 @@ func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error {
} }
func (u *CopyOnWriteFs) Create(name string) (File, error) { func (u *CopyOnWriteFs) Create(name string) (File, error) {
return u.OpenFile(name, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666) return u.OpenFile(name, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o666)
} }

View File

@ -141,8 +141,10 @@ func WriteFile(fs Fs, filename string, data []byte, perm os.FileMode) error {
// We generate random temporary file names so that there's a good // We generate random temporary file names so that there's a good
// chance the file doesn't exist yet - keeps the number of tries in // chance the file doesn't exist yet - keeps the number of tries in
// TempFile to a minimum. // TempFile to a minimum.
var randNum uint32 var (
var randmu sync.Mutex randNum uint32
randmu sync.Mutex
)
func reseed() uint32 { func reseed() uint32 {
return uint32(time.Now().UnixNano() + int64(os.Getpid())) return uint32(time.Now().UnixNano() + int64(os.Getpid()))
@ -190,7 +192,7 @@ func TempFile(fs Fs, dir, pattern string) (f File, err error) {
nconflict := 0 nconflict := 0
for i := 0; i < 10000; i++ { for i := 0; i < 10000; i++ {
name := filepath.Join(dir, prefix+nextRandom()+suffix) name := filepath.Join(dir, prefix+nextRandom()+suffix)
f, err = fs.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) f, err = fs.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600)
if os.IsExist(err) { if os.IsExist(err) {
if nconflict++; nconflict > 10 { if nconflict++; nconflict > 10 {
randmu.Lock() randmu.Lock()
@ -214,6 +216,7 @@ func TempFile(fs Fs, dir, pattern string) (f File, err error) {
func (a Afero) TempDir(dir, prefix string) (name string, err error) { func (a Afero) TempDir(dir, prefix string) (name string, err error) {
return TempDir(a.Fs, dir, prefix) return TempDir(a.Fs, dir, prefix)
} }
func TempDir(fs Fs, dir, prefix string) (name string, err error) { func TempDir(fs Fs, dir, prefix string) (name string, err error) {
if dir == "" { if dir == "" {
dir = os.TempDir() dir = os.TempDir()
@ -222,7 +225,7 @@ func TempDir(fs Fs, dir, prefix string) (name string, err error) {
nconflict := 0 nconflict := 0
for i := 0; i < 10000; i++ { for i := 0; i < 10000; i++ {
try := filepath.Join(dir, prefix+nextRandom()) try := filepath.Join(dir, prefix+nextRandom())
err = fs.Mkdir(try, 0700) err = fs.Mkdir(try, 0o700)
if os.IsExist(err) { if os.IsExist(err) {
if nconflict++; nconflict > 10 { if nconflict++; nconflict > 10 {
randmu.Lock() randmu.Lock()

View File

@ -245,7 +245,7 @@ func (f *File) Truncate(size int64) error {
defer f.fileData.Unlock() defer f.fileData.Unlock()
if size > int64(len(f.fileData.data)) { if size > int64(len(f.fileData.data)) {
diff := size - int64(len(f.fileData.data)) diff := size - int64(len(f.fileData.data))
f.fileData.data = append(f.fileData.data, bytes.Repeat([]byte{00}, int(diff))...) f.fileData.data = append(f.fileData.data, bytes.Repeat([]byte{0o0}, int(diff))...)
} else { } else {
f.fileData.data = f.fileData.data[0:size] f.fileData.data = f.fileData.data[0:size]
} }
@ -285,7 +285,7 @@ func (f *File) Write(b []byte) (n int, err error) {
tail = f.fileData.data[n+int(cur):] tail = f.fileData.data[n+int(cur):]
} }
if diff > 0 { if diff > 0 {
f.fileData.data = append(f.fileData.data, append(bytes.Repeat([]byte{00}, int(diff)), b...)...) f.fileData.data = append(f.fileData.data, append(bytes.Repeat([]byte{0o0}, int(diff)), b...)...)
f.fileData.data = append(f.fileData.data, tail...) f.fileData.data = append(f.fileData.data, tail...)
} else { } else {
f.fileData.data = append(f.fileData.data[:cur], b...) f.fileData.data = append(f.fileData.data[:cur], b...)
@ -321,16 +321,19 @@ func (s *FileInfo) Name() string {
s.Unlock() s.Unlock()
return name return name
} }
func (s *FileInfo) Mode() os.FileMode { func (s *FileInfo) Mode() os.FileMode {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
return s.mode return s.mode
} }
func (s *FileInfo) ModTime() time.Time { func (s *FileInfo) ModTime() time.Time {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
return s.modtime return s.modtime
} }
func (s *FileInfo) IsDir() bool { func (s *FileInfo) IsDir() bool {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()

View File

@ -15,6 +15,7 @@ package afero
import ( import (
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -43,7 +44,7 @@ func (m *MemMapFs) getData() map[string]*mem.FileData {
// Root should always exist, right? // Root should always exist, right?
// TODO: what about windows? // TODO: what about windows?
root := mem.CreateDir(FilePathSeparator) root := mem.CreateDir(FilePathSeparator)
mem.SetMode(root, os.ModeDir|0755) mem.SetMode(root, os.ModeDir|0o755)
m.data[FilePathSeparator] = root m.data[FilePathSeparator] = root
}) })
return m.data return m.data
@ -96,12 +97,12 @@ func (m *MemMapFs) registerWithParent(f *mem.FileData, perm os.FileMode) {
pdir := filepath.Dir(filepath.Clean(f.Name())) pdir := filepath.Dir(filepath.Clean(f.Name()))
err := m.lockfreeMkdir(pdir, perm) err := m.lockfreeMkdir(pdir, perm)
if err != nil { if err != nil {
//log.Println("Mkdir error:", err) // log.Println("Mkdir error:", err)
return return
} }
parent, err = m.lockfreeOpen(pdir) parent, err = m.lockfreeOpen(pdir)
if err != nil { if err != nil {
//log.Println("Open after Mkdir error:", err) // log.Println("Open after Mkdir error:", err)
return return
} }
} }
@ -142,6 +143,11 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
} }
m.mu.Lock() m.mu.Lock()
// Dobule check that it doesn't exist.
if _, ok := m.getData()[name]; ok {
m.mu.Unlock()
return &os.PathError{Op: "mkdir", Path: name, Err: ErrFileExists}
}
item := mem.CreateDir(name) item := mem.CreateDir(name)
mem.SetMode(item, os.ModeDir|perm) mem.SetMode(item, os.ModeDir|perm)
m.getData()[name] = item m.getData()[name] = item
@ -232,7 +238,7 @@ func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, erro
file = mem.NewReadOnlyFileHandle(file.(*mem.File).Data()) file = mem.NewReadOnlyFileHandle(file.(*mem.File).Data())
} }
if flag&os.O_APPEND > 0 { if flag&os.O_APPEND > 0 {
_, err = file.Seek(0, os.SEEK_END) _, err = file.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
file.Close() file.Close()
return nil, err return nil, err
@ -314,6 +320,18 @@ func (m *MemMapFs) Rename(oldname, newname string) error {
} else { } else {
return &os.PathError{Op: "rename", Path: oldname, Err: ErrFileNotFound} return &os.PathError{Op: "rename", Path: oldname, Err: ErrFileNotFound}
} }
for p, fileData := range m.getData() {
if strings.HasPrefix(p, oldname+FilePathSeparator) {
m.mu.RUnlock()
m.mu.Lock()
delete(m.getData(), p)
p := strings.Replace(p, oldname, newname, 1)
m.getData()[p] = fileData
m.mu.Unlock()
m.mu.RLock()
}
}
return nil return nil
} }

View File

@ -10,7 +10,6 @@ import (
// The RegexpFs filters files (not directories) by regular expression. Only // The RegexpFs filters files (not directories) by regular expression. Only
// files matching the given regexp will be allowed, all others get a ENOENT error ( // files matching the given regexp will be allowed, all others get a ENOENT error (
// "No such file or directory"). // "No such file or directory").
//
type RegexpFs struct { type RegexpFs struct {
re *regexp.Regexp re *regexp.Regexp
source Fs source Fs

View File

@ -21,9 +21,9 @@ import (
// filesystems saying so. // filesystems saying so.
// It indicates support for 3 symlink related interfaces that implement the // It indicates support for 3 symlink related interfaces that implement the
// behaviors of the os methods: // behaviors of the os methods:
// - Lstat // - Lstat
// - Symlink, and // - Symlink, and
// - Readlink // - Readlink
type Symlinker interface { type Symlinker interface {
Lstater Lstater
Linker Linker

View File

@ -47,7 +47,7 @@ func (f *UnionFile) Read(s []byte) (int, error) {
if (err == nil || err == io.EOF) && f.Base != nil { if (err == nil || err == io.EOF) && f.Base != nil {
// advance the file position also in the base file, the next // advance the file position also in the base file, the next
// call may be a write at this position (or a seek with SEEK_CUR) // call may be a write at this position (or a seek with SEEK_CUR)
if _, seekErr := f.Base.Seek(int64(n), os.SEEK_CUR); seekErr != nil { if _, seekErr := f.Base.Seek(int64(n), io.SeekCurrent); seekErr != nil {
// only overwrite err in case the seek fails: we need to // only overwrite err in case the seek fails: we need to
// report an eventual io.EOF to the caller // report an eventual io.EOF to the caller
err = seekErr err = seekErr
@ -130,7 +130,7 @@ func (f *UnionFile) Name() string {
type DirsMerger func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) type DirsMerger func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error)
var defaultUnionMergeDirsFn = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) { var defaultUnionMergeDirsFn = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
var files = make(map[string]os.FileInfo) files := make(map[string]os.FileInfo)
for _, fi := range lofi { for _, fi := range lofi {
files[fi.Name()] = fi files[fi.Name()] = fi
@ -151,7 +151,6 @@ var defaultUnionMergeDirsFn = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, err
} }
return rfi, nil return rfi, nil
} }
// Readdir will weave the two directories together and // Readdir will weave the two directories together and
@ -275,7 +274,7 @@ func copyFile(base Fs, layer Fs, name string, bfh File) error {
return err return err
} }
if !exists { if !exists {
err = layer.MkdirAll(filepath.Dir(name), 0777) // FIXME? err = layer.MkdirAll(filepath.Dir(name), 0o777) // FIXME?
if err != nil { if err != nil {
return err return err
} }

View File

@ -43,7 +43,7 @@ func WriteReader(fs Fs, path string, r io.Reader) (err error) {
ospath := filepath.FromSlash(dir) ospath := filepath.FromSlash(dir)
if ospath != "" { if ospath != "" {
err = fs.MkdirAll(ospath, 0777) // rwx, rw, r err = fs.MkdirAll(ospath, 0o777) // rwx, rw, r
if err != nil { if err != nil {
if err != os.ErrExist { if err != os.ErrExist {
return err return err
@ -71,7 +71,7 @@ func SafeWriteReader(fs Fs, path string, r io.Reader) (err error) {
ospath := filepath.FromSlash(dir) ospath := filepath.FromSlash(dir)
if ospath != "" { if ospath != "" {
err = fs.MkdirAll(ospath, 0777) // rwx, rw, r err = fs.MkdirAll(ospath, 0o777) // rwx, rw, r
if err != nil { if err != nil {
return return
} }
@ -124,7 +124,7 @@ func GetTempDir(fs Fs, subPath string) string {
return addSlash(dir) return addSlash(dir)
} }
err := fs.MkdirAll(dir, 0777) err := fs.MkdirAll(dir, 0o777)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -197,7 +197,6 @@ func FileContainsAnyBytes(fs Fs, filename string, subslices [][]byte) (bool, err
// readerContains reports whether any of the subslices is within r. // readerContains reports whether any of the subslices is within r.
func readerContainsAny(r io.Reader, subslices ...[]byte) bool { func readerContainsAny(r io.Reader, subslices ...[]byte) bool {
if r == nil || len(subslices) == 0 { if r == nil || len(subslices) == 0 {
return false return false
} }

2
vendor/modules.txt vendored
View File

@ -731,7 +731,7 @@ github.com/sergi/go-diff/diffmatchpatch
# github.com/sirupsen/logrus v1.9.0 # github.com/sirupsen/logrus v1.9.0
## explicit; go 1.13 ## explicit; go 1.13
github.com/sirupsen/logrus github.com/sirupsen/logrus
# github.com/spf13/afero v1.9.2 # github.com/spf13/afero v1.9.5
## explicit; go 1.16 ## explicit; go 1.16
github.com/spf13/afero github.com/spf13/afero
github.com/spf13/afero/internal/common github.com/spf13/afero/internal/common