Skip to content

Commit

Permalink
Merge branch 'main' into fix-ui-public-org
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang authored Jul 14, 2022
2 parents 3cc3ce9 + f85bb6f commit 0c08884
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cmd/dump_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package cmd
import (
"context"
"errors"
"fmt"
"os"
"strings"

"code.gitea.io/gitea/modules/convert"
Expand All @@ -15,6 +17,7 @@ import (
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/migrations"

"github.com/urfave/cli"
Expand Down Expand Up @@ -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(
context.Background(),
ctx.String("repo_dir"),
repoDir,
ctx.String("owner_name"),
opts,
); err != nil {
Expand Down

0 comments on commit 0c08884

Please sign in to comment.