Skip to content

Commit 294257e

Browse files
committed
feat: Enhance file copy process with verbose logging for better debugging
1 parent 8c28d28 commit 294257e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

pkg/sync/sync.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,40 @@ func (s *Syncer) syncRegularFile(sourcePath, destPath string, fileInfo FileInfo)
386386

387387
// copyFile performs the actual file copy
388388
func (s *Syncer) copyFile(src, dst string) error {
389+
if s.options.Verbose {
390+
fmt.Printf(" Opening source file: %s\n", src)
391+
}
392+
389393
source, err := os.Open(src)
390394
if err != nil {
391-
return err
395+
return fmt.Errorf("failed to open source file %s: %w", src, err)
392396
}
393397
defer source.Close()
394398

399+
if s.options.Verbose {
400+
fmt.Printf(" Creating/overwriting destination file: %s\n", dst)
401+
}
402+
395403
destination, err := os.Create(dst)
396404
if err != nil {
397-
return err
405+
return fmt.Errorf("failed to create destination file %s: %w", dst, err)
398406
}
399407
defer destination.Close()
400408

401-
_, err = io.Copy(destination, source)
402-
return err
409+
if s.options.Verbose {
410+
fmt.Printf(" Copying data from source to destination...\n")
411+
}
412+
413+
bytesWritten, err := io.Copy(destination, source)
414+
if err != nil {
415+
return fmt.Errorf("failed to copy data: %w", err)
416+
}
417+
418+
if s.options.Verbose {
419+
fmt.Printf(" Successfully copied %d bytes\n", bytesWritten)
420+
}
421+
422+
return nil
403423
}
404424

405425
// deleteExtraFiles removes files from destination that don't exist in source

0 commit comments

Comments
 (0)