From: Tim Kientzle Date: Thu, 12 Jan 2012 06:46:14 +0000 (-0500) Subject: Merge r4085 from trunk: Simplify finalizing the file size when X-Git-Tag: v3.0.3~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f443d1a06ea871a4121e30fdeb51a0dc244acf58;p=thirdparty%2Flibarchive.git Merge r4085 from trunk: Simplify finalizing the file size when writing files on Windows. SVN-Revision: 4138 --- diff --git a/libarchive/archive_write_disk_windows.c b/libarchive/archive_write_disk_windows.c index 910431564..8300e2e91 100644 --- a/libarchive/archive_write_disk_windows.c +++ b/libarchive/archive_write_disk_windows.c @@ -1062,48 +1062,11 @@ _archive_write_disk_finish_entry(struct archive *_a) /* Last write ended at exactly the filesize; we're done. */ /* Hopefully, this is the common case. */ } else { - if (la_ftruncate(a->fh, a->filesize) == -1 && - a->filesize == 0) { + if (la_ftruncate(a->fh, a->filesize) == -1) { archive_set_error(&a->archive, errno, "File size could not be restored"); return (ARCHIVE_FAILED); } - /* - * 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 = lazy_stat(a)) != ARCHIVE_OK) - return (ret); - /* We can use lseek()/write() to extend the file if - * ftruncate didn't work or isn't available. */ - if (bhfi_size(&(a->st)) < a->filesize) { - const char nul = '\0'; - LARGE_INTEGER distance; - distance.QuadPart = a->filesize - 1; - if (!SetFilePointerEx_perso(a->fh, distance, NULL, FILE_BEGIN)) { - DWORD lasterr = GetLastError(); - if (lasterr == ERROR_ACCESS_DENIED) - errno = EBADF; - else - la_dosmaperr(lasterr); - archive_set_error(&a->archive, errno, - "Seek failed"); - return (ARCHIVE_FATAL); - } - if (!WriteFile(a->fh, &nul, 1, NULL, NULL)) { - DWORD lasterr = GetLastError(); - if (lasterr == ERROR_ACCESS_DENIED) - errno = EBADF; - else - la_dosmaperr(lasterr); - archive_set_error(&a->archive, errno, - "Write to restore size failed"); - return (ARCHIVE_FATAL); - } - a->pst = NULL; - } } /* Restore metadata. */