Skip to content

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 <hackzhuyan@gmail.com>

* Update archiver.go

---------

Signed-off-by: Yan Zhu <hackzhuyan@gmail.com>
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
  • Loading branch information
halfcrazy and mholt committed 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
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.