Skip to content

Commit 72a8b76

Browse files
committed
default storage
1 parent 1f32cc2 commit 72a8b76

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type ConfigData struct {
3838
DisableLeptonGo bool `json:"disable_lepton_go"`
3939
SkipHashFailures bool `json:"skip_hash_failures"`
4040
UseGitignore bool `json:"use_gitignore"`
41+
DefaultStorage string `json:"default_storage"`
4142
}
4243

4344
func Config() ConfigData {

storage/storage.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"sync"
99

10+
"github.com/leijurv/gb/config"
1011
"github.com/leijurv/gb/crypto"
1112
"github.com/leijurv/gb/db"
1213
"github.com/leijurv/gb/gdrive"
@@ -151,30 +152,41 @@ func ClearCache() {
151152
cacheLock.Unlock()
152153
}
153154

155+
func storageSelectPrintOptions() {
156+
descs := GetAllDescriptors()
157+
log.Println("Options:")
158+
for _, d := range descs {
159+
var label string
160+
err := db.DB.QueryRow("SELECT readable_label FROM storage WHERE storage_id = ?", d.StorageID[:]).Scan(&label)
161+
if err != nil {
162+
panic(err)
163+
}
164+
log.Println("•", d.Kind, d.RootPath, "To use this one, add the option `--label=\""+label+"\"`")
165+
}
166+
}
167+
154168
func StorageSelect(label string) (storage_base.Storage, bool) {
169+
if label == "" && config.Config().DefaultStorage != "" {
170+
label = config.Config().DefaultStorage
171+
log.Println("Using default storage from config:", label)
172+
}
155173
if label == "" {
156174
descs := GetAllDescriptors()
157175
if len(descs) == 1 {
158176
log.Println("Auto-selecting the only storage available")
159177
return StorageDataToStorage(descs[0]), true
160178
}
161179
log.Println("First, we need to pick a storage to fetch em from")
162-
log.Println("Options:")
163-
for _, d := range descs {
164-
var label string
165-
err := db.DB.QueryRow("SELECT readable_label FROM storage WHERE storage_id = ?", d.StorageID[:]).Scan(&label)
166-
if err != nil {
167-
panic(err)
168-
}
169-
log.Println("•", d.Kind, d.RootPath, "To use this one, add the option `--label=\""+label+"\"`")
170-
}
180+
storageSelectPrintOptions()
171181
return nil, false
172182
}
173183
GetAll()
174184
var storageID []byte
175185
err := db.DB.QueryRow("SELECT storage_id FROM storage WHERE readable_label = ?", label).Scan(&storageID)
176186
if err != nil {
177-
panic(err)
187+
log.Println("No storage found with label:", label)
188+
storageSelectPrintOptions()
189+
return nil, false
178190
}
179191
storage := GetByID(storageID)
180192
log.Println("Using storage:", storage)

0 commit comments

Comments
 (0)