From fd0958c8bc286f6ae598d26c127ce9074db5928e Mon Sep 17 00:00:00 2001 From: Nate Rosenblum Date: Fri, 5 Feb 2016 06:28:58 -0800 Subject: [PATCH] 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. --- libarchive/test/test_sparse_basic.c | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); -- 2.47.2