]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge r4085 from trunk: Simplify finalizing the file size when
authorTim Kientzle <kientzle@gmail.com>
Thu, 12 Jan 2012 06:46:14 +0000 (01:46 -0500)
committerTim Kientzle <kientzle@gmail.com>
Thu, 12 Jan 2012 06:46:14 +0000 (01:46 -0500)
writing files on Windows.

SVN-Revision: 4138

libarchive/archive_write_disk_windows.c

index 910431564af062b151f1a867f4c49868652e1f5f..8300e2e91c19b1bac6cfbf47045accb009cf613d 100644 (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. */