forked from mirror/afero
fix repos
This commit is contained in:
parent
a800a9de53
commit
1707ad0dd8
12
README.md
12
README.md
|
@ -2,7 +2,7 @@
|
|||
|
||||
A FileSystem Abstraction System for Go
|
||||
|
||||
[![Test](https://github.com/spf13/afero/actions/workflows/test.yml/badge.svg)](https://github.com/spf13/afero/actions/workflows/test.yml) [![GoDoc](https://godoc.org/github.com/spf13/afero?status.svg)](https://godoc.org/github.com/spf13/afero) [![Join the chat at https://gitter.im/spf13/afero](https://badges.gitter.im/Dev%20Chat.svg)](https://gitter.im/spf13/afero?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[![Test](https://git.internal/re/afero/actions/workflows/test.yml/badge.svg)](https://git.internal/re/afero/actions/workflows/test.yml) [![GoDoc](https://godoc.org/git.internal/re/afero?status.svg)](https://godoc.org/git.internal/re/afero) [![Join the chat at https://gitter.im/spf13/afero](https://badges.gitter.im/Dev%20Chat.svg)](https://gitter.im/spf13/afero?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
# Overview
|
||||
|
||||
|
@ -50,11 +50,11 @@ A few different ways you could use Afero:
|
|||
|
||||
First use go get to install the latest version of the library.
|
||||
|
||||
$ go get github.com/spf13/afero
|
||||
$ go get git.internal/re/afero
|
||||
|
||||
Next include Afero in your application.
|
||||
```go
|
||||
import "github.com/spf13/afero"
|
||||
import "git.internal/re/afero"
|
||||
```
|
||||
|
||||
## Step 2: Declare a backend
|
||||
|
@ -152,7 +152,7 @@ Walk(root string, walkFn filepath.WalkFunc) error
|
|||
WriteFile(filename string, data []byte, perm os.FileMode) error
|
||||
WriteReader(path string, r io.Reader) (err error)
|
||||
```
|
||||
For a complete list see [Afero's GoDoc](https://godoc.org/github.com/spf13/afero)
|
||||
For a complete list see [Afero's GoDoc](https://godoc.org/git.internal/re/afero)
|
||||
|
||||
They are available under two different approaches to use. You can either call
|
||||
them directly where the first parameter of each function will be the file
|
||||
|
@ -417,7 +417,7 @@ Googles very well.
|
|||
|
||||
## Release Notes
|
||||
|
||||
See the [Releases Page](https://github.com/spf13/afero/releases).
|
||||
See the [Releases Page](https://git.internal/re/afero/releases).
|
||||
|
||||
## Contributing
|
||||
|
||||
|
@ -439,4 +439,4 @@ Names in no particular order:
|
|||
## License
|
||||
|
||||
Afero is released under the Apache 2.0 license. See
|
||||
[LICENSE.txt](https://github.com/spf13/afero/blob/master/LICENSE.txt)
|
||||
[LICENSE.txt](https://git.internal/re/afero/blob/master/LICENSE.txt)
|
||||
|
|
|
@ -28,8 +28,10 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var testName = "test.txt"
|
||||
var Fss = []Fs{&MemMapFs{}, &OsFs{}}
|
||||
var (
|
||||
testName = "test.txt"
|
||||
Fss = []Fs{&MemMapFs{}, &OsFs{}}
|
||||
)
|
||||
|
||||
var testRegistry map[Fs][]string = make(map[Fs][]string)
|
||||
|
||||
|
@ -45,7 +47,6 @@ func testDir(fs Fs) string {
|
|||
|
||||
func tmpFile(fs Fs) File {
|
||||
x, err := TempFile(fs, "", "afero")
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprint("unable to work with temp file", err))
|
||||
}
|
||||
|
@ -55,7 +56,7 @@ func tmpFile(fs Fs) File {
|
|||
return x
|
||||
}
|
||||
|
||||
//Read with length 0 should not return EOF.
|
||||
// Read with length 0 should not return EOF.
|
||||
func TestRead0(t *testing.T) {
|
||||
for _, fs := range Fss {
|
||||
f := tmpFile(fs)
|
||||
|
@ -83,7 +84,7 @@ func TestOpenFile(t *testing.T) {
|
|||
tmp := testDir(fs)
|
||||
path := filepath.Join(tmp, testName)
|
||||
|
||||
f, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
|
||||
f, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0o600)
|
||||
if err != nil {
|
||||
t.Error(fs.Name(), "OpenFile (O_CREATE) failed:", err)
|
||||
continue
|
||||
|
@ -91,7 +92,7 @@ func TestOpenFile(t *testing.T) {
|
|||
io.WriteString(f, "initial")
|
||||
f.Close()
|
||||
|
||||
f, err = fs.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0600)
|
||||
f, err = fs.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0o600)
|
||||
if err != nil {
|
||||
t.Error(fs.Name(), "OpenFile (O_APPEND) failed:", err)
|
||||
continue
|
||||
|
@ -99,7 +100,7 @@ func TestOpenFile(t *testing.T) {
|
|||
io.WriteString(f, "|append")
|
||||
f.Close()
|
||||
|
||||
f, _ = fs.OpenFile(path, os.O_RDONLY, 0600)
|
||||
f, _ = fs.OpenFile(path, os.O_RDONLY, 0o600)
|
||||
contents, _ := ioutil.ReadAll(f)
|
||||
expectedContents := "initial|append"
|
||||
if string(contents) != expectedContents {
|
||||
|
@ -107,7 +108,7 @@ func TestOpenFile(t *testing.T) {
|
|||
}
|
||||
f.Close()
|
||||
|
||||
f, err = fs.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0600)
|
||||
f, err = fs.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0o600)
|
||||
if err != nil {
|
||||
t.Error(fs.Name(), "OpenFile (O_TRUNC) failed:", err)
|
||||
continue
|
||||
|
@ -333,7 +334,7 @@ func TestSeek(t *testing.T) {
|
|||
whence int
|
||||
out int64
|
||||
}
|
||||
var tests = []test{
|
||||
tests := []test{
|
||||
{0, 1, int64(len(data))},
|
||||
{0, 0, 0},
|
||||
{5, 0, 5},
|
||||
|
@ -424,7 +425,7 @@ func setupTestDirReusePath(t *testing.T, fs Fs, path string) string {
|
|||
|
||||
func setupTestFiles(t *testing.T, fs Fs, path string) string {
|
||||
testSubDir := filepath.Join(path, "more", "subdirectories", "for", "testing", "we")
|
||||
err := fs.MkdirAll(testSubDir, 0700)
|
||||
err := fs.MkdirAll(testSubDir, 0o700)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -592,7 +593,7 @@ func TestReaddir(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// https://github.com/spf13/afero/issues/169
|
||||
// https://git.internal/re/afero/issues/169
|
||||
func TestReaddirRegularFile(t *testing.T) {
|
||||
defer removeAllTestFiles(t)
|
||||
for _, fs := range Fss {
|
||||
|
@ -637,7 +638,7 @@ func TestReaddirAll(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var namesRoot = []string{}
|
||||
namesRoot := []string{}
|
||||
for _, e := range rootInfo {
|
||||
namesRoot = append(namesRoot, e.Name())
|
||||
}
|
||||
|
@ -652,7 +653,7 @@ func TestReaddirAll(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var namesSub = []string{}
|
||||
namesSub := []string{}
|
||||
for _, e := range subInfo {
|
||||
namesSub = append(namesSub, e.Name())
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ func TestCopyOnWrite(t *testing.T) {
|
|||
|
||||
compositeFs := NewCopyOnWriteFs(NewReadOnlyFs(NewOsFs()), osFs)
|
||||
|
||||
var dir = filepath.Join(writeDir, "some/path")
|
||||
dir := filepath.Join(writeDir, "some/path")
|
||||
|
||||
err = compositeFs.MkdirAll(dir, 0744)
|
||||
err = compositeFs.MkdirAll(dir, 0o744)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -27,17 +27,17 @@ func TestCopyOnWrite(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// https://github.com/spf13/afero/issues/189
|
||||
// https://git.internal/re/afero/issues/189
|
||||
// We want the composite file system to behave like the OS file system
|
||||
// on Mkdir and MkdirAll
|
||||
for _, fs := range []Fs{osFs, compositeFs} {
|
||||
err = fs.Mkdir(dir, 0744)
|
||||
err = fs.Mkdir(dir, 0o744)
|
||||
if err == nil || !os.IsExist(err) {
|
||||
t.Errorf("Mkdir: Got %q for %T", err, fs)
|
||||
}
|
||||
|
||||
// MkdirAll does not return an error when the directory already exists
|
||||
err = fs.MkdirAll(dir, 0744)
|
||||
err = fs.MkdirAll(dir, 0o744)
|
||||
if err != nil {
|
||||
t.Errorf("MkdirAll: Got %q for %T", err, fs)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func TestCopyOnWriteFileInMemMapBase(t *testing.T) {
|
|||
base := &MemMapFs{}
|
||||
layer := &MemMapFs{}
|
||||
|
||||
if err := WriteFile(base, "base.txt", []byte("base"), 0755); err != nil {
|
||||
if err := WriteFile(base, "base.txt", []byte("base"), 0o755); err != nil {
|
||||
t.Fatalf("Failed to write file: %s", err)
|
||||
}
|
||||
|
||||
|
|
14
gcsfs/gcs.go
14
gcsfs/gcs.go
|
@ -22,8 +22,8 @@ import (
|
|||
"time"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
"git.internal/re/afero"
|
||||
"github.com/googleapis/google-cloud-go-testing/storage/stiface"
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"google.golang.org/api/option"
|
||||
)
|
||||
|
@ -76,39 +76,51 @@ func NewGcsFSFromClientWithSeparator(ctx context.Context, client *storage.Client
|
|||
func (fs *GcsFs) Name() string {
|
||||
return fs.source.Name()
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Create(name string) (afero.File, error) {
|
||||
return fs.source.Create(name)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Mkdir(name string, perm os.FileMode) error {
|
||||
return fs.source.Mkdir(name, perm)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) MkdirAll(path string, perm os.FileMode) error {
|
||||
return fs.source.MkdirAll(path, perm)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Open(name string) (afero.File, error) {
|
||||
return fs.source.Open(name)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
|
||||
return fs.source.OpenFile(name, flag, perm)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Remove(name string) error {
|
||||
return fs.source.Remove(name)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) RemoveAll(path string) error {
|
||||
return fs.source.RemoveAll(path)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Rename(oldname, newname string) error {
|
||||
return fs.source.Rename(oldname, newname)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Stat(name string) (os.FileInfo, error) {
|
||||
return fs.source.Stat(name)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Chmod(name string, mode os.FileMode) error {
|
||||
return fs.source.Chmod(name, mode)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
return fs.source.Chtimes(name, atime, mtime)
|
||||
}
|
||||
|
||||
func (fs *GcsFs) Chown(name string, uid, gid int) error {
|
||||
return fs.source.Chown(name, uid, gid)
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
"git.internal/re/afero"
|
||||
"github.com/googleapis/google-cloud-go-testing/storage/stiface"
|
||||
"github.com/spf13/afero"
|
||||
"google.golang.org/api/iterator"
|
||||
)
|
||||
|
||||
|
@ -166,7 +166,7 @@ func (w *writerMock) Close() error {
|
|||
if w.file == nil {
|
||||
var err error
|
||||
if strings.HasSuffix(w.name, "/") {
|
||||
err = w.fs.Mkdir(w.name, 0755)
|
||||
err = w.fs.Mkdir(w.name, 0o755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ import (
|
|||
"golang.org/x/oauth2/google"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
"git.internal/re/afero"
|
||||
"github.com/googleapis/google-cloud-go-testing/storage/stiface"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -122,7 +122,7 @@ func TestMain(m *testing.M) {
|
|||
gcsAfs = &afero.Afero{Fs: &GcsFs{NewGcsFs(ctx, mockClient)}}
|
||||
|
||||
// Uncomment to use the real, not mocked, client
|
||||
//gcsAfs = &Afero{Fs: &GcsFs{gcsfs.NewGcsFs(ctx, client)}}
|
||||
// gcsAfs = &Afero{Fs: &GcsFs{gcsfs.NewGcsFs(ctx, client)}}
|
||||
|
||||
exitCode = m.Run()
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ func TestGcsSeek(t *testing.T) {
|
|||
t.Fatalf("opening %v: %v", name, err)
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
offIn int64
|
||||
whence int
|
||||
offOut int64
|
||||
|
@ -477,7 +477,7 @@ func TestGcsOpenFile(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, name := range names {
|
||||
file, err := gcsAfs.OpenFile(name, os.O_RDONLY, 0400)
|
||||
file, err := gcsAfs.OpenFile(name, os.O_RDONLY, 0o400)
|
||||
if !f.exists {
|
||||
if (f.name != "" && !errors.Is(err, syscall.ENOENT)) ||
|
||||
(f.name == "" && !errors.Is(err, ErrNoBucketInName)) {
|
||||
|
@ -496,7 +496,7 @@ func TestGcsOpenFile(t *testing.T) {
|
|||
t.Fatalf("failed to close a file \"%s\": %s", name, err)
|
||||
}
|
||||
|
||||
_, err = gcsAfs.OpenFile(name, os.O_CREATE, 0600)
|
||||
_, err = gcsAfs.OpenFile(name, os.O_CREATE, 0o600)
|
||||
if !errors.Is(err, syscall.EPERM) {
|
||||
t.Errorf("%v: open for write: got %v, expected %v", name, err, syscall.EPERM)
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ func TestGcsMkdir(t *testing.T) {
|
|||
t.Run("empty", func(t *testing.T) {
|
||||
emptyDirName := bucketName
|
||||
|
||||
err := gcsAfs.Mkdir(emptyDirName, 0755)
|
||||
err := gcsAfs.Mkdir(emptyDirName, 0o755)
|
||||
if err == nil {
|
||||
t.Fatal("did not fail upon creation of an empty folder")
|
||||
}
|
||||
|
@ -723,7 +723,7 @@ func TestGcsMkdir(t *testing.T) {
|
|||
dirName := filepath.Join(bucketName, "a-test-dir")
|
||||
var err error
|
||||
|
||||
err = gcsAfs.Mkdir(dirName, 0755)
|
||||
err = gcsAfs.Mkdir(dirName, 0o755)
|
||||
if err != nil {
|
||||
t.Fatal("failed to create a folder with error", err)
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ func TestGcsMkdir(t *testing.T) {
|
|||
t.Errorf("%s: mode is not directory", dirName)
|
||||
}
|
||||
|
||||
if info.Mode() != os.ModeDir|0755 {
|
||||
if info.Mode() != os.ModeDir|0o755 {
|
||||
t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", dirName, info.Mode())
|
||||
}
|
||||
|
||||
|
@ -754,7 +754,7 @@ func TestGcsMkdirAll(t *testing.T) {
|
|||
t.Run("empty", func(t *testing.T) {
|
||||
emptyDirName := bucketName
|
||||
|
||||
err := gcsAfs.MkdirAll(emptyDirName, 0755)
|
||||
err := gcsAfs.MkdirAll(emptyDirName, 0o755)
|
||||
if err == nil {
|
||||
t.Fatal("did not fail upon creation of an empty folder")
|
||||
}
|
||||
|
@ -762,7 +762,7 @@ func TestGcsMkdirAll(t *testing.T) {
|
|||
t.Run("success", func(t *testing.T) {
|
||||
dirName := filepath.Join(bucketName, "a/b/c")
|
||||
|
||||
err := gcsAfs.MkdirAll(dirName, 0755)
|
||||
err := gcsAfs.MkdirAll(dirName, 0o755)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ func TestGcsMkdirAll(t *testing.T) {
|
|||
if !info.Mode().IsDir() {
|
||||
t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a"))
|
||||
}
|
||||
if info.Mode() != os.ModeDir|0755 {
|
||||
if info.Mode() != os.ModeDir|0o755 {
|
||||
t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a"), info.Mode())
|
||||
}
|
||||
info, err = gcsAfs.Stat(filepath.Join(bucketName, "a/b"))
|
||||
|
@ -784,7 +784,7 @@ func TestGcsMkdirAll(t *testing.T) {
|
|||
if !info.Mode().IsDir() {
|
||||
t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a/b"))
|
||||
}
|
||||
if info.Mode() != os.ModeDir|0755 {
|
||||
if info.Mode() != os.ModeDir|0o755 {
|
||||
t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a/b"), info.Mode())
|
||||
}
|
||||
info, err = gcsAfs.Stat(dirName)
|
||||
|
@ -794,7 +794,7 @@ func TestGcsMkdirAll(t *testing.T) {
|
|||
if !info.Mode().IsDir() {
|
||||
t.Errorf("%s: mode is not directory", dirName)
|
||||
}
|
||||
if info.Mode() != os.ModeDir|0755 {
|
||||
if info.Mode() != os.ModeDir|0o755 {
|
||||
t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", dirName, info.Mode())
|
||||
}
|
||||
|
||||
|
@ -816,7 +816,7 @@ func TestGcsRemoveAll(t *testing.T) {
|
|||
aDir := filepath.Join(bucketName, "a")
|
||||
bDir := filepath.Join(aDir, "b")
|
||||
|
||||
err := gcsAfs.MkdirAll(bDir, 0755)
|
||||
err := gcsAfs.MkdirAll(bDir, 0o755)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/spf13/afero
|
||||
module git.internal/re/afero
|
||||
|
||||
require (
|
||||
cloud.google.com/go/storage v1.14.0
|
||||
|
|
2
iofs.go
2
iofs.go
|
@ -11,7 +11,7 @@ import (
|
|||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero/internal/common"
|
||||
"git.internal/re/afero/internal/common"
|
||||
)
|
||||
|
||||
// IOFS adopts afero.Fs to stdlib io/fs.FS
|
||||
|
|
15
iofs_test.go
15
iofs_test.go
|
@ -17,7 +17,7 @@ import (
|
|||
"testing/fstest"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero/internal/common"
|
||||
"git.internal/re/afero/internal/common"
|
||||
)
|
||||
|
||||
func TestIOFS(t *testing.T) {
|
||||
|
@ -66,7 +66,6 @@ func TestIOFS(t *testing.T) {
|
|||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestIOFSNativeDirEntryWhenPossible(t *testing.T) {
|
||||
|
@ -145,7 +144,6 @@ func TestIOFSNativeDirEntryWhenPossible(t *testing.T) {
|
|||
}
|
||||
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -155,7 +153,6 @@ func TestIOFSNativeDirEntryWhenPossible(t *testing.T) {
|
|||
if fileCount != numFiles {
|
||||
t.Fatalf("expected %d, got %d", numFiles, fileCount)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFromIOFS(t *testing.T) {
|
||||
|
@ -360,7 +357,6 @@ func TestFromIOFS_File(t *testing.T) {
|
|||
// MapFS files implements io.ReaderAt
|
||||
b := make([]byte, 2)
|
||||
_, err := file.ReadAt(b, 2)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("ReadAt failed: %v", err)
|
||||
return
|
||||
|
@ -420,7 +416,7 @@ func TestFromIOFS_File(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
var expectedItems = []struct {
|
||||
expectedItems := []struct {
|
||||
Name string
|
||||
IsDir bool
|
||||
Size int64
|
||||
|
@ -472,7 +468,7 @@ func TestFromIOFS_File(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
var expectedItems = []string{"dir1", "dir2", "test.txt"}
|
||||
expectedItems := []string{"dir1", "dir2", "test.txt"}
|
||||
|
||||
if len(expectedItems) != len(items) {
|
||||
t.Errorf("Items count mismatch, expected %d, got %d", len(expectedItems), len(items))
|
||||
|
@ -530,7 +526,7 @@ func BenchmarkWalkDir(b *testing.B) {
|
|||
dirname := ""
|
||||
for i := 0; i < level; i++ {
|
||||
dirname = filepath.Join(dirname, fmt.Sprintf("dir%d", i))
|
||||
err := osfs.MkdirAll(dirname, 0755)
|
||||
err := osfs.MkdirAll(dirname, 0o755)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
@ -547,12 +543,9 @@ func BenchmarkWalkDir(b *testing.B) {
|
|||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero/internal/common"
|
||||
"git.internal/re/afero/internal/common"
|
||||
)
|
||||
|
||||
const FilePathSeparator = string(filepath.Separator)
|
||||
|
@ -245,7 +245,7 @@ func (f *File) Truncate(size int64) error {
|
|||
defer f.fileData.Unlock()
|
||||
if 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 {
|
||||
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):]
|
||||
}
|
||||
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...)
|
||||
} else {
|
||||
f.fileData.data = append(f.fileData.data[:cur], b...)
|
||||
|
@ -321,16 +321,19 @@ func (s *FileInfo) Name() string {
|
|||
s.Unlock()
|
||||
return name
|
||||
}
|
||||
|
||||
func (s *FileInfo) Mode() os.FileMode {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.mode
|
||||
}
|
||||
|
||||
func (s *FileInfo) ModTime() time.Time {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.modtime
|
||||
}
|
||||
|
||||
func (s *FileInfo) IsDir() bool {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
|
|
@ -66,8 +66,8 @@ func TestFileDataModTimeRace(t *testing.T) {
|
|||
|
||||
func TestFileDataModeRace(t *testing.T) {
|
||||
t.Parallel()
|
||||
const someMode = 0777
|
||||
const someOtherMode = 0660
|
||||
const someMode = 0o777
|
||||
const someOtherMode = 0o660
|
||||
|
||||
d := FileData{
|
||||
mode: someMode,
|
||||
|
@ -95,7 +95,7 @@ func TestFileDataModeRace(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// See https://github.com/spf13/afero/issues/286.
|
||||
// See https://git.internal/re/afero/issues/286.
|
||||
func TestFileWriteAt(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
@ -167,7 +167,7 @@ func TestFileDataIsDirRace(t *testing.T) {
|
|||
s.Unlock()
|
||||
}()
|
||||
|
||||
//just logging the value to trigger a read:
|
||||
// just logging the value to trigger a read:
|
||||
t.Logf("Value is %v", s.IsDir())
|
||||
}
|
||||
|
||||
|
@ -196,10 +196,10 @@ func TestFileDataSizeRace(t *testing.T) {
|
|||
s.Unlock()
|
||||
}()
|
||||
|
||||
//just logging the value to trigger a read:
|
||||
// just logging the value to trigger a read:
|
||||
t.Logf("Value is %v", s.Size())
|
||||
|
||||
//Testing the Dir size case
|
||||
// Testing the Dir size case
|
||||
d.dir = true
|
||||
if s.Size() != int64(42) {
|
||||
t.Errorf("Failed to read correct value for dir, was %v", s.Size())
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero/mem"
|
||||
"git.internal/re/afero/mem"
|
||||
)
|
||||
|
||||
const chmodBits = os.ModePerm | os.ModeSetuid | os.ModeSetgid | os.ModeSticky // Only a subset of bits are allowed to be changed. Documented under os.Chmod()
|
||||
|
@ -43,7 +43,7 @@ func (m *MemMapFs) getData() map[string]*mem.FileData {
|
|||
// Root should always exist, right?
|
||||
// TODO: what about windows?
|
||||
root := mem.CreateDir(FilePathSeparator)
|
||||
mem.SetMode(root, os.ModeDir|0755)
|
||||
mem.SetMode(root, os.ModeDir|0o755)
|
||||
m.data[FilePathSeparator] = root
|
||||
})
|
||||
return m.data
|
||||
|
@ -96,12 +96,12 @@ func (m *MemMapFs) registerWithParent(f *mem.FileData, perm os.FileMode) {
|
|||
pdir := filepath.Dir(filepath.Clean(f.Name()))
|
||||
err := m.lockfreeMkdir(pdir, perm)
|
||||
if err != nil {
|
||||
//log.Println("Mkdir error:", err)
|
||||
// log.Println("Mkdir error:", err)
|
||||
return
|
||||
}
|
||||
parent, err = m.lockfreeOpen(pdir)
|
||||
if err != nil {
|
||||
//log.Println("Open after Mkdir error:", err)
|
||||
// log.Println("Open after Mkdir error:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"git.internal/re/afero"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
// Fs is a afero.Fs implementation that uses functions provided by the sftp package.
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"sort"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"git.internal/re/afero"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"git.internal/re/afero"
|
||||
)
|
||||
|
||||
type Fs struct {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"git.internal/re/afero"
|
||||
)
|
||||
|
||||
var files = []struct {
|
||||
|
@ -161,7 +161,7 @@ func TestSeek(t *testing.T) {
|
|||
t.Fatalf("opening %v: %v", f.name, err)
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
tests := []struct {
|
||||
offin int64
|
||||
whence int
|
||||
offout int64
|
||||
|
@ -252,7 +252,7 @@ func TestClose(t *testing.T) {
|
|||
|
||||
func TestOpenFile(t *testing.T) {
|
||||
for _, f := range files {
|
||||
file, err := afs.OpenFile(f.name, os.O_RDONLY, 0400)
|
||||
file, err := afs.OpenFile(f.name, os.O_RDONLY, 0o400)
|
||||
if !f.exists {
|
||||
if !errors.Is(err, syscall.ENOENT) {
|
||||
t.Errorf("%v: got %v, expected%v", f.name, err, syscall.ENOENT)
|
||||
|
@ -266,7 +266,7 @@ func TestOpenFile(t *testing.T) {
|
|||
}
|
||||
file.Close()
|
||||
|
||||
_, err = afs.OpenFile(f.name, os.O_CREATE, 0600)
|
||||
_, err = afs.OpenFile(f.name, os.O_CREATE, 0o600)
|
||||
if !errors.Is(err, syscall.EPERM) {
|
||||
t.Errorf("%v: open for write: got %v, expected %v", f.name, err, syscall.EPERM)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"git.internal/re/afero"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
"git.internal/re/afero"
|
||||
)
|
||||
|
||||
type Fs struct {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package zipfs
|
||||
|
||||
import (
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"archive/zip"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.internal/re/afero"
|
||||
)
|
||||
|
||||
func TestZipFS(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue