mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-14 05:56:14 +01:00
Co-authored-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
parent
4c1f4ee84c
commit
975a962a2f
1 changed files with 18 additions and 1 deletions
|
@ -7,6 +7,8 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
|
@ -15,6 +17,7 @@ import (
|
||||||
base "code.gitea.io/gitea/modules/migration"
|
base "code.gitea.io/gitea/modules/migration"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/services/migrations"
|
"code.gitea.io/gitea/services/migrations"
|
||||||
|
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -159,9 +162,23 @@ func runDumpRepository(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the repo_dir will be removed if error occurs in DumpRepository
|
||||||
|
// make sure the directory doesn't exist or is empty, prevent from deleting user files
|
||||||
|
repoDir := ctx.String("repo_dir")
|
||||||
|
if exists, err := util.IsExist(repoDir); err != nil {
|
||||||
|
return fmt.Errorf("unable to stat repo_dir %q: %v", repoDir, err)
|
||||||
|
} else if exists {
|
||||||
|
if isDir, _ := util.IsDir(repoDir); !isDir {
|
||||||
|
return fmt.Errorf("repo_dir %q already exists but it's not a directory", repoDir)
|
||||||
|
}
|
||||||
|
if dir, _ := os.ReadDir(repoDir); len(dir) > 0 {
|
||||||
|
return fmt.Errorf("repo_dir %q is not empty", repoDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := migrations.DumpRepository(
|
if err := migrations.DumpRepository(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
ctx.String("repo_dir"),
|
repoDir,
|
||||||
ctx.String("owner_name"),
|
ctx.String("owner_name"),
|
||||||
opts,
|
opts,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue