Merge pull request #93 from moorereason/no-defer-on-err

Immediately check for errors on fs.Open
This commit is contained in:
Martin Bertschler 2016-08-21 10:36:12 +02:00 committed by GitHub
commit 20500e2abd
2 changed files with 4 additions and 4 deletions

View File

@ -394,13 +394,13 @@ func TestWriteAt(t *testing.T) {
} }
f2, err := fs.Open(f.Name()) f2, err := fs.Open(f.Name())
if err != nil {
t.Fatalf("%v: ReadFile %s: %v", fs.Name(), f.Name(), err)
}
defer f2.Close() defer f2.Close()
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
buf.ReadFrom(f2) buf.ReadFrom(f2)
b := buf.Bytes() b := buf.Bytes()
if err != nil {
t.Fatalf("%v: ReadFile %s: %v", fs.Name(), f.Name(), err)
}
if string(b) != "hello, WORLD\n" { if string(b) != "hello, WORLD\n" {
t.Fatalf("after write: have %q want %q", string(b), "hello, WORLD\n") t.Fatalf("after write: have %q want %q", string(b), "hello, WORLD\n")
} }

View File

@ -295,10 +295,10 @@ func IsEmpty(fs Fs, path string) (bool, error) {
} }
if fi.IsDir() { if fi.IsDir() {
f, err := fs.Open(path) f, err := fs.Open(path)
defer f.Close()
if err != nil { if err != nil {
return false, err return false, err
} }
defer f.Close()
list, err := f.Readdir(-1) list, err := f.Readdir(-1)
return len(list) == 0, nil return len(list) == 0, nil
} }