]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix sparse tests with holes at the end
authorNate Rosenblum <natr@google.com>
Fri, 5 Feb 2016 14:28:58 +0000 (06:28 -0800)
committerNate Rosenblum <natr@google.com>
Fri, 5 Feb 2016 15:02:14 +0000 (07:02 -0800)
Sparse file creation in test_sparse_basic failed to create holes at
the end of files. These tests don't presently verify the existence of
holes at the end (they are concerned only with the sparse data block
entries), but this change ensures that the input file matches the
expected hole/data layout.

libarchive/test/test_sparse_basic.c

index fc3d56c54f663e134cc9bb4ececb0ae4e999ad84..1541155fefd7d964b9298610ffe6d0558a7c8c4e 100644 (file)
@@ -218,9 +218,19 @@ create_sparse_file(const char *path, const struct sparse *s)
 {
        char buff[1024];
        int fd;
+       size_t total_size = 0;
+       const struct sparse *cur = s;
 
        memset(buff, ' ', sizeof(buff));
        assert((fd = open(path, O_CREAT | O_WRONLY, 0600)) != -1);
+
+       /* Handle holes at the end by extending the file */
+       while (cur->type != END) {
+               total_size += cur->size;
+               ++cur;
+       }
+       assert(ftruncate(fd, total_size) != -1);
+
        while (s->type != END) {
                if (s->type == HOLE) {
                        assert(lseek(fd, s->size, SEEK_CUR) != (off_t)-1);