/* 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. */