diff --git a/archiver.go b/archiver.go index 73ec00d4..1701b078 100644 --- a/archiver.go +++ b/archiver.go @@ -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