Skip to content
Snippets Groups Projects
Commit 0919f2f9 authored by Travis Ralston's avatar Travis Ralston
Browse files

Support storagePaths configuration option at a higher level

parent e3972068
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,24 @@ func main() { ...@@ -28,6 +28,24 @@ func main() {
panic(err) panic(err)
} }
if len(config.Get().Uploads.StoragePaths) > 0 {
logrus.Warn("storagePaths usage is deprecated - please use datastores instead")
for _, p := range config.Get().Uploads.StoragePaths {
ds, err := storage.GetOrCreateDatastoreOfType(context.Background(), logrus.WithFields(logrus.Fields{"path": p}), "file", p)
if err != nil {
logrus.Fatal(err)
}
fakeConfig := config.DatastoreConfig{
Type: "file",
Enabled: true,
ForUploads: true,
Options: map[string]string{"path": ds.Uri},
}
config.Get().DataStores = append(config.Get().DataStores, fakeConfig)
}
}
mediaStore := storage.GetDatabase().GetMediaStore(context.TODO(), &logrus.Entry{}) mediaStore := storage.GetDatabase().GetMediaStore(context.TODO(), &logrus.Entry{})
logrus.Info("Initializing datastores...") logrus.Info("Initializing datastores...")
......
...@@ -66,62 +66,6 @@ func GetUriForDatastore(dsConf config.DatastoreConfig) string { ...@@ -66,62 +66,6 @@ func GetUriForDatastore(dsConf config.DatastoreConfig) string {
} }
func PickDatastore(ctx context.Context, log *logrus.Entry) (*DatastoreRef, error) { func PickDatastore(ctx context.Context, log *logrus.Entry) (*DatastoreRef, error) {
// Legacy options first
storagePaths := config.Get().Uploads.StoragePaths
if len(storagePaths) > 0 {
log.Warn("Using legacy options to find a datastore")
if len(storagePaths) == 1 {
ds, err := storage.GetOrCreateDatastoreOfType(ctx, log, "file", storagePaths[0])
if err != nil {
return nil, err
}
fakeConfig := config.DatastoreConfig{
Type: "file",
Enabled: true,
ForUploads: true,
Options: map[string]string{"path": ds.Uri},
}
return newDatastoreRef(ds, fakeConfig), nil
}
var basePath string
var pathSize int64
for i := 0; i < len(storagePaths); i++ {
currPath := storagePaths[i]
ds, err := storage.GetOrCreateDatastoreOfType(ctx, log, "file", currPath)
if err != nil {
continue
}
size, err := estimatedDatastoreSize(ds, ctx, log)
if err != nil {
continue
}
if basePath == "" || size < pathSize {
basePath = currPath
pathSize = size
}
}
if basePath != "" {
ds, err := storage.GetOrCreateDatastoreOfType(ctx, log, "file", basePath)
if err != nil {
return nil, err
}
fakeConfig := config.DatastoreConfig{
Type: "file",
Enabled: true,
ForUploads: true,
Options: map[string]string{"path": ds.Uri},
}
return newDatastoreRef(ds, fakeConfig), nil
}
}
// If we haven't found a legacy option, pick a datastore // If we haven't found a legacy option, pick a datastore
log.Info("Finding a suitable datastore to pick for uploads") log.Info("Finding a suitable datastore to pick for uploads")
confDatastores := config.Get().DataStores confDatastores := config.Get().DataStores
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment