summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/afero/mem/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/afero/mem/file.go')
-rw-r--r--vendor/github.com/spf13/afero/mem/file.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/vendor/github.com/spf13/afero/mem/file.go b/vendor/github.com/spf13/afero/mem/file.go
index 699f1fb0..5a20730c 100644
--- a/vendor/github.com/spf13/afero/mem/file.go
+++ b/vendor/github.com/spf13/afero/mem/file.go
@@ -22,10 +22,9 @@ import (
"path/filepath"
"sync"
"sync/atomic"
+ "time"
)
-import "time"
-
const FilePathSeparator = string(filepath.Separator)
type File struct {
@@ -57,6 +56,8 @@ type FileData struct {
dir bool
mode os.FileMode
modtime time.Time
+ uid int
+ gid int
}
func (d *FileData) Name() string {
@@ -95,6 +96,18 @@ func setModTime(f *FileData, mtime time.Time) {
f.modtime = mtime
}
+func SetUID(f *FileData, uid int) {
+ f.Lock()
+ f.uid = uid
+ f.Unlock()
+}
+
+func SetGID(f *FileData, gid int) {
+ f.Lock()
+ f.gid = gid
+ f.Unlock()
+}
+
func GetFileInfo(f *FileData) *FileInfo {
return &FileInfo{f}
}
@@ -210,6 +223,8 @@ func (f *File) Truncate(size int64) error {
if size < 0 {
return ErrOutOfRange
}
+ f.fileData.Lock()
+ 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))...)
@@ -225,11 +240,11 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
return 0, ErrFileClosed
}
switch whence {
- case 0:
+ case io.SeekStart:
atomic.StoreInt64(&f.at, offset)
- case 1:
- atomic.AddInt64(&f.at, int64(offset))
- case 2:
+ case io.SeekCurrent:
+ atomic.AddInt64(&f.at, offset)
+ case io.SeekEnd:
atomic.StoreInt64(&f.at, int64(len(f.fileData.data))+offset)
}
return f.at, nil
@@ -252,7 +267,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(bytes.Repeat([]byte{00}, int(diff)), b...)
+ f.fileData.data = append(f.fileData.data, append(bytes.Repeat([]byte{00}, int(diff)), b...)...)
f.fileData.data = append(f.fileData.data, tail...)
} else {
f.fileData.data = append(f.fileData.data[:cur], b...)
@@ -260,7 +275,7 @@ func (f *File) Write(b []byte) (n int, err error) {
}
setModTime(f.fileData, time.Now())
- atomic.StoreInt64(&f.at, int64(len(f.fileData.data)))
+ atomic.AddInt64(&f.at, int64(n))
return
}