From d5ea4bae4a15cc9f3c16c046389737682277ff0f Mon Sep 17 00:00:00 2001 From: Mabin Date: Fri, 27 Feb 2015 11:53:11 +0800 Subject: [PATCH] when the file that was opened has been read into buffer, the file should be close. Signed-off-by: Mabin --- image/image.go | 8 +++----- integration-cli/docker_utils.go | 7 ++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/image/image.go b/image/image.go index 27554d972a..a661e3ce70 100644 --- a/image/image.go +++ b/image/image.go @@ -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 } diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 2c4518fa14..77f8d8c807 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -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) }