Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Fix create archive to a continuous writing source file failed (#388)
Browse files Browse the repository at this point in the history
* Fix create archive to a continuous writing source file failed

#387
Signed-off-by: Yan Zhu <[email protected]>

* Update archiver.go

---------

Signed-off-by: Yan Zhu <[email protected]>
Co-authored-by: Matt Holt <[email protected]>
  • Loading branch information
halfcrazy and mholt authored Dec 13, 2023
1 parent aa12f39 commit 09bbccc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,14 @@ func openAndCopyFile(file File, w io.Writer) error {
return err
}
defer fileReader.Close()
_, err = io.Copy(w, fileReader)
return err
// When file is in use and size is being written to, creating the compressed
// file will fail with "archive/tar: write too long." Using CopyN gracefully
// handles this.
_, err = io.CopyN(w, fileReader, file.Size())
if err != nil && err != io.EOF {
return err
}
return nil
}

// fileIsIncluded returns true if filename is included according to
Expand Down

0 comments on commit 09bbccc

Please sign in to comment.