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>
if err == io.EOF {
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 {
- return names, dirents, infos, &PathError{"readdir", file.name, syscall.ErrShortStat}
+ return names, dirents, infos, &PathError{Op: "readdir", Path: file.name, Err: syscall.ErrShortStat}
}
}
b := d.buf[d.bufp:]
m := int(uint16(b[0])|uint16(b[1])<<8) + 2
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])
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 {
d.nbuf, errno = f.pfd.ReadDirent(d.buf)
runtime.KeepAlive(f)
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 {
break // EOF
func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEntry, infos []FileInfo, err error) {
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
if wantAll {
if e == syscall.ERROR_NO_MORE_FILES {
break
} else {
- err = &PathError{"FindNextFile", file.name, e}
+ err = &PathError{Op: "FindNextFile", Path: file.name, Err: e}
return
}
}
pid, h, e := syscall.StartProcess(name, argv, sysattr)
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
runtime.KeepAlive(attr)
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
}
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 {
}
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 {
// If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error {
if runtime.GOOS == "windows" && isWindowsNulName(name) {
- return &PathError{"mkdir", name, syscall.ENOTDIR}
+ return &PathError{Op: "mkdir", Path: name, Err: syscall.ENOTDIR}
}
longName := fixLongPath(name)
e := ignoringEINTR(func() error {
})
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
func Chdir(dir string) error {
if e := syscall.Chdir(dir); e != nil {
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 {
wd, err := Getwd()
if err == poll.ErrFileClosing {
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.
if IsNotExist(e) && create {
fd, e = syscall.Create(name, flag, syscallMode(perm))
if e != nil {
- return nil, &PathError{"create", name, e}
+ return nil, &PathError{Op: "create", Path: name, Err: e}
}
}
}
if e != nil {
- return nil, &PathError{"open", name, e}
+ return nil, &PathError{Op: "open", Path: name, Err: e}
}
if append {
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}
}
}
}
var err error
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
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
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 {
- return &PathError{"truncate", f.name, err}
+ return &PathError{Op: "truncate", Path: f.name, Err: err}
}
return nil
}
odir, e := dirstat(f)
if e != nil {
- return &PathError{"chmod", f.name, e}
+ return &PathError{Op: "chmod", Path: f.name, Err: e}
}
d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
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 {
- return &PathError{"chmod", f.name, err}
+ return &PathError{Op: "chmod", Path: f.name, Err: err}
}
return nil
}
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
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 {
- return &PathError{"sync", f.name, err}
+ return &PathError{Op: "sync", Path: f.name, Err: err}
}
return nil
}
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
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 {
- return &PathError{"truncate", name, err}
+ return &PathError{Op: "truncate", Path: name, Err: err}
}
return nil
}
// If there is an error, it will be of type *PathError.
func Remove(name string) error {
if e := syscall.Remove(name); e != nil {
- return &PathError{"remove", name, e}
+ return &PathError{Op: "remove", Path: name, Err: e}
}
return nil
}
odir, e := dirstat(name)
if e != nil {
- return &PathError{"chmod", name, e}
+ return &PathError{Op: "chmod", Path: name, Err: e}
}
d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
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 {
- return &PathError{"chmod", name, err}
+ return &PathError{Op: "chmod", Path: name, Err: err}
}
return nil
}
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
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 {
- return &PathError{"chtimes", name, err}
+ return &PathError{Op: "chtimes", Path: name, Err: err}
}
return nil
}
// Readlink returns the destination of the named symbolic link.
// If there is an error, it will be of type *PathError.
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.
// On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or
// EPLAN9 error, wrapped in *PathError.
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.
// 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.
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.
if f == nil {
return ErrInvalid
}
- return &PathError{"chown", f.name, syscall.EPLAN9}
+ return &PathError{Op: "chown", Path: f.name, Err: syscall.EPLAN9}
}
func tempDir() string {
return err
}
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 ErrInvalid
}
if f.fd == badFd {
- return &PathError{op, f.name, ErrClosed}
+ return &PathError{Op: op, Path: f.name, Err: ErrClosed}
}
return nil
}
return syscall.Chmod(longName, syscallMode(mode))
})
if e != nil {
- return &PathError{"chmod", name, e}
+ return &PathError{Op: "chmod", Path: name, Err: e}
}
return nil
}
return syscall.Chown(name, uid, gid)
})
if e != nil {
- return &PathError{"chown", name, e}
+ return &PathError{Op: "chown", Path: name, Err: e}
}
return nil
}
return syscall.Lchown(name, uid, gid)
})
if e != nil {
- return &PathError{"lchown", name, e}
+ return &PathError{Op: "lchown", Path: name, Err: e}
}
return nil
}
utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
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
}
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
if e == poll.ErrFileClosing {
e = ErrClosed
}
- err = &PathError{"close", file.name, e}
+ err = &PathError{Op: "close", Path: file.name, Err: e}
}
// no need for a finalizer anymore
return syscall.Truncate(name, size)
})
if e != nil {
- return &PathError{"truncate", name, e}
+ return &PathError{Op: "truncate", Path: name, Err: e}
}
return nil
}
if e1 != syscall.ENOTDIR {
e = e1
}
- return &PathError{"remove", name, e}
+ return &PathError{Op: "remove", Path: name, Err: e}
}
func tempDir() string {
continue
}
if e != nil {
- return "", &PathError{"readlink", name, e}
+ return "", &PathError{Op: "readlink", Path: name, Err: e}
}
if n < len {
return string(b[0:n]), nil
// openFileNolog is the Windows implementation of OpenFile.
func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
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)
if errf == nil {
if errd == nil {
if flag&O_WRONLY != 0 || flag&O_RDWR != 0 {
r.Close()
- return nil, &PathError{"open", name, syscall.EISDIR}
+ return nil, &PathError{Op: "open", Path: name, Err: syscall.EISDIR}
}
return r, nil
}
- return nil, &PathError{"open", name, errf}
+ return nil, &PathError{Op: "open", Path: name, Err: errf}
}
func (file *file) close() error {
if e == poll.ErrFileClosing {
e = ErrClosed
}
- err = &PathError{"close", file.name, e}
+ err = &PathError{Op: "close", Path: file.name, Err: e}
}
// no need for a finalizer anymore
func Remove(name string) error {
p, e := syscall.UTF16PtrFromString(fixLongPath(name))
if e != nil {
- return &PathError{"remove", name, e}
+ return &PathError{Op: "remove", Path: name, Err: e}
}
// Go file interface forces us to know whether
}
}
}
- return &PathError{"remove", name, e}
+ return &PathError{Op: "remove", Path: name, Err: e}
}
func rename(oldname, newname string) error {
func Readlink(name string) (string, error) {
s, err := readlink(fixLongPath(name))
if err != nil {
- return "", &PathError{"readlink", name, err}
+ return "", &PathError{Op: "readlink", Path: name, Err: err}
}
return s, nil
}
if dir.IsDir() {
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.
// The rmdir system call does not permit removing ".",
// so we don't permit it either.
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.
// whose contents need to be removed.
// Otherwise just return the error.
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?
if IsNotExist(statErr) {
return nil
}
- return &PathError{"fstatat", base, statErr}
+ return &PathError{Op: "fstatat", Path: base, Err: statErr}
}
if statInfo.Mode&syscall.S_IFMT != syscall.S_IFDIR {
// 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.
if IsNotExist(err) {
return nil
}
- recurseErr = &PathError{"openfdat", base, err}
+ recurseErr = &PathError{Op: "openfdat", Path: base, Err: err}
break
}
if IsNotExist(readErr) {
return nil
}
- return &PathError{"readdirnames", base, readErr}
+ return &PathError{Op: "readdirnames", Path: base, Err: readErr}
}
respSize = len(names)
if recurseErr != nil {
return recurseErr
}
- return &PathError{"unlinkat", base, unlinkError}
+ return &PathError{Op: "unlinkat", Path: base, Err: unlinkError}
}
// openFdAt opens path relative to the directory in fd.
// so we don't permit it to remain consistent with the
// "at" implementation of RemoveAll.
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.
}
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.
if size <= n {
d, err := syscall.UnmarshalDir(buf[:n])
if err != nil {
- return nil, &PathError{"stat", name, err}
+ return nil, &PathError{Op: "stat", Path: name, Err: err}
}
return d, nil
}
err = syscall.ErrBadStat
}
- return nil, &PathError{"stat", name, err}
+ return nil, &PathError{Op: "stat", Path: name, Err: err}
}
// statNolog implements Stat for Plan 9.
var fs fileStat
err := f.pfd.Fstat(&fs.sys)
if err != nil {
- return nil, &PathError{"stat", f.name, err}
+ return nil, &PathError{Op: "stat", Path: f.name, Err: err}
}
fillFileStatFromSys(&fs, f.name)
return &fs, nil
return syscall.Stat(name, &fs.sys)
})
if err != nil {
- return nil, &PathError{"stat", name, err}
+ return nil, &PathError{Op: "stat", Path: name, Err: err}
}
fillFileStatFromSys(&fs, name)
return &fs, nil
return syscall.Lstat(name, &fs.sys)
})
if err != nil {
- return nil, &PathError{"lstat", name, err}
+ return nil, &PathError{Op: "lstat", Path: name, Err: err}
}
fillFileStatFromSys(&fs, name)
return &fs, nil
ft, err := file.pfd.GetFileType()
if err != nil {
- return nil, &PathError{"GetFileType", file.name, err}
+ return nil, &PathError{Op: "GetFileType", Path: file.name, Err: err}
}
switch ft {
case syscall.FILE_TYPE_PIPE, syscall.FILE_TYPE_CHAR:
// stat implements both Stat and Lstat of a file.
func stat(funcname, name string, createFileAttrs uint32) (FileInfo, error) {
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) {
return &devNullStat, nil
}
namep, err := syscall.UTF16PtrFromString(fixLongPath(name))
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.
var fd syscall.Win32finddata
sh, err := syscall.FindFirstFile(namep, &fd)
if err != nil {
- return nil, &PathError{"FindFirstFile", name, err}
+ return nil, &PathError{Op: "FindFirstFile", Path: name, Err: err}
}
syscall.FindClose(sh)
fs := newFileStatFromWin32finddata(&fd)
h, err := syscall.CreateFile(namep, 0, 0, nil,
syscall.OPEN_EXISTING, createFileAttrs, 0)
if err != nil {
- return nil, &PathError{"CreateFile", name, err}
+ return nil, &PathError{Op: "CreateFile", Path: name, Err: err}
}
defer syscall.CloseHandle(h)
var d syscall.ByHandleFileInformation
err = syscall.GetFileInformationByHandle(h, &d)
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
// instance to indicate no symlinks are possible.
ti.ReparseTag = 0
} else {
- return nil, &PathError{"GetFileInformationByHandleEx", path, err}
+ return nil, &PathError{Op: "GetFileInformationByHandleEx", Path: path, Err: err}
}
}
var err error
fs.path, err = syscall.FullPath(fs.path)
if err != nil {
- return &PathError{"FullPath", path, err}
+ return &PathError{Op: "FullPath", Path: path, Err: err}
}
}
fs.name = basename(path)