From: Tim Kientzle Date: Thu, 27 Aug 2009 04:25:42 +0000 (-0400) Subject: Reverse-merge r1394 from release/2.7 branch: Fix sparse X-Git-Tag: v2.8.0~409 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95cfd8e4a7cc37f2fdc372b65e514f4eb75ace6c;p=thirdparty%2Flibarchive.git Reverse-merge r1394 from release/2.7 branch: Fix sparse file handling on systems that lack ftruncate(). SVN-Revision: 1395 --- diff --git a/libarchive/archive_write_disk.c b/libarchive/archive_write_disk.c index 99e15a108..36853370e 100644 --- a/libarchive/archive_write_disk.c +++ b/libarchive/archive_write_disk.c @@ -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);