mirror of https://github.com/spf13/afero.git
making the fs property accessible Afero.fs -> Afero.Fs
This commit is contained in:
parent
2affd36eba
commit
30bd450c02
2
afero.go
2
afero.go
|
@ -30,7 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Afero struct {
|
type Afero struct {
|
||||||
fs Fs
|
Fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// File represents a file in the filesystem.
|
// File represents a file in the filesystem.
|
||||||
|
|
10
ioutil.go
10
ioutil.go
|
@ -36,7 +36,7 @@ func (f byName) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||||
// ReadDir reads the directory named by dirname and returns
|
// ReadDir reads the directory named by dirname and returns
|
||||||
// a list of sorted directory entries.
|
// a list of sorted directory entries.
|
||||||
func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error) {
|
func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error) {
|
||||||
return ReadDir(a.fs, dirname)
|
return ReadDir(a.Fs, dirname)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadDir(fs Fs, dirname string) ([]os.FileInfo, error) {
|
func ReadDir(fs Fs, dirname string) ([]os.FileInfo, error) {
|
||||||
|
@ -58,7 +58,7 @@ func ReadDir(fs Fs, dirname string) ([]os.FileInfo, error) {
|
||||||
// reads the whole file, it does not treat an EOF from Read as an error
|
// reads the whole file, it does not treat an EOF from Read as an error
|
||||||
// to be reported.
|
// to be reported.
|
||||||
func (a Afero) ReadFile(filename string) ([]byte, error) {
|
func (a Afero) ReadFile(filename string) ([]byte, error) {
|
||||||
return ReadFile(a.fs, filename)
|
return ReadFile(a.Fs, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadFile(fs Fs, filename string) ([]byte, error) {
|
func ReadFile(fs Fs, filename string) ([]byte, error) {
|
||||||
|
@ -118,7 +118,7 @@ func ReadAll(r io.Reader) ([]byte, error) {
|
||||||
// If the file does not exist, WriteFile creates it with permissions perm;
|
// If the file does not exist, WriteFile creates it with permissions perm;
|
||||||
// otherwise WriteFile truncates it before writing.
|
// otherwise WriteFile truncates it before writing.
|
||||||
func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error {
|
func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error {
|
||||||
return WriteFile(a.fs, filename, data, perm)
|
return WriteFile(a.Fs, filename, data, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteFile(fs Fs, filename string, data []byte, perm os.FileMode) error {
|
func WriteFile(fs Fs, filename string, data []byte, perm os.FileMode) error {
|
||||||
|
@ -169,7 +169,7 @@ func nextSuffix() string {
|
||||||
// to find the pathname of the file. It is the caller's responsibility
|
// to find the pathname of the file. It is the caller's responsibility
|
||||||
// to remove the file when no longer needed.
|
// to remove the file when no longer needed.
|
||||||
func (a Afero) TempFile(dir, prefix string) (f File, err error) {
|
func (a Afero) TempFile(dir, prefix string) (f File, err error) {
|
||||||
return TempFile(a.fs, dir, prefix)
|
return TempFile(a.Fs, dir, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TempFile(fs Fs, dir, prefix string) (f File, err error) {
|
func TempFile(fs Fs, dir, prefix string) (f File, err error) {
|
||||||
|
@ -202,7 +202,7 @@ func TempFile(fs Fs, dir, prefix string) (f File, err error) {
|
||||||
// will not choose the same directory. It is the caller's responsibility
|
// will not choose the same directory. It is the caller's responsibility
|
||||||
// to remove the directory when no longer needed.
|
// to remove the directory when no longer needed.
|
||||||
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 == "" {
|
||||||
|
|
|
@ -29,7 +29,7 @@ func checkSizePath(t *testing.T, path string, size int64) {
|
||||||
|
|
||||||
func TestReadFile(t *testing.T) {
|
func TestReadFile(t *testing.T) {
|
||||||
testFS = &MemMapFs{}
|
testFS = &MemMapFs{}
|
||||||
fsutil := &Afero{fs: testFS}
|
fsutil := &Afero{Fs: testFS}
|
||||||
|
|
||||||
testFS.Create("this_exists.go")
|
testFS.Create("this_exists.go")
|
||||||
filename := "rumpelstilzchen"
|
filename := "rumpelstilzchen"
|
||||||
|
@ -49,7 +49,7 @@ func TestReadFile(t *testing.T) {
|
||||||
|
|
||||||
func TestWriteFile(t *testing.T) {
|
func TestWriteFile(t *testing.T) {
|
||||||
testFS = &MemMapFs{}
|
testFS = &MemMapFs{}
|
||||||
fsutil := &Afero{fs: testFS}
|
fsutil := &Afero{Fs: testFS}
|
||||||
f, err := fsutil.TempFile("", "ioutil-test")
|
f, err := fsutil.TempFile("", "ioutil-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
2
path.go
2
path.go
|
@ -96,7 +96,7 @@ func lstatIfOs(fs Fs, path string) (info os.FileInfo, err error) {
|
||||||
// Walk does not follow symbolic links.
|
// Walk does not follow symbolic links.
|
||||||
|
|
||||||
func (a Afero) Walk(root string, walkFn filepath.WalkFunc) error {
|
func (a Afero) Walk(root string, walkFn filepath.WalkFunc) error {
|
||||||
return Walk(a.fs, root, walkFn)
|
return Walk(a.Fs, root, walkFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error {
|
func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error {
|
||||||
|
|
16
util.go
16
util.go
|
@ -35,7 +35,7 @@ const FilePathSeparator = string(filepath.Separator)
|
||||||
|
|
||||||
// Takes a reader and a path and writes the content
|
// Takes a reader and a path and writes the content
|
||||||
func (a Afero) WriteReader(path string, r io.Reader) (err error) {
|
func (a Afero) WriteReader(path string, r io.Reader) (err error) {
|
||||||
return WriteReader(a.fs, path, r)
|
return WriteReader(a.Fs, path, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteReader(fs Fs, path string, r io.Reader) (err error) {
|
func WriteReader(fs Fs, path string, r io.Reader) (err error) {
|
||||||
|
@ -63,7 +63,7 @@ func WriteReader(fs Fs, path string, r io.Reader) (err error) {
|
||||||
|
|
||||||
// Same as WriteReader but checks to see if file/directory already exists.
|
// Same as WriteReader but checks to see if file/directory already exists.
|
||||||
func (a Afero) SafeWriteReader(path string, r io.Reader) (err error) {
|
func (a Afero) SafeWriteReader(path string, r io.Reader) (err error) {
|
||||||
return SafeWriteReader(a.fs, path, r)
|
return SafeWriteReader(a.Fs, path, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SafeWriteReader(fs Fs, path string, r io.Reader) (err error) {
|
func SafeWriteReader(fs Fs, path string, r io.Reader) (err error) {
|
||||||
|
@ -96,7 +96,7 @@ func SafeWriteReader(fs Fs, path string, r io.Reader) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Afero) GetTempDir(subPath string) string {
|
func (a Afero) GetTempDir(subPath string) string {
|
||||||
return GetTempDir(a.fs, subPath)
|
return GetTempDir(a.Fs, subPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTempDir returns the default temp directory with trailing slash
|
// GetTempDir returns the default temp directory with trailing slash
|
||||||
|
@ -170,7 +170,7 @@ func isMn(r rune) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Afero) FileContainsBytes(filename string, subslice []byte) (bool, error) {
|
func (a Afero) FileContainsBytes(filename string, subslice []byte) (bool, error) {
|
||||||
return FileContainsBytes(a.fs, filename, subslice)
|
return FileContainsBytes(a.Fs, filename, subslice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a file contains a specified string.
|
// Check if a file contains a specified string.
|
||||||
|
@ -221,7 +221,7 @@ func readerContains(r io.Reader, subslice []byte) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Afero) DirExists(path string) (bool, error) {
|
func (a Afero) DirExists(path string) (bool, error) {
|
||||||
return DirExists(a.fs, path)
|
return DirExists(a.Fs, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DirExists checks if a path exists and is a directory.
|
// DirExists checks if a path exists and is a directory.
|
||||||
|
@ -237,7 +237,7 @@ func DirExists(fs Fs, path string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Afero) IsDir(path string) (bool, error) {
|
func (a Afero) IsDir(path string) (bool, error) {
|
||||||
return IsDir(a.fs, path)
|
return IsDir(a.Fs, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDir checks if a given path is a directory.
|
// IsDir checks if a given path is a directory.
|
||||||
|
@ -250,7 +250,7 @@ func IsDir(fs Fs, path string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Afero) IsEmpty(path string) (bool, error) {
|
func (a Afero) IsEmpty(path string) (bool, error) {
|
||||||
return IsEmpty(a.fs, path)
|
return IsEmpty(a.Fs, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty checks if a given file or directory is empty.
|
// IsEmpty checks if a given file or directory is empty.
|
||||||
|
@ -275,7 +275,7 @@ func IsEmpty(fs Fs, path string) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Afero) Exists(path string) (bool, error) {
|
func (a Afero) Exists(path string) (bool, error) {
|
||||||
return Exists(a.fs, path)
|
return Exists(a.Fs, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a file or directory exists.
|
// Check if a file or directory exists.
|
||||||
|
|
Loading…
Reference in New Issue