-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
os: reset dirinfo when seeking on Darwin
The first Readdirnames calls opendir and caches the result. The behavior of that cached opendir result isn't specified on a seek of the underlying fd. Free the opendir result on a seek so that we'll allocate a new one the next time around. Also fix wasm behavior in this regard, so that a seek to the file start resets the Readdirnames position, regardless of platform. p.s. I hate the Readdirnames API. Fixes #35767. Change-Id: Ieffb61b3c5cdd42591f69ab13f932003966f2297 Reviewed-on: https://go-review.googlesource.com/c/go/+/209961 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
- Loading branch information
Showing
5 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// run | ||
|
||
// Copyright 2019 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
f, err := os.Open(wd) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
dirnames1, err := f.Readdirnames(0) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
ret, err := f.Seek(0, 0) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if ret != 0 { | ||
log.Fatalf("seek result not zero: %d", ret) | ||
} | ||
|
||
dirnames2, err := f.Readdirnames(0) | ||
if err != nil { | ||
log.Fatal(err) | ||
return | ||
} | ||
|
||
if len(dirnames1) != len(dirnames2) { | ||
log.Fatalf("listings have different lengths: %d and %d\n", len(dirnames1), len(dirnames2)) | ||
} | ||
for i, n1 := range dirnames1 { | ||
n2 := dirnames2[i] | ||
if n1 != n2 { | ||
log.Fatalf("different name i=%d n1=%s n2=%s\n", i, n1, n2) | ||
} | ||
} | ||
} |