fix repos

This commit is contained in:
re 2022-12-12 18:01:24 +03:00
parent a800a9de53
commit 1707ad0dd8
19 changed files with 88 additions and 79 deletions

View File

@ -2,7 +2,7 @@
A FileSystem Abstraction System for Go 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 # 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. 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. Next include Afero in your application.
```go ```go
import "github.com/spf13/afero" import "git.internal/re/afero"
``` ```
## Step 2: Declare a backend ## 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 WriteFile(filename string, data []byte, perm os.FileMode) error
WriteReader(path string, r io.Reader) (err 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 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 them directly where the first parameter of each function will be the file
@ -417,7 +417,7 @@ Googles very well.
## Release Notes ## Release Notes
See the [Releases Page](https://github.com/spf13/afero/releases). See the [Releases Page](https://git.internal/re/afero/releases).
## Contributing ## Contributing
@ -439,4 +439,4 @@ Names in no particular order:
## License ## License
Afero is released under the Apache 2.0 license. See 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)

View File

@ -28,8 +28,10 @@ import (
"testing" "testing"
) )
var testName = "test.txt" var (
var Fss = []Fs{&MemMapFs{}, &OsFs{}} testName = "test.txt"
Fss = []Fs{&MemMapFs{}, &OsFs{}}
)
var testRegistry map[Fs][]string = make(map[Fs][]string) var testRegistry map[Fs][]string = make(map[Fs][]string)
@ -45,7 +47,6 @@ func testDir(fs Fs) string {
func tmpFile(fs Fs) File { func tmpFile(fs Fs) File {
x, err := TempFile(fs, "", "afero") x, err := TempFile(fs, "", "afero")
if err != nil { if err != nil {
panic(fmt.Sprint("unable to work with temp file", err)) panic(fmt.Sprint("unable to work with temp file", err))
} }
@ -55,7 +56,7 @@ func tmpFile(fs Fs) File {
return x return x
} }
//Read with length 0 should not return EOF. // Read with length 0 should not return EOF.
func TestRead0(t *testing.T) { func TestRead0(t *testing.T) {
for _, fs := range Fss { for _, fs := range Fss {
f := tmpFile(fs) f := tmpFile(fs)
@ -83,7 +84,7 @@ func TestOpenFile(t *testing.T) {
tmp := testDir(fs) tmp := testDir(fs)
path := filepath.Join(tmp, testName) 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 { if err != nil {
t.Error(fs.Name(), "OpenFile (O_CREATE) failed:", err) t.Error(fs.Name(), "OpenFile (O_CREATE) failed:", err)
continue continue
@ -91,7 +92,7 @@ func TestOpenFile(t *testing.T) {
io.WriteString(f, "initial") io.WriteString(f, "initial")
f.Close() 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 { if err != nil {
t.Error(fs.Name(), "OpenFile (O_APPEND) failed:", err) t.Error(fs.Name(), "OpenFile (O_APPEND) failed:", err)
continue continue
@ -99,7 +100,7 @@ func TestOpenFile(t *testing.T) {
io.WriteString(f, "|append") io.WriteString(f, "|append")
f.Close() f.Close()
f, _ = fs.OpenFile(path, os.O_RDONLY, 0600) f, _ = fs.OpenFile(path, os.O_RDONLY, 0o600)
contents, _ := ioutil.ReadAll(f) contents, _ := ioutil.ReadAll(f)
expectedContents := "initial|append" expectedContents := "initial|append"
if string(contents) != expectedContents { if string(contents) != expectedContents {
@ -107,7 +108,7 @@ func TestOpenFile(t *testing.T) {
} }
f.Close() 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 { if err != nil {
t.Error(fs.Name(), "OpenFile (O_TRUNC) failed:", err) t.Error(fs.Name(), "OpenFile (O_TRUNC) failed:", err)
continue continue
@ -333,7 +334,7 @@ func TestSeek(t *testing.T) {
whence int whence int
out int64 out int64
} }
var tests = []test{ tests := []test{
{0, 1, int64(len(data))}, {0, 1, int64(len(data))},
{0, 0, 0}, {0, 0, 0},
{5, 0, 5}, {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 { func setupTestFiles(t *testing.T, fs Fs, path string) string {
testSubDir := filepath.Join(path, "more", "subdirectories", "for", "testing", "we") 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) { if err != nil && !os.IsExist(err) {
t.Fatal(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) { func TestReaddirRegularFile(t *testing.T) {
defer removeAllTestFiles(t) defer removeAllTestFiles(t)
for _, fs := range Fss { for _, fs := range Fss {
@ -637,7 +638,7 @@ func TestReaddirAll(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
var namesRoot = []string{} namesRoot := []string{}
for _, e := range rootInfo { for _, e := range rootInfo {
namesRoot = append(namesRoot, e.Name()) namesRoot = append(namesRoot, e.Name())
} }
@ -652,7 +653,7 @@ func TestReaddirAll(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
var namesSub = []string{} namesSub := []string{}
for _, e := range subInfo { for _, e := range subInfo {
namesSub = append(namesSub, e.Name()) namesSub = append(namesSub, e.Name())
} }

View File

@ -16,9 +16,9 @@ func TestCopyOnWrite(t *testing.T) {
compositeFs := NewCopyOnWriteFs(NewReadOnlyFs(NewOsFs()), osFs) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -27,17 +27,17 @@ func TestCopyOnWrite(t *testing.T) {
t.Fatal(err) 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 // We want the composite file system to behave like the OS file system
// on Mkdir and MkdirAll // on Mkdir and MkdirAll
for _, fs := range []Fs{osFs, compositeFs} { for _, fs := range []Fs{osFs, compositeFs} {
err = fs.Mkdir(dir, 0744) err = fs.Mkdir(dir, 0o744)
if err == nil || !os.IsExist(err) { if err == nil || !os.IsExist(err) {
t.Errorf("Mkdir: Got %q for %T", err, fs) t.Errorf("Mkdir: Got %q for %T", err, fs)
} }
// MkdirAll does not return an error when the directory already exists // MkdirAll does not return an error when the directory already exists
err = fs.MkdirAll(dir, 0744) err = fs.MkdirAll(dir, 0o744)
if err != nil { if err != nil {
t.Errorf("MkdirAll: Got %q for %T", err, fs) t.Errorf("MkdirAll: Got %q for %T", err, fs)
} }
@ -49,7 +49,7 @@ func TestCopyOnWriteFileInMemMapBase(t *testing.T) {
base := &MemMapFs{} base := &MemMapFs{}
layer := &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) t.Fatalf("Failed to write file: %s", err)
} }

View File

@ -22,8 +22,8 @@ import (
"time" "time"
"cloud.google.com/go/storage" "cloud.google.com/go/storage"
"git.internal/re/afero"
"github.com/googleapis/google-cloud-go-testing/storage/stiface" "github.com/googleapis/google-cloud-go-testing/storage/stiface"
"github.com/spf13/afero"
"google.golang.org/api/option" "google.golang.org/api/option"
) )
@ -76,39 +76,51 @@ func NewGcsFSFromClientWithSeparator(ctx context.Context, client *storage.Client
func (fs *GcsFs) Name() string { func (fs *GcsFs) Name() string {
return fs.source.Name() return fs.source.Name()
} }
func (fs *GcsFs) Create(name string) (afero.File, error) { func (fs *GcsFs) Create(name string) (afero.File, error) {
return fs.source.Create(name) return fs.source.Create(name)
} }
func (fs *GcsFs) Mkdir(name string, perm os.FileMode) error { func (fs *GcsFs) Mkdir(name string, perm os.FileMode) error {
return fs.source.Mkdir(name, perm) return fs.source.Mkdir(name, perm)
} }
func (fs *GcsFs) MkdirAll(path string, perm os.FileMode) error { func (fs *GcsFs) MkdirAll(path string, perm os.FileMode) error {
return fs.source.MkdirAll(path, perm) return fs.source.MkdirAll(path, perm)
} }
func (fs *GcsFs) Open(name string) (afero.File, error) { func (fs *GcsFs) Open(name string) (afero.File, error) {
return fs.source.Open(name) return fs.source.Open(name)
} }
func (fs *GcsFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) { func (fs *GcsFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
return fs.source.OpenFile(name, flag, perm) return fs.source.OpenFile(name, flag, perm)
} }
func (fs *GcsFs) Remove(name string) error { func (fs *GcsFs) Remove(name string) error {
return fs.source.Remove(name) return fs.source.Remove(name)
} }
func (fs *GcsFs) RemoveAll(path string) error { func (fs *GcsFs) RemoveAll(path string) error {
return fs.source.RemoveAll(path) return fs.source.RemoveAll(path)
} }
func (fs *GcsFs) Rename(oldname, newname string) error { func (fs *GcsFs) Rename(oldname, newname string) error {
return fs.source.Rename(oldname, newname) return fs.source.Rename(oldname, newname)
} }
func (fs *GcsFs) Stat(name string) (os.FileInfo, error) { func (fs *GcsFs) Stat(name string) (os.FileInfo, error) {
return fs.source.Stat(name) return fs.source.Stat(name)
} }
func (fs *GcsFs) Chmod(name string, mode os.FileMode) error { func (fs *GcsFs) Chmod(name string, mode os.FileMode) error {
return fs.source.Chmod(name, mode) return fs.source.Chmod(name, mode)
} }
func (fs *GcsFs) Chtimes(name string, atime time.Time, mtime time.Time) error { func (fs *GcsFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
return fs.source.Chtimes(name, atime, mtime) return fs.source.Chtimes(name, atime, mtime)
} }
func (fs *GcsFs) Chown(name string, uid, gid int) error { func (fs *GcsFs) Chown(name string, uid, gid int) error {
return fs.source.Chown(name, uid, gid) return fs.source.Chown(name, uid, gid)
} }

View File

@ -18,8 +18,8 @@ import (
"strings" "strings"
"cloud.google.com/go/storage" "cloud.google.com/go/storage"
"git.internal/re/afero"
"github.com/googleapis/google-cloud-go-testing/storage/stiface" "github.com/googleapis/google-cloud-go-testing/storage/stiface"
"github.com/spf13/afero"
"google.golang.org/api/iterator" "google.golang.org/api/iterator"
) )
@ -166,7 +166,7 @@ func (w *writerMock) Close() error {
if w.file == nil { if w.file == nil {
var err error var err error
if strings.HasSuffix(w.name, "/") { if strings.HasSuffix(w.name, "/") {
err = w.fs.Mkdir(w.name, 0755) err = w.fs.Mkdir(w.name, 0o755)
if err != nil { if err != nil {
return err return err
} }

View File

@ -20,8 +20,8 @@ import (
"golang.org/x/oauth2/google" "golang.org/x/oauth2/google"
"cloud.google.com/go/storage" "cloud.google.com/go/storage"
"git.internal/re/afero"
"github.com/googleapis/google-cloud-go-testing/storage/stiface" "github.com/googleapis/google-cloud-go-testing/storage/stiface"
"github.com/spf13/afero"
) )
const ( const (
@ -122,7 +122,7 @@ func TestMain(m *testing.M) {
gcsAfs = &afero.Afero{Fs: &GcsFs{NewGcsFs(ctx, mockClient)}} gcsAfs = &afero.Afero{Fs: &GcsFs{NewGcsFs(ctx, mockClient)}}
// Uncomment to use the real, not mocked, client // 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() exitCode = m.Run()
} }
@ -341,7 +341,7 @@ func TestGcsSeek(t *testing.T) {
t.Fatalf("opening %v: %v", name, err) t.Fatalf("opening %v: %v", name, err)
} }
var tests = []struct { tests := []struct {
offIn int64 offIn int64
whence int whence int
offOut int64 offOut int64
@ -477,7 +477,7 @@ func TestGcsOpenFile(t *testing.T) {
} }
for _, name := range names { 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.exists {
if (f.name != "" && !errors.Is(err, syscall.ENOENT)) || if (f.name != "" && !errors.Is(err, syscall.ENOENT)) ||
(f.name == "" && !errors.Is(err, ErrNoBucketInName)) { (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) 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) { if !errors.Is(err, syscall.EPERM) {
t.Errorf("%v: open for write: got %v, expected %v", name, 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) { t.Run("empty", func(t *testing.T) {
emptyDirName := bucketName emptyDirName := bucketName
err := gcsAfs.Mkdir(emptyDirName, 0755) err := gcsAfs.Mkdir(emptyDirName, 0o755)
if err == nil { if err == nil {
t.Fatal("did not fail upon creation of an empty folder") 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") dirName := filepath.Join(bucketName, "a-test-dir")
var err error var err error
err = gcsAfs.Mkdir(dirName, 0755) err = gcsAfs.Mkdir(dirName, 0o755)
if err != nil { if err != nil {
t.Fatal("failed to create a folder with error", err) 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) 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()) 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) { t.Run("empty", func(t *testing.T) {
emptyDirName := bucketName emptyDirName := bucketName
err := gcsAfs.MkdirAll(emptyDirName, 0755) err := gcsAfs.MkdirAll(emptyDirName, 0o755)
if err == nil { if err == nil {
t.Fatal("did not fail upon creation of an empty folder") 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) { t.Run("success", func(t *testing.T) {
dirName := filepath.Join(bucketName, "a/b/c") dirName := filepath.Join(bucketName, "a/b/c")
err := gcsAfs.MkdirAll(dirName, 0755) err := gcsAfs.MkdirAll(dirName, 0o755)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -774,7 +774,7 @@ func TestGcsMkdirAll(t *testing.T) {
if !info.Mode().IsDir() { if !info.Mode().IsDir() {
t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a")) 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()) 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")) info, err = gcsAfs.Stat(filepath.Join(bucketName, "a/b"))
@ -784,7 +784,7 @@ func TestGcsMkdirAll(t *testing.T) {
if !info.Mode().IsDir() { if !info.Mode().IsDir() {
t.Errorf("%s: mode is not directory", filepath.Join(bucketName, "a/b")) 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()) t.Errorf("%s: wrong permissions, expected drwxr-xr-x, got %s", filepath.Join(bucketName, "a/b"), info.Mode())
} }
info, err = gcsAfs.Stat(dirName) info, err = gcsAfs.Stat(dirName)
@ -794,7 +794,7 @@ func TestGcsMkdirAll(t *testing.T) {
if !info.Mode().IsDir() { if !info.Mode().IsDir() {
t.Errorf("%s: mode is not directory", dirName) 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()) 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") aDir := filepath.Join(bucketName, "a")
bDir := filepath.Join(aDir, "b") bDir := filepath.Join(aDir, "b")
err := gcsAfs.MkdirAll(bDir, 0755) err := gcsAfs.MkdirAll(bDir, 0o755)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/spf13/afero module git.internal/re/afero
require ( require (
cloud.google.com/go/storage v1.14.0 cloud.google.com/go/storage v1.14.0

View File

@ -11,7 +11,7 @@ import (
"sort" "sort"
"time" "time"
"github.com/spf13/afero/internal/common" "git.internal/re/afero/internal/common"
) )
// IOFS adopts afero.Fs to stdlib io/fs.FS // IOFS adopts afero.Fs to stdlib io/fs.FS

View File

@ -17,7 +17,7 @@ import (
"testing/fstest" "testing/fstest"
"time" "time"
"github.com/spf13/afero/internal/common" "git.internal/re/afero/internal/common"
) )
func TestIOFS(t *testing.T) { func TestIOFS(t *testing.T) {
@ -66,7 +66,6 @@ func TestIOFS(t *testing.T) {
t.Error(err) t.Error(err)
} }
}) })
} }
func TestIOFSNativeDirEntryWhenPossible(t *testing.T) { func TestIOFSNativeDirEntryWhenPossible(t *testing.T) {
@ -145,7 +144,6 @@ func TestIOFSNativeDirEntryWhenPossible(t *testing.T) {
} }
return nil return nil
}) })
if err != nil { if err != nil {
@ -155,7 +153,6 @@ func TestIOFSNativeDirEntryWhenPossible(t *testing.T) {
if fileCount != numFiles { if fileCount != numFiles {
t.Fatalf("expected %d, got %d", numFiles, fileCount) t.Fatalf("expected %d, got %d", numFiles, fileCount)
} }
} }
func TestFromIOFS(t *testing.T) { func TestFromIOFS(t *testing.T) {
@ -360,7 +357,6 @@ func TestFromIOFS_File(t *testing.T) {
// MapFS files implements io.ReaderAt // MapFS files implements io.ReaderAt
b := make([]byte, 2) b := make([]byte, 2)
_, err := file.ReadAt(b, 2) _, err := file.ReadAt(b, 2)
if err != nil { if err != nil {
t.Errorf("ReadAt failed: %v", err) t.Errorf("ReadAt failed: %v", err)
return return
@ -420,7 +416,7 @@ func TestFromIOFS_File(t *testing.T) {
return return
} }
var expectedItems = []struct { expectedItems := []struct {
Name string Name string
IsDir bool IsDir bool
Size int64 Size int64
@ -472,7 +468,7 @@ func TestFromIOFS_File(t *testing.T) {
return return
} }
var expectedItems = []string{"dir1", "dir2", "test.txt"} expectedItems := []string{"dir1", "dir2", "test.txt"}
if len(expectedItems) != len(items) { if len(expectedItems) != len(items) {
t.Errorf("Items count mismatch, expected %d, got %d", 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 := "" dirname := ""
for i := 0; i < level; i++ { for i := 0; i < level; i++ {
dirname = filepath.Join(dirname, fmt.Sprintf("dir%d", 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) { if err != nil && !os.IsExist(err) {
b.Fatal(err) b.Fatal(err)
} }
@ -547,12 +543,9 @@ func BenchmarkWalkDir(b *testing.B) {
return err return err
} }
return nil return nil
}) })
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
} }
} }

View File

@ -25,7 +25,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/spf13/afero/internal/common" "git.internal/re/afero/internal/common"
) )
const FilePathSeparator = string(filepath.Separator) const FilePathSeparator = string(filepath.Separator)
@ -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

@ -66,8 +66,8 @@ func TestFileDataModTimeRace(t *testing.T) {
func TestFileDataModeRace(t *testing.T) { func TestFileDataModeRace(t *testing.T) {
t.Parallel() t.Parallel()
const someMode = 0777 const someMode = 0o777
const someOtherMode = 0660 const someOtherMode = 0o660
d := FileData{ d := FileData{
mode: someMode, 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) { func TestFileWriteAt(t *testing.T) {
t.Parallel() t.Parallel()
@ -167,7 +167,7 @@ func TestFileDataIsDirRace(t *testing.T) {
s.Unlock() 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()) t.Logf("Value is %v", s.IsDir())
} }
@ -196,10 +196,10 @@ func TestFileDataSizeRace(t *testing.T) {
s.Unlock() 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()) t.Logf("Value is %v", s.Size())
//Testing the Dir size case // Testing the Dir size case
d.dir = true d.dir = true
if s.Size() != int64(42) { if s.Size() != int64(42) {
t.Errorf("Failed to read correct value for dir, was %v", s.Size()) t.Errorf("Failed to read correct value for dir, was %v", s.Size())

View File

@ -22,7 +22,7 @@ import (
"sync" "sync"
"time" "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() 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? // 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 +96,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
} }
} }

View File

@ -17,8 +17,8 @@ import (
"os" "os"
"time" "time"
"git.internal/re/afero"
"github.com/pkg/sftp" "github.com/pkg/sftp"
"github.com/spf13/afero"
) )
// Fs is a afero.Fs implementation that uses functions provided by the sftp package. // Fs is a afero.Fs implementation that uses functions provided by the sftp package.

View File

@ -8,7 +8,7 @@ import (
"sort" "sort"
"syscall" "syscall"
"github.com/spf13/afero" "git.internal/re/afero"
) )
type File struct { type File struct {

View File

@ -10,7 +10,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/spf13/afero" "git.internal/re/afero"
) )
type Fs struct { type Fs struct {

View File

@ -13,7 +13,7 @@ import (
"syscall" "syscall"
"testing" "testing"
"github.com/spf13/afero" "git.internal/re/afero"
) )
var files = []struct { var files = []struct {
@ -161,7 +161,7 @@ func TestSeek(t *testing.T) {
t.Fatalf("opening %v: %v", f.name, err) t.Fatalf("opening %v: %v", f.name, err)
} }
var tests = []struct { tests := []struct {
offin int64 offin int64
whence int whence int
offout int64 offout int64
@ -252,7 +252,7 @@ func TestClose(t *testing.T) {
func TestOpenFile(t *testing.T) { func TestOpenFile(t *testing.T) {
for _, f := range files { 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 !f.exists {
if !errors.Is(err, syscall.ENOENT) { if !errors.Is(err, syscall.ENOENT) {
t.Errorf("%v: got %v, expected%v", f.name, 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() 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) { if !errors.Is(err, syscall.EPERM) {
t.Errorf("%v: open for write: got %v, expected %v", f.name, err, syscall.EPERM) t.Errorf("%v: open for write: got %v, expected %v", f.name, err, syscall.EPERM)
} }

View File

@ -7,7 +7,7 @@ import (
"path/filepath" "path/filepath"
"syscall" "syscall"
"github.com/spf13/afero" "git.internal/re/afero"
) )
type File struct { type File struct {

View File

@ -7,7 +7,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/spf13/afero" "git.internal/re/afero"
) )
type Fs struct { type Fs struct {

View File

@ -1,12 +1,12 @@
package zipfs package zipfs
import ( import (
"github.com/spf13/afero"
"archive/zip" "archive/zip"
"path/filepath" "path/filepath"
"reflect" "reflect"
"testing" "testing"
"git.internal/re/afero"
) )
func TestZipFS(t *testing.T) { func TestZipFS(t *testing.T) {