From a720377f3ce268902429a00511dba05c028096ae Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Sun, 24 Sep 2017 12:36:06 -0500 Subject: [PATCH] Use Containers to find matched storage containers (#350) (#353) Use stow api correctly to find our function storage container on restarts. --- storagesvc/storagesvc.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/storagesvc/storagesvc.go b/storagesvc/storagesvc.go index bbaa709c..d4ebf5ac 100644 --- a/storagesvc/storagesvc.go +++ b/storagesvc/storagesvc.go @@ -24,7 +24,6 @@ import ( "log" "net/http" "os" - "path/filepath" "strconv" "github.com/gorilla/handlers" @@ -203,8 +202,19 @@ func MakeStorageService(sc *storageConfig) (*StorageService, error) { con, err := loc.CreateContainer(sc.containerName) if os.IsExist(err) { - id := filepath.Join(sc.localPath, sc.containerName) - con, err = loc.Container(id) + var cons []stow.Container + var cursor string + + // use location.Containers to find containers that match the prefix (container name) + cons, cursor, err = loc.Containers(sc.containerName, stow.CursorStart, 1) + if err == nil { + if !stow.IsCursorEnd(cursor) { + // Should only have one storage container + err = errors.New("Found more than one matched storage containers") + } else { + con = cons[0] + } + } } if err != nil { log.Printf("Error initializing storage: %v", err)