1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

when the file that was opened has been read into buffer, the file should be close.

Signed-off-by: Mabin <bin.ma@huawei.com>
This commit is contained in:
Mabin 2015-02-27 11:53:11 +08:00
parent f5850e8e30
commit d5ea4bae4a
2 changed files with 5 additions and 10 deletions

View file

@ -140,14 +140,12 @@ func (img *Image) RawJson() ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("Failed to get root for image %s: %s", img.ID, err)
}
fh, err := os.Open(jsonPath(root))
if err != nil {
return nil, fmt.Errorf("Failed to open json for image %s: %s", img.ID, err)
}
buf, err := ioutil.ReadAll(fh)
buf, err := ioutil.ReadFile(jsonPath(root))
if err != nil {
return nil, fmt.Errorf("Failed to read json for image %s: %s", img.ID, err)
}
return buf, nil
}

View file

@ -851,14 +851,11 @@ func writeFile(dst, content string, t *testing.T) {
// Return the contents of file at path `src`.
// Call t.Fatal() at the first error (including if the file doesn't exist)
func readFile(src string, t *testing.T) (content string) {
f, err := os.Open(src)
if err != nil {
t.Fatal(err)
}
data, err := ioutil.ReadAll(f)
data, err := ioutil.ReadFile(src)
if err != nil {
t.Fatal(err)
}
return string(data)
}