]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Reverse-merge r1394 from release/2.7 branch: Fix sparse
authorTim Kientzle <kientzle@gmail.com>
Thu, 27 Aug 2009 04:25:42 +0000 (00:25 -0400)
committerTim Kientzle <kientzle@gmail.com>
Thu, 27 Aug 2009 04:25:42 +0000 (00:25 -0400)
file handling on systems that lack ftruncate().

SVN-Revision: 1395

libarchive/archive_write_disk.c

index 99e15a1087909aa845dd59f58e6ebb2c3587e5fb..36853370e007c4503cfce89f9292c26bb16b689a 100644 (file)
@@ -696,15 +696,18 @@ _archive_write_finish_entry(struct archive *_a)
                }
 #endif
                /*
-                * Explicitly stat the file as some platforms might not
-                * implement the XSI option to extend files via ftruncate.
+                * Not all platforms implement the XSI option to
+                * extend files via ftruncate.  Stat() the file again
+                * to see what happened.
                 */
                a->pst = NULL;
                if ((ret = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK)
                        return (ret);
-               if (a->st.st_size != a->filesize) {
+               /* We can use lseek()/write() to extend the file if
+                * ftruncate didn't work or isn't available. */
+               if (a->st.st_size < a->filesize) {
                        const char nul = '\0';
-                       if (lseek(a->fd, a->st.st_size - 1, SEEK_SET) < 0) {
+                       if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) {
                                archive_set_error(&a->archive, errno,
                                    "Seek failed");
                                return (ARCHIVE_FATAL);