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

Commit 09bbccc

Browse files
halfcrazymholt
andauthored
Fix create archive to a continuous writing source file failed (#388)
* 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>
1 parent aa12f39 commit 09bbccc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

archiver.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,14 @@ func openAndCopyFile(file File, w io.Writer) error {
221221
return err
222222
}
223223
defer fileReader.Close()
224-
_, err = io.Copy(w, fileReader)
225-
return err
224+
// When file is in use and size is being written to, creating the compressed
225+
// file will fail with "archive/tar: write too long." Using CopyN gracefully
226+
// handles this.
227+
_, err = io.CopyN(w, fileReader, file.Size())
228+
if err != nil && err != io.EOF {
229+
return err
230+
}
231+
return nil
226232
}
227233

228234
// fileIsIncluded returns true if filename is included according to

0 commit comments

Comments
 (0)