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:
parent
f5850e8e30
commit
d5ea4bae4a
|
@ -140,14 +140,12 @@ func (img *Image) RawJson() ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to get root for image %s: %s", img.ID, err)
|
return nil, fmt.Errorf("Failed to get root for image %s: %s", img.ID, err)
|
||||||
}
|
}
|
||||||
fh, err := os.Open(jsonPath(root))
|
|
||||||
if err != nil {
|
buf, err := ioutil.ReadFile(jsonPath(root))
|
||||||
return nil, fmt.Errorf("Failed to open json for image %s: %s", img.ID, err)
|
|
||||||
}
|
|
||||||
buf, err := ioutil.ReadAll(fh)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to read json for image %s: %s", img.ID, err)
|
return nil, fmt.Errorf("Failed to read json for image %s: %s", img.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -851,14 +851,11 @@ func writeFile(dst, content string, t *testing.T) {
|
||||||
// Return the contents of file at path `src`.
|
// Return the contents of file at path `src`.
|
||||||
// Call t.Fatal() at the first error (including if the file doesn't exist)
|
// Call t.Fatal() at the first error (including if the file doesn't exist)
|
||||||
func readFile(src string, t *testing.T) (content string) {
|
func readFile(src string, t *testing.T) (content string) {
|
||||||
f, err := os.Open(src)
|
data, err := ioutil.ReadFile(src)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
data, err := ioutil.ReadAll(f)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue