summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/afero
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/afero')
-rw-r--r--vendor/github.com/spf13/afero/.travis.yml3
-rw-r--r--vendor/github.com/spf13/afero/README.md13
-rw-r--r--vendor/github.com/spf13/afero/appveyor.yml2
-rw-r--r--vendor/github.com/spf13/afero/cacheOnReadFs.go9
-rw-r--r--vendor/github.com/spf13/afero/composite_test.go36
-rw-r--r--vendor/github.com/spf13/afero/mem/file.go40
-rw-r--r--vendor/github.com/spf13/afero/mem/file_test.go154
-rw-r--r--vendor/github.com/spf13/afero/memmap.go5
-rw-r--r--vendor/github.com/spf13/afero/memmap_test.go47
-rw-r--r--vendor/github.com/spf13/afero/memradix.go14
-rw-r--r--vendor/github.com/spf13/afero/util.go2
11 files changed, 280 insertions, 45 deletions
diff --git a/vendor/github.com/spf13/afero/.travis.yml b/vendor/github.com/spf13/afero/.travis.yml
index 6c296d293..618159a4e 100644
--- a/vendor/github.com/spf13/afero/.travis.yml
+++ b/vendor/github.com/spf13/afero/.travis.yml
@@ -16,5 +16,6 @@ matrix:
fast_finish: true
script:
- - go test -v ./...
- go build
+ - go test -race -v ./...
+
diff --git a/vendor/github.com/spf13/afero/README.md b/vendor/github.com/spf13/afero/README.md
index d9e332730..0c9b04b53 100644
--- a/vendor/github.com/spf13/afero/README.md
+++ b/vendor/github.com/spf13/afero/README.md
@@ -61,11 +61,11 @@ import "github.com/spf13/afero"
First define a package variable and set it to a pointer to a filesystem.
```go
-var AppFs afero.Fs = afero.NewMemMapFs()
+var AppFs = afero.NewMemMapFs()
or
-var AppFs afero.Fs = afero.NewOsFs()
+var AppFs = afero.NewOsFs()
```
It is important to note that if you repeat the composite literal you
will be using a completely new and isolated filesystem. In the case of
@@ -81,7 +81,10 @@ So if my application before had:
```go
os.Open('/tmp/foo')
```
-We would replace it with a call to `AppFs.Open('/tmp/foo')`.
+We would replace it with:
+```go
+AppFs.Open('/tmp/foo')
+```
`AppFs` being the variable we defined above.
@@ -166,8 +169,8 @@ f, err := afero.TempFile(fs,"", "ioutil-test")
### Calling via Afero
```go
-fs := afero.NewMemMapFs
-afs := &Afero{Fs: fs}
+fs := afero.NewMemMapFs()
+afs := &afero.Afero{Fs: fs}
f, err := afs.TempFile("", "ioutil-test")
```
diff --git a/vendor/github.com/spf13/afero/appveyor.yml b/vendor/github.com/spf13/afero/appveyor.yml
index 006f31534..a633ad500 100644
--- a/vendor/github.com/spf13/afero/appveyor.yml
+++ b/vendor/github.com/spf13/afero/appveyor.yml
@@ -12,4 +12,4 @@ build_script:
go build github.com/spf13/afero
test_script:
-- cmd: go test -v github.com/spf13/afero
+- cmd: go test -race -v github.com/spf13/afero/...
diff --git a/vendor/github.com/spf13/afero/cacheOnReadFs.go b/vendor/github.com/spf13/afero/cacheOnReadFs.go
index e54a4f8b4..b026e0de8 100644
--- a/vendor/github.com/spf13/afero/cacheOnReadFs.go
+++ b/vendor/github.com/spf13/afero/cacheOnReadFs.go
@@ -64,15 +64,10 @@ func (u *CacheOnReadFs) cacheStatus(name string) (state cacheState, fi os.FileIn
return cacheHit, lfi, nil
}
- if err == syscall.ENOENT {
+ if err == syscall.ENOENT || os.IsNotExist(err) {
return cacheMiss, nil, nil
}
- var ok bool
- if err, ok = err.(*os.PathError); ok {
- if err == os.ErrNotExist {
- return cacheMiss, nil, nil
- }
- }
+
return cacheMiss, nil, err
}
diff --git a/vendor/github.com/spf13/afero/composite_test.go b/vendor/github.com/spf13/afero/composite_test.go
index e8ac1a818..8e44611dc 100644
--- a/vendor/github.com/spf13/afero/composite_test.go
+++ b/vendor/github.com/spf13/afero/composite_test.go
@@ -1,6 +1,7 @@
package afero
import (
+ "bytes"
"fmt"
"io/ioutil"
"os"
@@ -366,3 +367,38 @@ func TestUnionCacheExpire(t *testing.T) {
t.Errorf("cache time failed: <%s>", data)
}
}
+
+func TestCacheOnReadFsNotInLayer(t *testing.T) {
+ base := NewMemMapFs()
+ layer := NewMemMapFs()
+ fs := NewCacheOnReadFs(base, layer, 0)
+
+ fh, err := base.Create("/file.txt")
+ if err != nil {
+ t.Fatal("unable to create file: ", err)
+ }
+
+ txt := []byte("This is a test")
+ fh.Write(txt)
+ fh.Close()
+
+ fh, err = fs.Open("/file.txt")
+ if err != nil {
+ t.Fatal("could not open file: ", err)
+ }
+
+ b, err := ReadAll(fh)
+ fh.Close()
+
+ if err != nil {
+ t.Fatal("could not read file: ", err)
+ } else if !bytes.Equal(txt, b) {
+ t.Fatalf("wanted file text %q, got %q", txt, b)
+ }
+
+ fh, err = layer.Open("/file.txt")
+ if err != nil {
+ t.Fatal("could not open file from layer: ", err)
+ }
+ fh.Close()
+}
diff --git a/vendor/github.com/spf13/afero/mem/file.go b/vendor/github.com/spf13/afero/mem/file.go
index e41e0123d..5401a3b7c 100644
--- a/vendor/github.com/spf13/afero/mem/file.go
+++ b/vendor/github.com/spf13/afero/mem/file.go
@@ -74,14 +74,24 @@ func CreateDir(name string) *FileData {
}
func ChangeFileName(f *FileData, newname string) {
+ f.Lock()
f.name = newname
+ f.Unlock()
}
func SetMode(f *FileData, mode os.FileMode) {
+ f.Lock()
f.mode = mode
+ f.Unlock()
}
func SetModTime(f *FileData, mtime time.Time) {
+ f.Lock()
+ setModTime(f, mtime)
+ f.Unlock()
+}
+
+func setModTime(f *FileData, mtime time.Time) {
f.modtime = mtime
}
@@ -102,7 +112,7 @@ func (f *File) Close() error {
f.fileData.Lock()
f.closed = true
if !f.readOnly {
- SetModTime(f.fileData, time.Now())
+ setModTime(f.fileData, time.Now())
}
f.fileData.Unlock()
return nil
@@ -197,7 +207,7 @@ func (f *File) Truncate(size int64) error {
} else {
f.fileData.data = f.fileData.data[0:size]
}
- SetModTime(f.fileData, time.Now())
+ setModTime(f.fileData, time.Now())
return nil
}
@@ -236,7 +246,7 @@ func (f *File) Write(b []byte) (n int, err error) {
f.fileData.data = append(f.fileData.data[:cur], b...)
f.fileData.data = append(f.fileData.data, tail...)
}
- SetModTime(f.fileData, time.Now())
+ setModTime(f.fileData, time.Now())
atomic.StoreInt64(&f.at, int64(len(f.fileData.data)))
return
@@ -261,17 +271,33 @@ type FileInfo struct {
// Implements os.FileInfo
func (s *FileInfo) Name() string {
+ s.Lock()
_, name := filepath.Split(s.name)
+ s.Unlock()
return name
}
-func (s *FileInfo) Mode() os.FileMode { return s.mode }
-func (s *FileInfo) ModTime() time.Time { return s.modtime }
-func (s *FileInfo) IsDir() bool { return s.dir }
-func (s *FileInfo) Sys() interface{} { return nil }
+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()
+ return s.dir
+}
+func (s *FileInfo) Sys() interface{} { return nil }
func (s *FileInfo) Size() int64 {
if s.IsDir() {
return int64(42)
}
+ s.Lock()
+ defer s.Unlock()
return int64(len(s.data))
}
diff --git a/vendor/github.com/spf13/afero/mem/file_test.go b/vendor/github.com/spf13/afero/mem/file_test.go
new file mode 100644
index 000000000..5769067a7
--- /dev/null
+++ b/vendor/github.com/spf13/afero/mem/file_test.go
@@ -0,0 +1,154 @@
+package mem
+
+import (
+ "testing"
+ "time"
+)
+
+func TestFileDataNameRace(t *testing.T) {
+ t.Parallel()
+ const someName = "someName"
+ const someOtherName = "someOtherName"
+ d := FileData{
+ name: someName,
+ }
+
+ if d.Name() != someName {
+ t.Errorf("Failed to read correct Name, was %v", d.Name())
+ }
+
+ ChangeFileName(&d, someOtherName)
+ if d.Name() != someOtherName {
+ t.Errorf("Failed to set Name, was %v", d.Name())
+ }
+
+ go func() {
+ ChangeFileName(&d, someName)
+ }()
+
+ if d.Name() != someName && d.Name() != someOtherName {
+ t.Errorf("Failed to read either Name, was %v", d.Name())
+ }
+}
+
+func TestFileDataModTimeRace(t *testing.T) {
+ t.Parallel()
+ someTime := time.Now()
+ someOtherTime := someTime.Add(1 * time.Minute)
+
+ d := FileData{
+ modtime: someTime,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.ModTime() != someTime {
+ t.Errorf("Failed to read correct value, was %v", s.ModTime())
+ }
+
+ SetModTime(&d, someOtherTime)
+ if s.ModTime() != someOtherTime {
+ t.Errorf("Failed to set ModTime, was %v", s.ModTime())
+ }
+
+ go func() {
+ SetModTime(&d, someTime)
+ }()
+
+ if s.ModTime() != someTime && s.ModTime() != someOtherTime {
+ t.Errorf("Failed to read either modtime, was %v", s.ModTime())
+ }
+}
+
+func TestFileDataModeRace(t *testing.T) {
+ t.Parallel()
+ const someMode = 0777
+ const someOtherMode = 0660
+
+ d := FileData{
+ mode: someMode,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.Mode() != someMode {
+ t.Errorf("Failed to read correct value, was %v", s.Mode())
+ }
+
+ SetMode(&d, someOtherMode)
+ if s.Mode() != someOtherMode {
+ t.Errorf("Failed to set Mode, was %v", s.Mode())
+ }
+
+ go func() {
+ SetMode(&d, someMode)
+ }()
+
+ if s.Mode() != someMode && s.Mode() != someOtherMode {
+ t.Errorf("Failed to read either mode, was %v", s.Mode())
+ }
+}
+
+func TestFileDataIsDirRace(t *testing.T) {
+ t.Parallel()
+
+ d := FileData{
+ dir: true,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.IsDir() != true {
+ t.Errorf("Failed to read correct value, was %v", s.IsDir())
+ }
+
+ go func() {
+ s.Lock()
+ d.dir = false
+ s.Unlock()
+ }()
+
+ //just logging the value to trigger a read:
+ t.Logf("Value is %v", s.IsDir())
+}
+
+func TestFileDataSizeRace(t *testing.T) {
+ t.Parallel()
+
+ const someData = "Hello"
+ const someOtherDataSize = "Hello World"
+
+ d := FileData{
+ data: []byte(someData),
+ dir: false,
+ }
+
+ s := FileInfo{
+ FileData: &d,
+ }
+
+ if s.Size() != int64(len(someData)) {
+ t.Errorf("Failed to read correct value, was %v", s.Size())
+ }
+
+ go func() {
+ s.Lock()
+ d.data = []byte(someOtherDataSize)
+ s.Unlock()
+ }()
+
+ //just logging the value to trigger a read:
+ t.Logf("Value is %v", s.Size())
+
+ //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())
+ }
+}
diff --git a/vendor/github.com/spf13/afero/memmap.go b/vendor/github.com/spf13/afero/memmap.go
index 14cd438fb..09498e70f 100644
--- a/vendor/github.com/spf13/afero/memmap.go
+++ b/vendor/github.com/spf13/afero/memmap.go
@@ -141,7 +141,7 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
m.registerWithParent(item)
m.mu.Unlock()
- m.Chmod(name, perm)
+ m.Chmod(name, perm|os.ModeDir)
return nil
}
@@ -151,9 +151,8 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error {
if err != nil {
if err.(*os.PathError).Err == ErrFileExists {
return nil
- } else {
- return err
}
+ return err
}
return nil
}
diff --git a/vendor/github.com/spf13/afero/memmap_test.go b/vendor/github.com/spf13/afero/memmap_test.go
index d28e91220..09d8680f6 100644
--- a/vendor/github.com/spf13/afero/memmap_test.go
+++ b/vendor/github.com/spf13/afero/memmap_test.go
@@ -110,6 +110,8 @@ func TestPermSet(t *testing.T) {
const dirPathAll = "/my/path/to/dir"
const fileMode = os.FileMode(0765)
+ // directories will also have the directory bit set
+ const dirMode = fileMode | os.ModeDir
fs := NewMemMapFs()
@@ -132,7 +134,7 @@ func TestPermSet(t *testing.T) {
}
// Test Mkdir
- err = fs.Mkdir(dirPath, fileMode)
+ err = fs.Mkdir(dirPath, dirMode)
if err != nil {
t.Errorf("MkDir Create failed: %s", err)
return
@@ -142,13 +144,14 @@ func TestPermSet(t *testing.T) {
t.Errorf("Stat failed: %s", err)
return
}
- if s.Mode().String() != fileMode.String() {
- t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String())
+ // sets File
+ if s.Mode().String() != dirMode.String() {
+ t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
return
}
// Test MkdirAll
- err = fs.MkdirAll(dirPathAll, fileMode)
+ err = fs.MkdirAll(dirPathAll, dirMode)
if err != nil {
t.Errorf("MkDir Create failed: %s", err)
return
@@ -158,8 +161,8 @@ func TestPermSet(t *testing.T) {
t.Errorf("Stat failed: %s", err)
return
}
- if s.Mode().String() != fileMode.String() {
- t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String())
+ if s.Mode().String() != dirMode.String() {
+ t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
return
}
}
@@ -384,3 +387,35 @@ loop:
}
}
}
+
+func TestMemFsDirMode(t *testing.T) {
+ fs := NewMemMapFs()
+ err := fs.Mkdir("/testDir1", 0644)
+ if err != nil {
+ t.Error(err)
+ }
+ err = fs.MkdirAll("/sub/testDir2", 0644)
+ if err != nil {
+ t.Error(err)
+ }
+ info, err := fs.Stat("/testDir1")
+ if err != nil {
+ t.Error(err)
+ }
+ if !info.IsDir() {
+ t.Error("should be a directory")
+ }
+ if !info.Mode().IsDir() {
+ t.Error("FileMode is not directory")
+ }
+ info, err = fs.Stat("/sub/testDir2")
+ if err != nil {
+ t.Error(err)
+ }
+ if !info.IsDir() {
+ t.Error("should be a directory")
+ }
+ if !info.Mode().IsDir() {
+ t.Error("FileMode is not directory")
+ }
+}
diff --git a/vendor/github.com/spf13/afero/memradix.go b/vendor/github.com/spf13/afero/memradix.go
deleted file mode 100644
index 87527f35a..000000000
--- a/vendor/github.com/spf13/afero/memradix.go
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright © 2014 Steve Francia <spf@spf13.com>.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package afero
diff --git a/vendor/github.com/spf13/afero/util.go b/vendor/github.com/spf13/afero/util.go
index 2f44e6a10..7463887fd 100644
--- a/vendor/github.com/spf13/afero/util.go
+++ b/vendor/github.com/spf13/afero/util.go
@@ -157,7 +157,7 @@ func UnicodeSanitize(s string) string {
return string(target)
}
-// Transform characters with accents into plan forms
+// Transform characters with accents into plain forms.
func NeuterAccents(s string) string {
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
result, _, _ := transform.String(t, string(s))