diff options
Diffstat (limited to 'libgo/go/os/file_unix.go')
-rw-r--r-- | libgo/go/os/file_unix.go | 97 |
1 files changed, 8 insertions, 89 deletions
diff --git a/libgo/go/os/file_unix.go b/libgo/go/os/file_unix.go index 5d6c8af..54b5dfd 100644 --- a/libgo/go/os/file_unix.go +++ b/libgo/go/os/file_unix.go @@ -11,11 +11,16 @@ import ( "syscall" ) -func sameFile(fs1, fs2 *fileStat) bool { - return fs1.sys.Dev == fs2.sys.Dev && fs1.sys.Ino == fs2.sys.Ino +// fixLongPath is a noop on non-Windows platforms. +func fixLongPath(path string) string { + return path } func rename(oldname, newname string) error { + fi, err := Lstat(newname) + if err == nil && fi.IsDir() { + return &LinkError{"rename", oldname, newname, syscall.EEXIST} + } e := syscall.Rename(oldname, newname) if e != nil { return &LinkError{"rename", oldname, newname, e} @@ -23,11 +28,6 @@ func rename(oldname, newname string) error { return nil } -// File represents an open file descriptor. -type File struct { - *file -} - // file is the real representation of *File. // The extra level of indirection ensures that no clients of os // can overwrite this data, which could cause the finalizer @@ -132,7 +132,7 @@ func (f *File) Close() error { } func (file *file) close() error { - if file == nil || file.fd < 0 { + if file == nil || file.fd == badFd { return syscall.EINVAL } var err error @@ -158,69 +158,6 @@ func (file *file) close() error { return err } -// Stat returns the FileInfo structure describing file. -// If there is an error, it will be of type *PathError. -func (f *File) Stat() (FileInfo, error) { - if f == nil { - return nil, ErrInvalid - } - var fs fileStat - err := syscall.Fstat(f.fd, &fs.sys) - if err != nil { - return nil, &PathError{"stat", f.name, err} - } - fillFileStatFromSys(&fs, f.name) - return &fs, nil -} - -// Stat returns a FileInfo describing the named file. -// If there is an error, it will be of type *PathError. -func Stat(name string) (FileInfo, error) { - var fs fileStat - err := syscall.Stat(name, &fs.sys) - if err != nil { - return nil, &PathError{"stat", name, err} - } - fillFileStatFromSys(&fs, name) - return &fs, nil -} - -// Lstat returns a FileInfo describing the named file. -// If the file is a symbolic link, the returned FileInfo -// describes the symbolic link. Lstat makes no attempt to follow the link. -// If there is an error, it will be of type *PathError. -func Lstat(name string) (FileInfo, error) { - var fs fileStat - err := syscall.Lstat(name, &fs.sys) - if err != nil { - return nil, &PathError{"lstat", name, err} - } - fillFileStatFromSys(&fs, name) - return &fs, nil -} - -func (f *File) readdir(n int) (fi []FileInfo, err error) { - dirname := f.name - if dirname == "" { - dirname = "." - } - names, err := f.Readdirnames(n) - fi = make([]FileInfo, 0, len(names)) - for _, filename := range names { - fip, lerr := lstat(dirname + "/" + filename) - if IsNotExist(lerr) { - // File disappeared between readdir + stat. - // Just treat it as if it didn't exist. - continue - } - if lerr != nil { - return fi, lerr - } - fi = append(fi, fip) - } - return fi, err -} - // Darwin and FreeBSD can't read or write 2GB+ at a time, // even on 64-bit systems. See golang.org/issue/7812. // Use 1GB instead of, say, 2GB-1, to keep subsequent @@ -335,24 +272,6 @@ func Remove(name string) error { return &PathError{"remove", name, e} } -// basename removes trailing slashes and the leading directory name from path name -func basename(name string) string { - i := len(name) - 1 - // Remove trailing slashes - for ; i > 0 && name[i] == '/'; i-- { - name = name[:i] - } - // Remove leading directory name - for i--; i >= 0; i-- { - if name[i] == '/' { - name = name[i+1:] - break - } - } - - return name -} - // TempDir returns the default directory to use for temporary files. func TempDir() string { dir := Getenv("TMPDIR") |