From: Nate Rosenblum Date: Fri, 5 Feb 2016 14:28:58 +0000 (-0800) Subject: Fix sparse tests with holes at the end X-Git-Tag: v3.1.901a~9^2~3^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd0958c8bc286f6ae598d26c127ce9074db5928e;p=thirdparty%2Flibarchive.git Fix sparse tests with holes at the end 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. --- diff --git a/libarchive/test/test_sparse_basic.c b/libarchive/test/test_sparse_basic.c index fc3d56c54..1541155fe 100644 --- a/libarchive/test/test_sparse_basic.c +++ b/libarchive/test/test_sparse_basic.c @@ -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);