Browse Source

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

Signed-off-by: Mabin <bin.ma@huawei.com>
Mabin 10 years ago
parent
commit
d5ea4bae4a
2 changed files with 5 additions and 10 deletions
  1. 3 5
      image/image.go
  2. 2 5
      integration-cli/docker_utils.go

+ 3 - 5
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
 }
 

+ 2 - 5
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)
 }