Skip to content

Commit 19ef992

Browse files
wxiaoguang6543
authored andcommitted
Dump should only copy regular files and symlink regular files (go-gitea#20015)
1 parent 870d7f9 commit 19ef992

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

cmd/dump.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/util"
2323

2424
"gitea.com/go-chi/session"
25-
archiver "github.com/mholt/archiver/v3"
25+
"github.com/mholt/archiver/v3"
2626
"github.com/urfave/cli"
2727
)
2828

@@ -439,8 +439,23 @@ func addRecursiveExclude(w archiver.Writer, insidePath, absPath string, excludeA
439439
}
440440
}
441441
} else {
442-
if err = addFile(w, currentInsidePath, currentAbsPath, verbose); err != nil {
443-
return err
442+
// only copy regular files and symlink regular files, skip non-regular files like socket/pipe/...
443+
shouldAdd := file.Mode().IsRegular()
444+
if !shouldAdd && file.Mode()&os.ModeSymlink == os.ModeSymlink {
445+
target, err := filepath.EvalSymlinks(currentAbsPath)
446+
if err != nil {
447+
return err
448+
}
449+
targetStat, err := os.Stat(target)
450+
if err != nil {
451+
return err
452+
}
453+
shouldAdd = targetStat.Mode().IsRegular()
454+
}
455+
if shouldAdd {
456+
if err = addFile(w, currentInsidePath, currentAbsPath, verbose); err != nil {
457+
return err
458+
}
444459
}
445460
}
446461
}

0 commit comments

Comments
 (0)