1
0
mirror of https://github.com/golang/go synced 2024-09-29 12:24:31 -06:00

os: use keyed literals for PathError

Necessary to move PathError to io/fs.

For #41190.

Change-Id: I05e87675f38a22f0570d4366b751b6169f7a1b13
Reviewed-on: https://go-review.googlesource.com/c/go/+/243900
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Russ Cox 2020-07-03 12:25:49 -04:00
parent a4ede9f9a6
commit 2291cae2af
17 changed files with 79 additions and 79 deletions

View File

@ -32,10 +32,10 @@ func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []Di
if err == io.EOF { if err == io.EOF {
break break
} }
return names, dirents, infos, &PathError{"readdir", file.name, err} return names, dirents, infos, &PathError{Op: "readdir", Path: file.name, Err: err}
} }
if nb < syscall.STATFIXLEN { if nb < syscall.STATFIXLEN {
return names, dirents, infos, &PathError{"readdir", file.name, syscall.ErrShortStat} return names, dirents, infos, &PathError{Op: "readdir", Path: file.name, Err: syscall.ErrShortStat}
} }
} }
@ -43,12 +43,12 @@ func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []Di
b := d.buf[d.bufp:] b := d.buf[d.bufp:]
m := int(uint16(b[0])|uint16(b[1])<<8) + 2 m := int(uint16(b[0])|uint16(b[1])<<8) + 2
if m < syscall.STATFIXLEN { if m < syscall.STATFIXLEN {
return names, dirents, infos, &PathError{"readdir", file.name, syscall.ErrShortStat} return names, dirents, infos, &PathError{Op: "readdir", Path: file.name, Err: syscall.ErrShortStat}
} }
dir, err := syscall.UnmarshalDir(b[:m]) dir, err := syscall.UnmarshalDir(b[:m])
if err != nil { if err != nil {
return names, dirents, infos, &PathError{"readdir", file.name, err} return names, dirents, infos, &PathError{Op: "readdir", Path: file.name, Err: err}
} }
if mode == readdirName { if mode == readdirName {

View File

@ -50,7 +50,7 @@ func (f *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEn
d.nbuf, errno = f.pfd.ReadDirent(d.buf) d.nbuf, errno = f.pfd.ReadDirent(d.buf)
runtime.KeepAlive(f) runtime.KeepAlive(f)
if errno != nil { if errno != nil {
return names, dirents, infos, &PathError{"readdirent", f.name, errno} return names, dirents, infos, &PathError{Op: "readdirent", Path: f.name, Err: errno}
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break // EOF

View File

@ -12,7 +12,7 @@ import (
func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEntry, infos []FileInfo, err error) { func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEntry, infos []FileInfo, err error) {
if !file.isdir() { if !file.isdir() {
return nil, nil, nil, &PathError{"readdir", file.name, syscall.ENOTDIR} return nil, nil, nil, &PathError{Op: "readdir", Path: file.name, Err: syscall.ENOTDIR}
} }
wantAll := n <= 0 wantAll := n <= 0
if wantAll { if wantAll {
@ -27,7 +27,7 @@ func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []Di
if e == syscall.ERROR_NO_MORE_FILES { if e == syscall.ERROR_NO_MORE_FILES {
break break
} else { } else {
err = &PathError{"FindNextFile", file.name, e} err = &PathError{Op: "FindNextFile", Path: file.name, Err: e}
return return
} }
} }

View File

@ -34,7 +34,7 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
pid, h, e := syscall.StartProcess(name, argv, sysattr) pid, h, e := syscall.StartProcess(name, argv, sysattr)
if e != nil { if e != nil {
return nil, &PathError{"fork/exec", name, e} return nil, &PathError{Op: "fork/exec", Path: name, Err: e}
} }
return newProcess(pid, h), nil return newProcess(pid, h), nil

View File

@ -56,7 +56,7 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
runtime.KeepAlive(attr) runtime.KeepAlive(attr)
if e != nil { if e != nil {
return nil, &PathError{"fork/exec", name, e} return nil, &PathError{Op: "fork/exec", Path: name, Err: e}
} }
return newProcess(pid, h), nil return newProcess(pid, h), nil

View File

@ -127,7 +127,7 @@ func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
} }
if off < 0 { if off < 0 {
return 0, &PathError{"readat", f.name, errors.New("negative offset")} return 0, &PathError{Op: "readat", Path: f.name, Err: errors.New("negative offset")}
} }
for len(b) > 0 { for len(b) > 0 {
@ -203,7 +203,7 @@ func (f *File) WriteAt(b []byte, off int64) (n int, err error) {
} }
if off < 0 { if off < 0 {
return 0, &PathError{"writeat", f.name, errors.New("negative offset")} return 0, &PathError{Op: "writeat", Path: f.name, Err: errors.New("negative offset")}
} }
for len(b) > 0 { for len(b) > 0 {
@ -253,7 +253,7 @@ func (f *File) WriteString(s string) (n int, err error) {
// If there is an error, it will be of type *PathError. // If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error { func Mkdir(name string, perm FileMode) error {
if runtime.GOOS == "windows" && isWindowsNulName(name) { if runtime.GOOS == "windows" && isWindowsNulName(name) {
return &PathError{"mkdir", name, syscall.ENOTDIR} return &PathError{Op: "mkdir", Path: name, Err: syscall.ENOTDIR}
} }
longName := fixLongPath(name) longName := fixLongPath(name)
e := ignoringEINTR(func() error { e := ignoringEINTR(func() error {
@ -261,7 +261,7 @@ func Mkdir(name string, perm FileMode) error {
}) })
if e != nil { if e != nil {
return &PathError{"mkdir", name, e} return &PathError{Op: "mkdir", Path: name, Err: e}
} }
// mkdir(2) itself won't handle the sticky bit on *BSD and Solaris // mkdir(2) itself won't handle the sticky bit on *BSD and Solaris
@ -291,7 +291,7 @@ func setStickyBit(name string) error {
func Chdir(dir string) error { func Chdir(dir string) error {
if e := syscall.Chdir(dir); e != nil { if e := syscall.Chdir(dir); e != nil {
testlog.Open(dir) // observe likely non-existent directory testlog.Open(dir) // observe likely non-existent directory
return &PathError{"chdir", dir, e} return &PathError{Op: "chdir", Path: dir, Err: e}
} }
if log := testlog.Logger(); log != nil { if log := testlog.Logger(); log != nil {
wd, err := Getwd() wd, err := Getwd()
@ -366,7 +366,7 @@ func (f *File) wrapErr(op string, err error) error {
if err == poll.ErrFileClosing { if err == poll.ErrFileClosing {
err = ErrClosed err = ErrClosed
} }
return &PathError{op, f.name, err} return &PathError{Op: op, Path: f.name, Err: err}
} }
// TempDir returns the default directory to use for temporary files. // TempDir returns the default directory to use for temporary files.

View File

@ -119,18 +119,18 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
if IsNotExist(e) && create { if IsNotExist(e) && create {
fd, e = syscall.Create(name, flag, syscallMode(perm)) fd, e = syscall.Create(name, flag, syscallMode(perm))
if e != nil { if e != nil {
return nil, &PathError{"create", name, e} return nil, &PathError{Op: "create", Path: name, Err: e}
} }
} }
} }
if e != nil { if e != nil {
return nil, &PathError{"open", name, e} return nil, &PathError{Op: "open", Path: name, Err: e}
} }
if append { if append {
if _, e = syscall.Seek(fd, 0, io.SeekEnd); e != nil { if _, e = syscall.Seek(fd, 0, io.SeekEnd); e != nil {
return nil, &PathError{"seek", name, e} return nil, &PathError{Op: "seek", Path: name, Err: e}
} }
} }
@ -154,7 +154,7 @@ func (file *file) close() error {
} }
var err error var err error
if e := syscall.Close(file.fd); e != nil { if e := syscall.Close(file.fd); e != nil {
err = &PathError{"close", file.name, e} err = &PathError{Op: "close", Path: file.name, Err: e}
} }
file.fd = badFd // so it can't be closed again file.fd = badFd // so it can't be closed again
@ -191,10 +191,10 @@ func (f *File) Truncate(size int64) error {
var buf [syscall.STATFIXLEN]byte var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:]) n, err := d.Marshal(buf[:])
if err != nil { if err != nil {
return &PathError{"truncate", f.name, err} return &PathError{Op: "truncate", Path: f.name, Err: err}
} }
if err = syscall.Fwstat(f.fd, buf[:n]); err != nil { if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
return &PathError{"truncate", f.name, err} return &PathError{Op: "truncate", Path: f.name, Err: err}
} }
return nil return nil
} }
@ -209,7 +209,7 @@ func (f *File) chmod(mode FileMode) error {
odir, e := dirstat(f) odir, e := dirstat(f)
if e != nil { if e != nil {
return &PathError{"chmod", f.name, e} return &PathError{Op: "chmod", Path: f.name, Err: e}
} }
d.Null() d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
@ -217,10 +217,10 @@ func (f *File) chmod(mode FileMode) error {
var buf [syscall.STATFIXLEN]byte var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:]) n, err := d.Marshal(buf[:])
if err != nil { if err != nil {
return &PathError{"chmod", f.name, err} return &PathError{Op: "chmod", Path: f.name, Err: err}
} }
if err = syscall.Fwstat(f.fd, buf[:n]); err != nil { if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
return &PathError{"chmod", f.name, err} return &PathError{Op: "chmod", Path: f.name, Err: err}
} }
return nil return nil
} }
@ -238,10 +238,10 @@ func (f *File) Sync() error {
var buf [syscall.STATFIXLEN]byte var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:]) n, err := d.Marshal(buf[:])
if err != nil { if err != nil {
return &PathError{"sync", f.name, err} return &PathError{Op: "sync", Path: f.name, Err: err}
} }
if err = syscall.Fwstat(f.fd, buf[:n]); err != nil { if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
return &PathError{"sync", f.name, err} return &PathError{Op: "sync", Path: f.name, Err: err}
} }
return nil return nil
} }
@ -314,10 +314,10 @@ func Truncate(name string, size int64) error {
var buf [syscall.STATFIXLEN]byte var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:]) n, err := d.Marshal(buf[:])
if err != nil { if err != nil {
return &PathError{"truncate", name, err} return &PathError{Op: "truncate", Path: name, Err: err}
} }
if err = syscall.Wstat(name, buf[:n]); err != nil { if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"truncate", name, err} return &PathError{Op: "truncate", Path: name, Err: err}
} }
return nil return nil
} }
@ -326,7 +326,7 @@ func Truncate(name string, size int64) error {
// If there is an error, it will be of type *PathError. // If there is an error, it will be of type *PathError.
func Remove(name string) error { func Remove(name string) error {
if e := syscall.Remove(name); e != nil { if e := syscall.Remove(name); e != nil {
return &PathError{"remove", name, e} return &PathError{Op: "remove", Path: name, Err: e}
} }
return nil return nil
} }
@ -389,7 +389,7 @@ func chmod(name string, mode FileMode) error {
odir, e := dirstat(name) odir, e := dirstat(name)
if e != nil { if e != nil {
return &PathError{"chmod", name, e} return &PathError{Op: "chmod", Path: name, Err: e}
} }
d.Null() d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
@ -397,10 +397,10 @@ func chmod(name string, mode FileMode) error {
var buf [syscall.STATFIXLEN]byte var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:]) n, err := d.Marshal(buf[:])
if err != nil { if err != nil {
return &PathError{"chmod", name, err} return &PathError{Op: "chmod", Path: name, Err: err}
} }
if err = syscall.Wstat(name, buf[:n]); err != nil { if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"chmod", name, err} return &PathError{Op: "chmod", Path: name, Err: err}
} }
return nil return nil
} }
@ -421,10 +421,10 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
var buf [syscall.STATFIXLEN]byte var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:]) n, err := d.Marshal(buf[:])
if err != nil { if err != nil {
return &PathError{"chtimes", name, err} return &PathError{Op: "chtimes", Path: name, Err: err}
} }
if err = syscall.Wstat(name, buf[:n]); err != nil { if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"chtimes", name, err} return &PathError{Op: "chtimes", Path: name, Err: err}
} }
return nil return nil
} }
@ -458,7 +458,7 @@ func Symlink(oldname, newname string) error {
// Readlink returns the destination of the named symbolic link. // Readlink returns the destination of the named symbolic link.
// If there is an error, it will be of type *PathError. // If there is an error, it will be of type *PathError.
func Readlink(name string) (string, error) { func Readlink(name string) (string, error) {
return "", &PathError{"readlink", name, syscall.EPLAN9} return "", &PathError{Op: "readlink", Path: name, Err: syscall.EPLAN9}
} }
// Chown changes the numeric uid and gid of the named file. // Chown changes the numeric uid and gid of the named file.
@ -469,14 +469,14 @@ func Readlink(name string) (string, error) {
// On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or // On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or
// EPLAN9 error, wrapped in *PathError. // EPLAN9 error, wrapped in *PathError.
func Chown(name string, uid, gid int) error { func Chown(name string, uid, gid int) error {
return &PathError{"chown", name, syscall.EPLAN9} return &PathError{Op: "chown", Path: name, Err: syscall.EPLAN9}
} }
// Lchown changes the numeric uid and gid of the named file. // Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself. // If the file is a symbolic link, it changes the uid and gid of the link itself.
// If there is an error, it will be of type *PathError. // If there is an error, it will be of type *PathError.
func Lchown(name string, uid, gid int) error { func Lchown(name string, uid, gid int) error {
return &PathError{"lchown", name, syscall.EPLAN9} return &PathError{Op: "lchown", Path: name, Err: syscall.EPLAN9}
} }
// Chown changes the numeric uid and gid of the named file. // Chown changes the numeric uid and gid of the named file.
@ -485,7 +485,7 @@ func (f *File) Chown(uid, gid int) error {
if f == nil { if f == nil {
return ErrInvalid return ErrInvalid
} }
return &PathError{"chown", f.name, syscall.EPLAN9} return &PathError{Op: "chown", Path: f.name, Err: syscall.EPLAN9}
} }
func tempDir() string { func tempDir() string {
@ -505,7 +505,7 @@ func (f *File) Chdir() error {
return err return err
} }
if e := syscall.Fchdir(f.fd); e != nil { if e := syscall.Fchdir(f.fd); e != nil {
return &PathError{"chdir", f.name, e} return &PathError{Op: "chdir", Path: f.name, Err: e}
} }
return nil return nil
} }
@ -541,7 +541,7 @@ func (f *File) checkValid(op string) error {
return ErrInvalid return ErrInvalid
} }
if f.fd == badFd { if f.fd == badFd {
return &PathError{op, f.name, ErrClosed} return &PathError{Op: op, Path: f.name, Err: ErrClosed}
} }
return nil return nil
} }

View File

@ -81,7 +81,7 @@ func chmod(name string, mode FileMode) error {
return syscall.Chmod(longName, syscallMode(mode)) return syscall.Chmod(longName, syscallMode(mode))
}) })
if e != nil { if e != nil {
return &PathError{"chmod", name, e} return &PathError{Op: "chmod", Path: name, Err: e}
} }
return nil return nil
} }
@ -109,7 +109,7 @@ func Chown(name string, uid, gid int) error {
return syscall.Chown(name, uid, gid) return syscall.Chown(name, uid, gid)
}) })
if e != nil { if e != nil {
return &PathError{"chown", name, e} return &PathError{Op: "chown", Path: name, Err: e}
} }
return nil return nil
} }
@ -125,7 +125,7 @@ func Lchown(name string, uid, gid int) error {
return syscall.Lchown(name, uid, gid) return syscall.Lchown(name, uid, gid)
}) })
if e != nil { if e != nil {
return &PathError{"lchown", name, e} return &PathError{Op: "lchown", Path: name, Err: e}
} }
return nil return nil
} }
@ -182,7 +182,7 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
utimes[0] = syscall.NsecToTimespec(atime.UnixNano()) utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano()) utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
if e := syscall.UtimesNano(fixLongPath(name), utimes[0:]); e != nil { if e := syscall.UtimesNano(fixLongPath(name), utimes[0:]); e != nil {
return &PathError{"chtimes", name, e} return &PathError{Op: "chtimes", Path: name, Err: e}
} }
return nil return nil
} }

View File

@ -215,7 +215,7 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
continue continue
} }
return nil, &PathError{"open", name, e} return nil, &PathError{Op: "open", Path: name, Err: e}
} }
// open(2) itself won't handle the sticky bit on *BSD and Solaris // open(2) itself won't handle the sticky bit on *BSD and Solaris
@ -244,7 +244,7 @@ func (file *file) close() error {
if e == poll.ErrFileClosing { if e == poll.ErrFileClosing {
e = ErrClosed e = ErrClosed
} }
err = &PathError{"close", file.name, e} err = &PathError{Op: "close", Path: file.name, Err: e}
} }
// no need for a finalizer anymore // no need for a finalizer anymore
@ -276,7 +276,7 @@ func Truncate(name string, size int64) error {
return syscall.Truncate(name, size) return syscall.Truncate(name, size)
}) })
if e != nil { if e != nil {
return &PathError{"truncate", name, e} return &PathError{Op: "truncate", Path: name, Err: e}
} }
return nil return nil
} }
@ -313,7 +313,7 @@ func Remove(name string) error {
if e1 != syscall.ENOTDIR { if e1 != syscall.ENOTDIR {
e = e1 e = e1
} }
return &PathError{"remove", name, e} return &PathError{Op: "remove", Path: name, Err: e}
} }
func tempDir() string { func tempDir() string {
@ -372,7 +372,7 @@ func Readlink(name string) (string, error) {
continue continue
} }
if e != nil { if e != nil {
return "", &PathError{"readlink", name, e} return "", &PathError{Op: "readlink", Path: name, Err: e}
} }
if n < len { if n < len {
return string(b[0:n]), nil return string(b[0:n]), nil

View File

@ -168,7 +168,7 @@ func openDir(name string) (file *File, err error) {
// openFileNolog is the Windows implementation of OpenFile. // openFileNolog is the Windows implementation of OpenFile.
func openFileNolog(name string, flag int, perm FileMode) (*File, error) { func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
if name == "" { if name == "" {
return nil, &PathError{"open", name, syscall.ENOENT} return nil, &PathError{Op: "open", Path: name, Err: syscall.ENOENT}
} }
r, errf := openFile(name, flag, perm) r, errf := openFile(name, flag, perm)
if errf == nil { if errf == nil {
@ -178,11 +178,11 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
if errd == nil { if errd == nil {
if flag&O_WRONLY != 0 || flag&O_RDWR != 0 { if flag&O_WRONLY != 0 || flag&O_RDWR != 0 {
r.Close() r.Close()
return nil, &PathError{"open", name, syscall.EISDIR} return nil, &PathError{Op: "open", Path: name, Err: syscall.EISDIR}
} }
return r, nil return r, nil
} }
return nil, &PathError{"open", name, errf} return nil, &PathError{Op: "open", Path: name, Err: errf}
} }
func (file *file) close() error { func (file *file) close() error {
@ -198,7 +198,7 @@ func (file *file) close() error {
if e == poll.ErrFileClosing { if e == poll.ErrFileClosing {
e = ErrClosed e = ErrClosed
} }
err = &PathError{"close", file.name, e} err = &PathError{Op: "close", Path: file.name, Err: e}
} }
// no need for a finalizer anymore // no need for a finalizer anymore
@ -236,7 +236,7 @@ func Truncate(name string, size int64) error {
func Remove(name string) error { func Remove(name string) error {
p, e := syscall.UTF16PtrFromString(fixLongPath(name)) p, e := syscall.UTF16PtrFromString(fixLongPath(name))
if e != nil { if e != nil {
return &PathError{"remove", name, e} return &PathError{Op: "remove", Path: name, Err: e}
} }
// Go file interface forces us to know whether // Go file interface forces us to know whether
@ -267,7 +267,7 @@ func Remove(name string) error {
} }
} }
} }
return &PathError{"remove", name, e} return &PathError{Op: "remove", Path: name, Err: e}
} }
func rename(oldname, newname string) error { func rename(oldname, newname string) error {
@ -493,7 +493,7 @@ func readlink(path string) (string, error) {
func Readlink(name string) (string, error) { func Readlink(name string) (string, error) {
s, err := readlink(fixLongPath(name)) s, err := readlink(fixLongPath(name))
if err != nil { if err != nil {
return "", &PathError{"readlink", name, err} return "", &PathError{Op: "readlink", Path: name, Err: err}
} }
return s, nil return s, nil
} }

View File

@ -22,7 +22,7 @@ func MkdirAll(path string, perm FileMode) error {
if dir.IsDir() { if dir.IsDir() {
return nil return nil
} }
return &PathError{"mkdir", path, syscall.ENOTDIR} return &PathError{Op: "mkdir", Path: path, Err: syscall.ENOTDIR}
} }
// Slow path: make sure parent exists and then call Mkdir for path. // Slow path: make sure parent exists and then call Mkdir for path.

View File

@ -22,7 +22,7 @@ func removeAll(path string) error {
// The rmdir system call does not permit removing ".", // The rmdir system call does not permit removing ".",
// so we don't permit it either. // so we don't permit it either.
if endsWithDot(path) { if endsWithDot(path) {
return &PathError{"RemoveAll", path, syscall.EINVAL} return &PathError{Op: "RemoveAll", Path: path, Err: syscall.EINVAL}
} }
// Simple case: if Remove works, we're done. // Simple case: if Remove works, we're done.
@ -70,7 +70,7 @@ func removeAllFrom(parent *File, base string) error {
// whose contents need to be removed. // whose contents need to be removed.
// Otherwise just return the error. // Otherwise just return the error.
if err != syscall.EISDIR && err != syscall.EPERM && err != syscall.EACCES { if err != syscall.EISDIR && err != syscall.EPERM && err != syscall.EACCES {
return &PathError{"unlinkat", base, err} return &PathError{Op: "unlinkat", Path: base, Err: err}
} }
// Is this a directory we need to recurse into? // Is this a directory we need to recurse into?
@ -80,11 +80,11 @@ func removeAllFrom(parent *File, base string) error {
if IsNotExist(statErr) { if IsNotExist(statErr) {
return nil return nil
} }
return &PathError{"fstatat", base, statErr} return &PathError{Op: "fstatat", Path: base, Err: statErr}
} }
if statInfo.Mode&syscall.S_IFMT != syscall.S_IFDIR { if statInfo.Mode&syscall.S_IFMT != syscall.S_IFDIR {
// Not a directory; return the error from the unix.Unlinkat. // Not a directory; return the error from the unix.Unlinkat.
return &PathError{"unlinkat", base, err} return &PathError{Op: "unlinkat", Path: base, Err: err}
} }
// Remove the directory's entries. // Remove the directory's entries.
@ -99,7 +99,7 @@ func removeAllFrom(parent *File, base string) error {
if IsNotExist(err) { if IsNotExist(err) {
return nil return nil
} }
recurseErr = &PathError{"openfdat", base, err} recurseErr = &PathError{Op: "openfdat", Path: base, Err: err}
break break
} }
@ -113,7 +113,7 @@ func removeAllFrom(parent *File, base string) error {
if IsNotExist(readErr) { if IsNotExist(readErr) {
return nil return nil
} }
return &PathError{"readdirnames", base, readErr} return &PathError{Op: "readdirnames", Path: base, Err: readErr}
} }
respSize = len(names) respSize = len(names)
@ -159,7 +159,7 @@ func removeAllFrom(parent *File, base string) error {
if recurseErr != nil { if recurseErr != nil {
return recurseErr return recurseErr
} }
return &PathError{"unlinkat", base, unlinkError} return &PathError{Op: "unlinkat", Path: base, Err: unlinkError}
} }
// openFdAt opens path relative to the directory in fd. // openFdAt opens path relative to the directory in fd.

View File

@ -23,7 +23,7 @@ func removeAll(path string) error {
// so we don't permit it to remain consistent with the // so we don't permit it to remain consistent with the
// "at" implementation of RemoveAll. // "at" implementation of RemoveAll.
if endsWithDot(path) { if endsWithDot(path) {
return &PathError{"RemoveAll", path, syscall.EINVAL} return &PathError{Op: "RemoveAll", Path: path, Err: syscall.EINVAL}
} }
// Simple case: if Remove works, we're done. // Simple case: if Remove works, we're done.

View File

@ -65,7 +65,7 @@ func dirstat(arg interface{}) (*syscall.Dir, error) {
} }
if n < bitSize16 { if n < bitSize16 {
return nil, &PathError{"stat", name, err} return nil, &PathError{Op: "stat", Path: name, Err: err}
} }
// Pull the real size out of the stat message. // Pull the real size out of the stat message.
@ -76,7 +76,7 @@ func dirstat(arg interface{}) (*syscall.Dir, error) {
if size <= n { if size <= n {
d, err := syscall.UnmarshalDir(buf[:n]) d, err := syscall.UnmarshalDir(buf[:n])
if err != nil { if err != nil {
return nil, &PathError{"stat", name, err} return nil, &PathError{Op: "stat", Path: name, Err: err}
} }
return d, nil return d, nil
} }
@ -87,7 +87,7 @@ func dirstat(arg interface{}) (*syscall.Dir, error) {
err = syscall.ErrBadStat err = syscall.ErrBadStat
} }
return nil, &PathError{"stat", name, err} return nil, &PathError{Op: "stat", Path: name, Err: err}
} }
// statNolog implements Stat for Plan 9. // statNolog implements Stat for Plan 9.

View File

@ -19,7 +19,7 @@ func (f *File) Stat() (FileInfo, error) {
var fs fileStat var fs fileStat
err := f.pfd.Fstat(&fs.sys) err := f.pfd.Fstat(&fs.sys)
if err != nil { if err != nil {
return nil, &PathError{"stat", f.name, err} return nil, &PathError{Op: "stat", Path: f.name, Err: err}
} }
fillFileStatFromSys(&fs, f.name) fillFileStatFromSys(&fs, f.name)
return &fs, nil return &fs, nil
@ -32,7 +32,7 @@ func statNolog(name string) (FileInfo, error) {
return syscall.Stat(name, &fs.sys) return syscall.Stat(name, &fs.sys)
}) })
if err != nil { if err != nil {
return nil, &PathError{"stat", name, err} return nil, &PathError{Op: "stat", Path: name, Err: err}
} }
fillFileStatFromSys(&fs, name) fillFileStatFromSys(&fs, name)
return &fs, nil return &fs, nil
@ -45,7 +45,7 @@ func lstatNolog(name string) (FileInfo, error) {
return syscall.Lstat(name, &fs.sys) return syscall.Lstat(name, &fs.sys)
}) })
if err != nil { if err != nil {
return nil, &PathError{"lstat", name, err} return nil, &PathError{Op: "lstat", Path: name, Err: err}
} }
fillFileStatFromSys(&fs, name) fillFileStatFromSys(&fs, name)
return &fs, nil return &fs, nil

View File

@ -27,7 +27,7 @@ func (file *File) Stat() (FileInfo, error) {
ft, err := file.pfd.GetFileType() ft, err := file.pfd.GetFileType()
if err != nil { if err != nil {
return nil, &PathError{"GetFileType", file.name, err} return nil, &PathError{Op: "GetFileType", Path: file.name, Err: err}
} }
switch ft { switch ft {
case syscall.FILE_TYPE_PIPE, syscall.FILE_TYPE_CHAR: case syscall.FILE_TYPE_PIPE, syscall.FILE_TYPE_CHAR:
@ -45,14 +45,14 @@ func (file *File) Stat() (FileInfo, error) {
// stat implements both Stat and Lstat of a file. // stat implements both Stat and Lstat of a file.
func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) { func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
if len(name) == 0 { if len(name) == 0 {
return nil, &PathError{funcname, name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)} return nil, &PathError{Op: funcname, Path: name, Err: syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
} }
if isWindowsNulName(name) { if isWindowsNulName(name) {
return &devNullStat, nil return &devNullStat, nil
} }
namep, err := syscall.UTF16PtrFromString(fixLongPath(name)) namep, err := syscall.UTF16PtrFromString(fixLongPath(name))
if err != nil { if err != nil {
return nil, &PathError{funcname, name, err} return nil, &PathError{Op: funcname, Path: name, Err: err}
} }
// Try GetFileAttributesEx first, because it is faster than CreateFile. // Try GetFileAttributesEx first, because it is faster than CreateFile.
@ -80,7 +80,7 @@ func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
var fd syscall.Win32finddata var fd syscall.Win32finddata
sh, err := syscall.FindFirstFile(namep, &fd) sh, err := syscall.FindFirstFile(namep, &fd)
if err != nil { if err != nil {
return nil, &PathError{"FindFirstFile", name, err} return nil, &PathError{Op: "FindFirstFile", Path: name, Err: err}
} }
syscall.FindClose(sh) syscall.FindClose(sh)
fs := newFileStatFromWin32finddata(&fd) fs := newFileStatFromWin32finddata(&fd)
@ -94,7 +94,7 @@ func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
h, err := syscall.CreateFile(namep, 0, 0, nil, h, err := syscall.CreateFile(namep, 0, 0, nil,
syscall.OPEN_EXISTING, createFileAttrs, 0) syscall.OPEN_EXISTING, createFileAttrs, 0)
if err != nil { if err != nil {
return nil, &PathError{"CreateFile", name, err} return nil, &PathError{Op: "CreateFile", Path: name, Err: err}
} }
defer syscall.CloseHandle(h) defer syscall.CloseHandle(h)

View File

@ -45,7 +45,7 @@ func newFileStatFromGetFileInformationByHandle(path string, h syscall.Handle) (f
var d syscall.ByHandleFileInformation var d syscall.ByHandleFileInformation
err = syscall.GetFileInformationByHandle(h, &d) err = syscall.GetFileInformationByHandle(h, &d)
if err != nil { if err != nil {
return nil, &PathError{"GetFileInformationByHandle", path, err} return nil, &PathError{Op: "GetFileInformationByHandle", Path: path, Err: err}
} }
var ti windows.FILE_ATTRIBUTE_TAG_INFO var ti windows.FILE_ATTRIBUTE_TAG_INFO
@ -58,7 +58,7 @@ func newFileStatFromGetFileInformationByHandle(path string, h syscall.Handle) (f
// instance to indicate no symlinks are possible. // instance to indicate no symlinks are possible.
ti.ReparseTag = 0 ti.ReparseTag = 0
} else { } else {
return nil, &PathError{"GetFileInformationByHandleEx", path, err} return nil, &PathError{Op: "GetFileInformationByHandleEx", Path: path, Err: err}
} }
} }
@ -197,7 +197,7 @@ func (fs *fileStat) saveInfoFromPath(path string) error {
var err error var err error
fs.path, err = syscall.FullPath(fs.path) fs.path, err = syscall.FullPath(fs.path)
if err != nil { if err != nil {
return &PathError{"FullPath", path, err} return &PathError{Op: "FullPath", Path: path, Err: err}
} }
} }
fs.name = basename(path) fs.name = basename(path)