diff --git a/src/github.com/turt2live/matrix-media-repo/cmd/media_repo/main.go b/src/github.com/turt2live/matrix-media-repo/cmd/media_repo/main.go index 2f4910e2ab6725caaff9659d49eebb21f22dbbbf..5790a58e7ac27bd37c263e43c63e190b3a7961ef 100644 --- a/src/github.com/turt2live/matrix-media-repo/cmd/media_repo/main.go +++ b/src/github.com/turt2live/matrix-media-repo/cmd/media_repo/main.go @@ -28,6 +28,24 @@ func main() { 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{}) logrus.Info("Initializing datastores...") diff --git a/src/github.com/turt2live/matrix-media-repo/storage/datastore/datastore.go b/src/github.com/turt2live/matrix-media-repo/storage/datastore/datastore.go index 0fe1cc6149b0edcd12064c7a2843a84b916c92e6..4d029576d012eddf73fd3059d37af89d8b878ba7 100644 --- a/src/github.com/turt2live/matrix-media-repo/storage/datastore/datastore.go +++ b/src/github.com/turt2live/matrix-media-repo/storage/datastore/datastore.go @@ -66,62 +66,6 @@ func GetUriForDatastore(dsConf config.DatastoreConfig) string { } 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 log.Info("Finding a suitable datastore to pick for uploads") confDatastores := config.Get().DataStores