Merge r4085 from trunk: Simplify finalizing the file size when

writing files on Windows.

SVN-Revision: 4138
This commit is contained in:
Tim Kientzle committed 2012-01-12 01:46:14 -05:00
1 parent 67c5c2a443
commit f443d1a06e
1 file changed
+1 -38
+1 -38
View File
@@ -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. */