mirror of
https://github.com/golang/go
synced 2024-09-24 19:30:12 -06:00
os: try openFile before openDir in windows os.OpenFile
Logging calls when running "go install -a std" turns: 547 openDir succeeded 3593 openDir failed and fell back to openFile 3592 openFile succeeded 1 both failed into: 3592 openFile succeeded 548 openFile failed and fell back 547 openDir succeeded 1 both failed Here the change trades 3593 failed openDir for 548 failed openFile. Fix issue 7426. LGTM=alex.brainman R=golang-codereviews, alex.brainman, bradfitz CC=golang-codereviews https://golang.org/cl/70480044
This commit is contained in:
parent
1624c73c9d
commit
9a7cd11bc8
@ -134,20 +134,19 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
|
|||||||
if name == "" {
|
if name == "" {
|
||||||
return nil, &PathError{"open", name, syscall.ENOENT}
|
return nil, &PathError{"open", name, syscall.ENOENT}
|
||||||
}
|
}
|
||||||
// TODO(brainman): not sure about my logic of assuming it is dir first, then fall back to file
|
r, errf := openFile(name, flag, perm)
|
||||||
r, e := openDir(name)
|
if errf == nil {
|
||||||
if e == nil {
|
return r, nil
|
||||||
|
}
|
||||||
|
r, errd := openDir(name)
|
||||||
|
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{"open", name, syscall.EISDIR}
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
r, e = openFile(name, flag, perm)
|
return nil, &PathError{"open", name, errf}
|
||||||
if e == nil {
|
|
||||||
return r, nil
|
|
||||||
}
|
|
||||||
return nil, &PathError{"open", name, e}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the File, rendering it unusable for I/O.
|
// Close closes the File, rendering it unusable for I/O.
|
||||||
|
Loading…
Reference in New Issue
Block a user