浏览代码

Fix a bug which caused repository metadata to be cleared at startup

Solomon Hykes 12 年之前
父节点
当前提交
d0c776528b
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      tags.go

+ 7 - 1
tags.go

@@ -3,6 +3,7 @@ package docker
 import (
 	"encoding/json"
 	"io/ioutil"
+	"os"
 	"path/filepath"
 )
 
@@ -24,7 +25,12 @@ func NewTagStore(path string, graph *Graph) (*TagStore, error) {
 		graph:        graph,
 		Repositories: make(map[string]Repository),
 	}
-	if err := store.Save(); err != nil {
+	// Load the json file if it exists, otherwise create it.
+	if err := store.Reload(); os.IsNotExist(err) {
+		if err := store.Save(); err != nil {
+			return nil, err
+		}
+	} else if err != nil {
 		return nil, err
 	}
 	return store, nil