Eliminate go vet warnings

This commit is contained in:
Sotirios Mantziaris 2017-01-10 00:53:20 +02:00 committed by Bjørn Erik Pedersen
parent 90dd71edc4
commit 72b3142684
5 changed files with 30 additions and 30 deletions

View File

@ -52,7 +52,7 @@ func validateBasePathName(name string) error {
// On Windows a common mistake would be to provide an absolute OS path // On Windows a common mistake would be to provide an absolute OS path
// We could strip out the base part, but that would not be very portable. // We could strip out the base part, but that would not be very portable.
if filepath.IsAbs(name) { if filepath.IsAbs(name) {
return &os.PathError{"realPath", name, errors.New("got a real OS path instead of a virtual")} return &os.PathError{Op: "realPath", Path: name, Err: errors.New("got a real OS path instead of a virtual")}
} }
return nil return nil
@ -60,14 +60,14 @@ func validateBasePathName(name string) error {
func (b *BasePathFs) Chtimes(name string, atime, mtime time.Time) (err error) { func (b *BasePathFs) Chtimes(name string, atime, mtime time.Time) (err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return &os.PathError{"chtimes", name, err} return &os.PathError{Op: "chtimes", Path: name, Err: err}
} }
return b.source.Chtimes(name, atime, mtime) return b.source.Chtimes(name, atime, mtime)
} }
func (b *BasePathFs) Chmod(name string, mode os.FileMode) (err error) { func (b *BasePathFs) Chmod(name string, mode os.FileMode) (err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return &os.PathError{"chmod", name, err} return &os.PathError{Op: "chmod", Path: name, Err: err}
} }
return b.source.Chmod(name, mode) return b.source.Chmod(name, mode)
} }
@ -78,66 +78,66 @@ func (b *BasePathFs) Name() string {
func (b *BasePathFs) Stat(name string) (fi os.FileInfo, err error) { func (b *BasePathFs) Stat(name string) (fi os.FileInfo, err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return nil, &os.PathError{"stat", name, err} return nil, &os.PathError{Op: "stat", Path: name, Err: err}
} }
return b.source.Stat(name) return b.source.Stat(name)
} }
func (b *BasePathFs) Rename(oldname, newname string) (err error) { func (b *BasePathFs) Rename(oldname, newname string) (err error) {
if oldname, err = b.RealPath(oldname); err != nil { if oldname, err = b.RealPath(oldname); err != nil {
return &os.PathError{"rename", oldname, err} return &os.PathError{Op: "rename", Path: oldname, Err: err}
} }
if newname, err = b.RealPath(newname); err != nil { if newname, err = b.RealPath(newname); err != nil {
return &os.PathError{"rename", newname, err} return &os.PathError{Op: "rename", Path: newname, Err: err}
} }
return b.source.Rename(oldname, newname) return b.source.Rename(oldname, newname)
} }
func (b *BasePathFs) RemoveAll(name string) (err error) { func (b *BasePathFs) RemoveAll(name string) (err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return &os.PathError{"remove_all", name, err} return &os.PathError{Op: "remove_all", Path: name, Err: err}
} }
return b.source.RemoveAll(name) return b.source.RemoveAll(name)
} }
func (b *BasePathFs) Remove(name string) (err error) { func (b *BasePathFs) Remove(name string) (err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return &os.PathError{"remove", name, err} return &os.PathError{Op: "remove", Path: name, Err: err}
} }
return b.source.Remove(name) return b.source.Remove(name)
} }
func (b *BasePathFs) OpenFile(name string, flag int, mode os.FileMode) (f File, err error) { func (b *BasePathFs) OpenFile(name string, flag int, mode os.FileMode) (f File, err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return nil, &os.PathError{"openfile", name, err} return nil, &os.PathError{Op: "openfile", Path: name, Err: err}
} }
return b.source.OpenFile(name, flag, mode) return b.source.OpenFile(name, flag, mode)
} }
func (b *BasePathFs) Open(name string) (f File, err error) { func (b *BasePathFs) Open(name string) (f File, err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return nil, &os.PathError{"open", name, err} return nil, &os.PathError{Op: "open", Path: name, Err: err}
} }
return b.source.Open(name) return b.source.Open(name)
} }
func (b *BasePathFs) Mkdir(name string, mode os.FileMode) (err error) { func (b *BasePathFs) Mkdir(name string, mode os.FileMode) (err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return &os.PathError{"mkdir", name, err} return &os.PathError{Op: "mkdir", Path: name, Err: err}
} }
return b.source.Mkdir(name, mode) return b.source.Mkdir(name, mode)
} }
func (b *BasePathFs) MkdirAll(name string, mode os.FileMode) (err error) { func (b *BasePathFs) MkdirAll(name string, mode os.FileMode) (err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return &os.PathError{"mkdir", name, err} return &os.PathError{Op: "mkdir", Path: name, Err: err}
} }
return b.source.MkdirAll(name, mode) return b.source.MkdirAll(name, mode)
} }
func (b *BasePathFs) Create(name string) (f File, err error) { func (b *BasePathFs) Create(name string) (f File, err error) {
if name, err = b.RealPath(name); err != nil { if name, err = b.RealPath(name); err != nil {
return nil, &os.PathError{"create", name, err} return nil, &os.PathError{Op: "create", Path: name, Err: err}
} }
return b.source.Create(name) return b.source.Create(name)
} }

View File

@ -187,7 +187,7 @@ func TestNestedDirBaseReaddir(t *testing.T) {
fh, _ = ufs.Open("/home/test/foo") fh, _ = ufs.Open("/home/test/foo")
list, err := fh.Readdir(-1) list, err := fh.Readdir(-1)
if err != nil { if err != nil {
t.Errorf("Readdir failed", err) t.Errorf("Readdir failed %s", err)
} }
if len(list) != 2 { if len(list) != 2 {
for _, x := range list { for _, x := range list {
@ -220,7 +220,7 @@ func TestNestedDirOverlayReaddir(t *testing.T) {
fh, _ = ufs.Open("/home/test/foo") fh, _ = ufs.Open("/home/test/foo")
list, err := fh.Readdir(-1) list, err := fh.Readdir(-1)
if err != nil { if err != nil {
t.Errorf("Readdir failed", err) t.Errorf("Readdir failed %s", err)
} }
if len(list) != 2 { if len(list) != 2 {
for _, x := range list { for _, x := range list {
@ -255,7 +255,7 @@ func TestNestedDirOverlayOsFsReaddir(t *testing.T) {
list, err := fh.Readdir(-1) list, err := fh.Readdir(-1)
fh.Close() fh.Close()
if err != nil { if err != nil {
t.Errorf("Readdir failed", err) t.Errorf("Readdir failed %s", err)
} }
if len(list) != 2 { if len(list) != 2 {
for _, x := range list { for _, x := range list {

View File

@ -186,7 +186,7 @@ func (f *File) Truncate(size int64) error {
return ErrFileClosed return ErrFileClosed
} }
if f.readOnly { if f.readOnly {
return &os.PathError{"truncate", f.fileData.name, errors.New("file handle is read only")} return &os.PathError{Op: "truncate", Path: f.fileData.name, Err: errors.New("file handle is read only")}
} }
if size < 0 { if size < 0 {
return ErrOutOfRange return ErrOutOfRange
@ -218,7 +218,7 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
func (f *File) Write(b []byte) (n int, err error) { func (f *File) Write(b []byte) (n int, err error) {
if f.readOnly { if f.readOnly {
return 0, &os.PathError{"write", f.fileData.name, errors.New("file handle is read only")} return 0, &os.PathError{Op: "write", Path: f.fileData.name, Err: errors.New("file handle is read only")}
} }
n = len(b) n = len(b)
cur := atomic.LoadInt64(&f.at) cur := atomic.LoadInt64(&f.at)

View File

@ -45,7 +45,7 @@ func (m *MemMapFs) getData() map[string]*mem.FileData {
return m.data return m.data
} }
func (MemMapFs) Name() string { return "MemMapFS" } func (*MemMapFs) Name() string { return "MemMapFS" }
func (m *MemMapFs) Create(name string) (File, error) { func (m *MemMapFs) Create(name string) (File, error) {
name = normalizePath(name) name = normalizePath(name)
@ -108,7 +108,7 @@ func (m *MemMapFs) lockfreeMkdir(name string, perm os.FileMode) error {
x, ok := m.getData()[name] x, ok := m.getData()[name]
if ok { if ok {
// Only return ErrFileExists if it's a file, not a directory. // Only return ErrFileExists if it's a file, not a directory.
i := mem.FileInfo{x} i := mem.FileInfo{FileData: x}
if !i.IsDir() { if !i.IsDir() {
return ErrFileExists return ErrFileExists
} }
@ -127,7 +127,7 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
_, ok := m.getData()[name] _, ok := m.getData()[name]
m.mu.RUnlock() m.mu.RUnlock()
if ok { if ok {
return &os.PathError{"mkdir", name, ErrFileExists} return &os.PathError{Op: "mkdir", Path: name, Err: ErrFileExists}
} }
m.mu.Lock() m.mu.Lock()
@ -190,7 +190,7 @@ func (m *MemMapFs) open(name string) (*mem.FileData, error) {
f, ok := m.getData()[name] f, ok := m.getData()[name]
m.mu.RUnlock() m.mu.RUnlock()
if !ok { if !ok {
return nil, &os.PathError{"open", name, ErrFileNotFound} return nil, &os.PathError{Op: "open", Path: name, Err: ErrFileNotFound}
} }
return f, nil return f, nil
} }
@ -247,11 +247,11 @@ func (m *MemMapFs) Remove(name string) error {
if _, ok := m.getData()[name]; ok { if _, ok := m.getData()[name]; ok {
err := m.unRegisterWithParent(name) err := m.unRegisterWithParent(name)
if err != nil { if err != nil {
return &os.PathError{"remove", name, err} return &os.PathError{Op: "remove", Path: name, Err: err}
} }
delete(m.getData(), name) delete(m.getData(), name)
} else { } else {
return &os.PathError{"remove", name, os.ErrNotExist} return &os.PathError{Op: "remove", Path: name, Err: os.ErrNotExist}
} }
return nil return nil
} }
@ -299,7 +299,7 @@ func (m *MemMapFs) Rename(oldname, newname string) error {
m.mu.Unlock() m.mu.Unlock()
m.mu.RLock() m.mu.RLock()
} else { } else {
return &os.PathError{"rename", oldname, ErrFileNotFound} return &os.PathError{Op: "rename", Path: oldname, Err: ErrFileNotFound}
} }
return nil return nil
} }
@ -320,7 +320,7 @@ func (m *MemMapFs) Chmod(name string, mode os.FileMode) error {
f, ok := m.getData()[name] f, ok := m.getData()[name]
m.mu.RUnlock() m.mu.RUnlock()
if !ok { if !ok {
return &os.PathError{"chmod", name, ErrFileNotFound} return &os.PathError{Op: "chmod", Path: name, Err: ErrFileNotFound}
} }
m.mu.Lock() m.mu.Lock()
@ -337,7 +337,7 @@ func (m *MemMapFs) Chtimes(name string, atime time.Time, mtime time.Time) error
f, ok := m.getData()[name] f, ok := m.getData()[name]
m.mu.RUnlock() m.mu.RUnlock()
if !ok { if !ok {
return &os.PathError{"chtimes", name, ErrFileNotFound} return &os.PathError{Op: "chtimes", Path: name, Err: ErrFileNotFound}
} }
m.mu.Lock() m.mu.Lock()
@ -349,7 +349,7 @@ func (m *MemMapFs) Chtimes(name string, atime time.Time, mtime time.Time) error
func (m *MemMapFs) List() { func (m *MemMapFs) List() {
for _, x := range m.data { for _, x := range m.data {
y := mem.FileInfo{x} y := mem.FileInfo{FileData: x}
fmt.Println(x.Name(), y.Size()) fmt.Println(x.Name(), y.Size())
} }
} }

View File

@ -105,8 +105,8 @@ func checkPathError(t *testing.T, err error, op string) {
// Ensure Permissions are set on OpenFile/Mkdir/MkdirAll // Ensure Permissions are set on OpenFile/Mkdir/MkdirAll
func TestPermSet(t *testing.T) { func TestPermSet(t *testing.T) {
const fileName = "/myFileTest" const fileName = "/myFileTest"
const dirPath = "/myDirTest" const dirPath = "/myDirTest"
const dirPathAll = "/my/path/to/dir" const dirPathAll = "/my/path/to/dir"
const fileMode = os.FileMode(0765) const fileMode = os.FileMode(0765)