Use Containers to find matched storage containers (#350) (#353)

Use stow api correctly to find our function storage container on restarts.
This commit is contained in:
Ta-Ching Chen
2017-09-24 10:36:06 -07:00
committed by Soam Vasani
parent 42819ba362
commit a720377f3c
+13 -3
View File
@@ -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)