summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-09-29 17:05:13 +0800
committerGitHub <noreply@github.com>2020-09-29 12:05:13 +0300
commit3878e985b66cc6d4cb4d2b0e7406d5cf91af6191 (patch)
tree31229c29c2b57041d1941ec28b043165cbe4642d /cmd
parent4c6ac08182b5a14eaaffaafafef160bd90c4ae81 (diff)
downloadgitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.tar.gz
gitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.zip
Add default storage configurations (#12813)
Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dump.go45
-rw-r--r--cmd/migrate_storage.go17
2 files changed, 49 insertions, 13 deletions
diff --git a/cmd/dump.go b/cmd/dump.go
index 0e41ecb8c7..7ff986f14e 100644
--- a/cmd/dump.go
+++ b/cmd/dump.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
"gitea.com/macaron/session"
@@ -57,6 +58,8 @@ func addRecursive(w archiver.Writer, dirPath string, absPath string, verbose boo
if err != nil {
return fmt.Errorf("Could not open directory %s: %s", absPath, err)
}
+ defer dir.Close()
+
files, err := dir.Readdir(0)
if err != nil {
return fmt.Errorf("Unable to list files in %s: %s", absPath, err)
@@ -197,6 +200,10 @@ func runDump(ctx *cli.Context) error {
return err
}
+ if err := storage.Init(); err != nil {
+ return err
+ }
+
if file == nil {
file, err = os.Create(fileName)
if err != nil {
@@ -231,11 +238,21 @@ func runDump(ctx *cli.Context) error {
fatal("Failed to include repositories: %v", err)
}
- if _, err := os.Stat(setting.LFS.ContentPath); !os.IsNotExist(err) {
- log.Info("Dumping lfs... %s", setting.LFS.ContentPath)
- if err := addRecursive(w, "lfs", setting.LFS.ContentPath, verbose); err != nil {
- fatal("Failed to include lfs: %v", err)
+ if err := storage.LFS.IterateObjects(func(objPath string, object storage.Object) error {
+ info, err := object.Stat()
+ if err != nil {
+ return err
}
+
+ return w.Write(archiver.File{
+ FileInfo: archiver.FileInfo{
+ FileInfo: info,
+ CustomName: path.Join("data", "lfs", objPath),
+ },
+ ReadCloser: object,
+ })
+ }); err != nil {
+ fatal("Failed to dump LFS objects: %v", err)
}
}
@@ -302,13 +319,31 @@ func runDump(ctx *cli.Context) error {
}
excludes = append(excludes, setting.RepoRootPath)
- excludes = append(excludes, setting.LFS.ContentPath)
+ excludes = append(excludes, setting.LFS.Path)
+ excludes = append(excludes, setting.Attachment.Path)
excludes = append(excludes, setting.LogRootPath)
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
fatal("Failed to include data directory: %v", err)
}
}
+ if err := storage.Attachments.IterateObjects(func(objPath string, object storage.Object) error {
+ info, err := object.Stat()
+ if err != nil {
+ return err
+ }
+
+ return w.Write(archiver.File{
+ FileInfo: archiver.FileInfo{
+ FileInfo: info,
+ CustomName: path.Join("data", "attachments", objPath),
+ },
+ ReadCloser: object,
+ })
+ }); err != nil {
+ fatal("Failed to dump attachments: %v", err)
+ }
+
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
// ensuring that it's clear the dump is skipped whether the directory's initialized
// yet or not.
diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go
index b8e45c954d..aed81ddb01 100644
--- a/cmd/migrate_storage.go
+++ b/cmd/migrate_storage.go
@@ -7,6 +7,7 @@ package cmd
import (
"context"
"fmt"
+ "strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/migrations"
@@ -30,8 +31,8 @@ var CmdMigrateStorage = cli.Command{
Usage: "Kinds of files to migrate, currently only 'attachments' is supported",
},
cli.StringFlag{
- Name: "store, s",
- Value: "local",
+ Name: "storage, s",
+ Value: setting.LocalStorageType,
Usage: "New storage type, local or minio",
},
cli.StringFlag{
@@ -112,15 +113,15 @@ func runMigrateStorage(ctx *cli.Context) error {
var dstStorage storage.ObjectStorage
var err error
- switch ctx.String("store") {
- case "local":
+ switch strings.ToLower(ctx.String("storage")) {
+ case setting.LocalStorageType:
p := ctx.String("path")
if p == "" {
- log.Fatal("Path must be given when store is loal")
+ log.Fatal("Path must be given when storage is loal")
return nil
}
dstStorage, err = storage.NewLocalStorage(p)
- case "minio":
+ case setting.MinioStorageType:
dstStorage, err = storage.NewMinioStorage(
context.Background(),
ctx.String("minio-endpoint"),
@@ -132,14 +133,14 @@ func runMigrateStorage(ctx *cli.Context) error {
ctx.Bool("minio-use-ssl"),
)
default:
- return fmt.Errorf("Unsupported attachments store type: %s", ctx.String("store"))
+ return fmt.Errorf("Unsupported attachments storage type: %s", ctx.String("storage"))
}
if err != nil {
return err
}
- tp := ctx.String("type")
+ tp := strings.ToLower(ctx.String("type"))
switch tp {
case "attachments":
if err := migrateAttachments(dstStorage); err != nil {