]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Do not report a sparse block if its offset is zero and its length is
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 6 Feb 2010 01:41:47 +0000 (20:41 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 6 Feb 2010 01:41:47 +0000 (20:41 -0500)
the same as its file size. In this case, the file is not sparse.

SVN-Revision: 1879

libarchive/archive_read_disk_entry_from_file.c
libarchive/test/test_sparse_basic.c

index 63e6c0c4960fe76b11afbcfbcb29da3f341c4a8a..94c2dca29b0c47f75a112853e43b84bf83495833 100644 (file)
@@ -651,6 +651,11 @@ setup_sparse(struct archive_read_disk *a,
                                int64_t length = fe->fe_length;
                                if (fe->fe_logical + length > size)
                                        length -= fe->fe_logical + length - size;
+                               if (fe->fe_logical == 0 && length == size) {
+                                       /* This is not sparse. */
+                                       do_fiemap = 0;
+                                       break;
+                               }
                                if (length > 0)
                                        archive_entry_sparse_add_entry(entry,
                                            fe->fe_logical, length);
@@ -734,6 +739,8 @@ setup_sparse(struct archive_read_disk *a,
                        exit_sts = ARCHIVE_FAILED;
                        goto exit_setup_sparse;
                }
+               if (off_s == 0 && off_e == size)
+                       break;/* This is not spase. */
                archive_entry_sparse_add_entry(entry, off_s,
                        off_e - off_s);
                off_s = off_e;
@@ -796,7 +803,8 @@ setup_sparse(struct archive_read_disk *a,
        if ((info.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
                goto exit_setup_sparse;/* Not sparse file */
 
-       GetFileSizeEx(handle, &fsize);
+       fsize.HighPart = info.nFileSizeHigh;
+       fsize.LowPart = info.nFileSizeLow;
        range.FileOffset.QuadPart = 0;
        range.Length.QuadPart = fsize.QuadPart;
        outranges_size = 2048;
@@ -838,6 +846,10 @@ setup_sparse(struct archive_read_disk *a,
                                DWORD i, n;
 
                                n = retbytes / sizeof(outranges[0]);
+                               if (n == 1 &&
+                                   outranges[0].FileOffset.QuadPart == 0 &&
+                                   outranges[0].Length.QuadPart == fsize.QuadPart)
+                                       break;/* This is not sparse. */
                                for (i = 0; i < n; i++)
                                        archive_entry_sparse_add_entry(entry,
                                            outranges[i].FileOffset.QuadPart,
index 16f2cf30c050727853c80b9b97e4009ec9bb3233..3a5486f23189cfaaca5f167a64f06d00029a7a59 100644 (file)
@@ -331,7 +331,7 @@ DEFINE_TEST(test_sparse_basic)
        verify_sparse_file(a, path, sparse_file2, 20);
 
        strcpy(p, "/file3");
-       verify_sparse_file(a, path, sparse_file3, 1);
+       verify_sparse_file(a, path, sparse_file3, 0);
 
        archive_read_finish(a);
 }