mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(fileutil): reject copies onto the source file (#379)
This commit is contained in:
1 parent
86dc6c0019
commit
778bd2e14f
2 files changed
+35
No files matched your search
@@ -229,6 +229,13 @@ func CopyFile(srcPath string, dstPath string) error {
|
||||
return err
|
||||
}
|
||||
defer srcFile.Close()
|
||||
srcInfo, err := srcFile.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dstInfo, err := os.Stat(dstPath); err == nil && os.SameFile(srcInfo, dstInfo) {
|
||||
return errors.New("source and destination are the same file")
|
||||
}
|
||||
|
||||
distFile, err := os.Create(dstPath)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user