Skip to content

Commit

Permalink
Exclude the current dump file from the dump
Browse files Browse the repository at this point in the history
Always prevent the current file from being added to the dump.

Fix go-gitea#13618

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Feb 7, 2021
1 parent 5f248d0 commit cdabff7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ func runDump(ctx *cli.Context) error {
}
defer file.Close()

absFileName, err := filepath.Abs(fileName)
if err != nil {
return err
}

verbose := ctx.Bool("verbose")
outType := ctx.String("type")
var iface interface{}
Expand All @@ -233,7 +238,7 @@ func runDump(ctx *cli.Context) error {
log.Info("Skip dumping local repositories")
} else {
log.Info("Dumping local repositories... %s", setting.RepoRootPath)
if err := addRecursive(w, "repos", setting.RepoRootPath, verbose); err != nil {
if err := addRecursiveExclude(w, "repos", setting.RepoRootPath, []string{absFileName}, verbose); err != nil {
fatal("Failed to include repositories: %v", err)
}

Expand Down Expand Up @@ -295,7 +300,7 @@ func runDump(ctx *cli.Context) error {
customDir, err := os.Stat(setting.CustomPath)
if err == nil && customDir.IsDir() {
if is, _ := isSubdir(setting.AppDataPath, setting.CustomPath); !is {
if err := addRecursive(w, "custom", setting.CustomPath, verbose); err != nil {
if err := addRecursiveExclude(w, "custom", setting.CustomPath, []string{absFileName}, verbose); err != nil {
fatal("Failed to include custom: %v", err)
}
} else {
Expand Down Expand Up @@ -325,6 +330,7 @@ func runDump(ctx *cli.Context) error {
excludes = append(excludes, setting.LFS.Path)
excludes = append(excludes, setting.Attachment.Path)
excludes = append(excludes, setting.LogRootPath)
excludes = append(excludes, absFileName)
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
fatal("Failed to include data directory: %v", err)
}
Expand Down Expand Up @@ -358,7 +364,7 @@ func runDump(ctx *cli.Context) error {
log.Error("Unable to check if %s exists. Error: %v", setting.LogRootPath, err)
}
if isExist {
if err := addRecursive(w, "log", setting.LogRootPath, verbose); err != nil {
if err := addRecursiveExclude(w, "log", setting.LogRootPath, []string{absFileName}, verbose); err != nil {
fatal("Failed to include log: %v", err)
}
}
Expand Down

0 comments on commit cdabff7

Please sign in to comment.