forked from mirror/afero
Merge pull request #93 from moorereason/no-defer-on-err
Immediately check for errors on fs.Open
This commit is contained in:
commit
20500e2abd
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
2
util.go
2
util.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue