Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(17010)

Issue 18870043: code review 18870043: os: do not return Lstat errors from Readdir (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 5 months ago by rsc
Modified:
10 years, 5 months ago
CC:
golang-dev, bradfitz
Visibility:
Public.

Description

os: do not return Lstat errors from Readdir This CL restores the Go 1.1.2 semantics for os.File's Readdir method. The code in Go 1.1.2 was rewritten mainly because it looked buggy. This new version attempts to be clearer but still provide the 1.1.2 results. The important diff is not this CL's version against tip but this CL's version against Go 1.1.2. Go 1.1.2: names, err := f.Readdirnames(n) fi = make([]FileInfo, len(names)) for i, filename := range names { fip, err := Lstat(dirname + filename) if err == nil { fi[i] = fip } else { fi[i] = &fileStat{name: filename} } } return fi, err This CL: names, err := f.Readdirnames(n) fi = make([]FileInfo, len(names)) for i, filename := range names { fip, lerr := lstat(dirname + filename) if lerr != nil { fi[i] = &fileStat{name: filename} continue } fi[i] = fip } return fi, err The changes from Go 1.1.2 are stylistic, not semantic: 1. Use lstat instead of Lstat, for testing (done before this CL). 2. Make error handling in loop body look more like an error case. 3. Use separate error variable name in loop body, to be clear we are not trying to influence the final return result. Fixes issue 6656. Fixes issue 6680.

Patch Set 1 #

Patch Set 2 : diff -r 1a8903f0a577 https://code.google.com/p/go/ #

Patch Set 3 : diff -r 104d56b5d664 https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+5 lines, -8 lines) Patch
M src/pkg/os/file_unix.go View 1 1 chunk +3 lines, -6 lines 0 comments Download
M src/pkg/os/os_unix_test.go View 1 1 chunk +2 lines, -2 lines 0 comments Download

Messages

Total messages: 17
rsc
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go/
10 years, 5 months ago (2013-10-29 00:41:35 UTC) #1
bradfitz
I prefer the semantics at tip. This way (the Go 1.1 way) silently throws away ...
10 years, 5 months ago (2013-10-29 01:00:17 UTC) #2
rsc
Making Go 1.2 Readdir behave differently from Go 1.1 Readdir has already been demonstrated to ...
10 years, 5 months ago (2013-10-29 01:25:38 UTC) #3
bradfitz
Then document it. On Oct 28, 2013 6:25 PM, "Russ Cox" <rsc@golang.org> wrote: > Making ...
10 years, 5 months ago (2013-10-29 01:26:18 UTC) #4
rsc
If n <= 0, Readdir returns all the FileInfo from the directory in a single ...
10 years, 5 months ago (2013-10-29 01:28:11 UTC) #5
bradfitz
On Mon, Oct 28, 2013 at 6:28 PM, Russ Cox <rsc@golang.org> wrote: > If n ...
10 years, 5 months ago (2013-10-29 01:41:13 UTC) #6
rsc
The implementation is OS-dependent. The doc comment is not. I don't want Unix details leaking ...
10 years, 5 months ago (2013-10-29 02:17:38 UTC) #7
bradfitz
I think the Go 1.1 behavior was bad, silently discarding Lstat errors. If lstat is ...
10 years, 5 months ago (2013-10-29 02:26:40 UTC) #8
rsc
On Mon, Oct 28, 2013 at 10:26 PM, Brad Fitzpatrick <bradfitz@golang.org>wrote: > I think the ...
10 years, 5 months ago (2013-10-29 02:30:39 UTC) #9
bradfitz
On Mon, Oct 28, 2013 at 7:30 PM, Russ Cox <rsc@golang.org> wrote: > On Mon, ...
10 years, 5 months ago (2013-10-29 02:37:05 UTC) #10
rsc
For Go 1.3 I don't mind thinking about skipping over IsNotExist(lerr) and returning other errors, ...
10 years, 5 months ago (2013-10-29 02:39:23 UTC) #11
bradfitz
Even after sleeping on it, I still think we should just fix it. Otherwise what's ...
10 years, 5 months ago (2013-10-29 15:14:24 UTC) #12
rsc
It is too late to be designing new semantics. This late in the Go 1.2 ...
10 years, 5 months ago (2013-10-29 15:35:11 UTC) #13
bradfitz
LGTM :/ I'll open some bugs. On Tue, Oct 29, 2013 at 8:35 AM, Russ ...
10 years, 5 months ago (2013-10-29 15:38:39 UTC) #14
rsc
*** Submitted as https://code.google.com/p/go/source/detail?r=eca0ca43a863 *** os: do not return Lstat errors from Readdir This CL ...
10 years, 5 months ago (2013-10-29 15:50:45 UTC) #15
awalterschulze
On 2013/10/29 15:50:45, rsc wrote: > *** Submitted as https://code.google.com/p/go/source/detail?r=eca0ca43a863 *** > > os: do ...
10 years, 5 months ago (2013-10-29 15:59:48 UTC) #16
awalterschulze
10 years, 5 months ago (2013-10-29 16:06:09 UTC) #17
Message was sent while issue was closed.
On 2013/10/29 15:59:48, awalterschulze wrote:
> On 2013/10/29 15:50:45, rsc wrote:
> > *** Submitted as https://code.google.com/p/go/source/detail?r=eca0ca43a863
***
> > 
> > os: do not return Lstat errors from Readdir
> > 
> > This CL restores the Go 1.1.2 semantics for os.File's Readdir method.
> > 
> > The code in Go 1.1.2 was rewritten mainly because it looked buggy.
> > This new version attempts to be clearer but still provide the 1.1.2 results.
> > 
> > The important diff is not this CL's version against tip but this CL's
version
> > against Go 1.1.2.
> > 
> > Go 1.1.2:
> > 
> >         names, err := f.Readdirnames(n)
> >         fi = make([]FileInfo, len(names))
> >         for i, filename := range names {
> >                 fip, err := Lstat(dirname + filename)
> >                 if err == nil {
> >                         fi[i] = fip
> >                 } else {
> >                         fi[i] = &fileStat{name: filename}
> >                 }
> >         }
> >         return fi, err
> > 
> > This CL:
> > 
> >         names, err := f.Readdirnames(n)
> >         fi = make([]FileInfo, len(names))
> >         for i, filename := range names {
> >                 fip, lerr := lstat(dirname + filename)
> >                 if lerr != nil {
> >                         fi[i] = &fileStat{name: filename}
> >                         continue
> >                 }
> >                 fi[i] = fip
> >         }
> >         return fi, err
> > 
> > The changes from Go 1.1.2 are stylistic, not semantic:
> > 1. Use lstat instead of Lstat, for testing (done before this CL).
> > 2. Make error handling in loop body look more like an error case.
> > 3. Use separate error variable name in loop body, to be clear
> >    we are not trying to influence the final return result.
> > 
> > Fixes issue 6656.
> > Fixes issue 6680.
> > 
> > R=golang-dev, bradfitz
> > CC=golang-dev
> > https://codereview.appspot.com/18870043
> 
> Please update the docs if that is your fix
> 
> http://golang.org/pkg/os/#File.Readdir
> "If it encounters an error before the end of the directory, Readdir returns
the
> FileInfo read until that point and a non-nil error."

Ok after reading these comments.
Maybe you can just open some bugs.
But it would have been really cool to fix, since all the work is done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b