Skip to content

Commit

Permalink
Dump should only copy regular files and symlink regular files (#20015)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang authored Jun 18, 2022
1 parent 870d7f9 commit 433443f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"code.gitea.io/gitea/modules/util"

"gitea.com/go-chi/session"
archiver "github.com/mholt/archiver/v3"
"github.com/mholt/archiver/v3"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -439,8 +439,23 @@ func addRecursiveExclude(w archiver.Writer, insidePath, absPath string, excludeA
}
}
} else {
if err = addFile(w, currentInsidePath, currentAbsPath, verbose); err != nil {
return err
// only copy regular files and symlink regular files, skip non-regular files like socket/pipe/...
shouldAdd := file.Mode().IsRegular()
if !shouldAdd && file.Mode()&os.ModeSymlink == os.ModeSymlink {
target, err := filepath.EvalSymlinks(currentAbsPath)
if err != nil {
return err
}
targetStat, err := os.Stat(target)
if err != nil {
return err
}
shouldAdd = targetStat.Mode().IsRegular()
}
if shouldAdd {
if err = addFile(w, currentInsidePath, currentAbsPath, verbose); err != nil {
return err
}
}
}
}
Expand Down

0 comments on commit 433443f

Please sign in to comment.