summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-09-08 23:45:10 +0800
committerGitHub <noreply@github.com>2020-09-08 23:45:10 +0800
commit7a5465fc56f79f5fc3c32547c89a80b7ebb24c8f (patch)
treec663ce5f0f37e13d950384fd76428c422adfb06d /cmd
parente4b3f35b8d68d6409a280a8e644759e10b091cb1 (diff)
downloadgitea-7a5465fc56f79f5fc3c32547c89a80b7ebb24c8f.tar.gz
gitea-7a5465fc56f79f5fc3c32547c89a80b7ebb24c8f.zip
LFS support to be stored on minio (#12518)
* LFS support to be stored on minio * Fix test * Fix lint * Fix lint * Fix check * Fix test * Update documents and add migration for LFS * Fix some bugs
Diffstat (limited to 'cmd')
-rw-r--r--cmd/migrate_storage.go74
1 files changed, 43 insertions, 31 deletions
diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go
index 3a26f0b3f5..b8e45c954d 100644
--- a/cmd/migrate_storage.go
+++ b/cmd/migrate_storage.go
@@ -83,6 +83,13 @@ func migrateAttachments(dstStorage storage.ObjectStorage) error {
})
}
+func migrateLFS(dstStorage storage.ObjectStorage) error {
+ return models.IterateLFS(func(mo *models.LFSMetaObject) error {
+ _, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath())
+ return err
+ })
+}
+
func runMigrateStorage(ctx *cli.Context) error {
if err := initDB(); err != nil {
return err
@@ -103,45 +110,50 @@ func runMigrateStorage(ctx *cli.Context) error {
return err
}
+ var dstStorage storage.ObjectStorage
+ var err error
+ switch ctx.String("store") {
+ case "local":
+ p := ctx.String("path")
+ if p == "" {
+ log.Fatal("Path must be given when store is loal")
+ return nil
+ }
+ dstStorage, err = storage.NewLocalStorage(p)
+ case "minio":
+ dstStorage, err = storage.NewMinioStorage(
+ context.Background(),
+ ctx.String("minio-endpoint"),
+ ctx.String("minio-access-key-id"),
+ ctx.String("minio-secret-access-key"),
+ ctx.String("minio-bucket"),
+ ctx.String("minio-location"),
+ ctx.String("minio-base-path"),
+ ctx.Bool("minio-use-ssl"),
+ )
+ default:
+ return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store"))
+ }
+
+ if err != nil {
+ return err
+ }
+
tp := ctx.String("type")
switch tp {
case "attachments":
- var dstStorage storage.ObjectStorage
- var err error
- switch ctx.String("store") {
- case "local":
- p := ctx.String("path")
- if p == "" {
- log.Fatal("Path must be given when store is loal")
- return nil
- }
- dstStorage, err = storage.NewLocalStorage(p)
- case "minio":
- dstStorage, err = storage.NewMinioStorage(
- context.Background(),
- ctx.String("minio-endpoint"),
- ctx.String("minio-access-key-id"),
- ctx.String("minio-secret-access-key"),
- ctx.String("minio-bucket"),
- ctx.String("minio-location"),
- ctx.String("minio-base-path"),
- ctx.Bool("minio-use-ssl"),
- )
- default:
- return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store"))
- }
-
- if err != nil {
+ if err := migrateAttachments(dstStorage); err != nil {
return err
}
- if err := migrateAttachments(dstStorage); err != nil {
+ case "lfs":
+ if err := migrateLFS(dstStorage); err != nil {
return err
}
-
- log.Warn("All files have been copied to the new placement but old files are still on the orignial placement.")
-
- return nil
+ default:
+ return fmt.Errorf("Unsupported storage: %s", ctx.String("type"))
}
+ log.Warn("All files have been copied to the new placement but old files are still on the orignial placement.")
+
return nil
}