Skip to content

Commit 0097dc4

Browse files
Guard against unneeded overwrite
1 parent 3f3136f commit 0097dc4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

dgraphtest/image.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ func copy(src, dst string) error {
199199
return errors.Errorf("%s is not a regular file", src)
200200
}
201201

202+
// Check if destination already exists and matches source size
203+
if destStat, err := os.Stat(dst); err == nil {
204+
if destStat.Size() == sourceFileStat.Size() {
205+
log.Printf("[INFO] destination file %s already exists with matching size, skipping copy", dst)
206+
return nil
207+
}
208+
log.Printf("[WARNING] destination file %s exists but size mismatch (source=%d, dest=%d), will overwrite",
209+
dst, sourceFileStat.Size(), destStat.Size())
210+
}
211+
202212
// Open source file
203213
source, err := os.Open(src)
204214
if err != nil {

0 commit comments

Comments
 (0)