Score:1

What does the -W parameter of tar actually do?

tr flag

I am using tar to pack up some data. Before I move it to an archive, I want to check the integrity of the tarball. According to the man page, the parameter -W does a verification:

-W, --verify
Verify the archive after writing it.

I tested this and it seems to do something:

$ tar cvWf tartest.tar tartest/
tartest/
tartest/dir1/
tartest/dir1/bar
tartest/dir2/
tartest/dir2/foobar
Verify tartest/
Verify tartest/dir1/
Verify tartest/dir1/bar
Verify tartest/dir2/
Verify tartest/dir2/foobar

But what exactly does tar verify here? The presence of the files? File size? MD5 sums?

Score:1
cn flag

This took some digging to figure out. In the file src/compare.c in the Git repo for tar, we find a function named verify_volume (on line 527 at the time of writing), which contains the following comment

Verifying an archive is meant to check if the physical media got it correctly, so try to defeat clever in-memory buffering pertaining to this particular media. On Linux, for example, the floppy drive would not even be accessed for the whole verification.

That explains what it tries to do, but as to how it does it, we need to look at the code for the function. It starts off by comparing the headers to make sure they match, and if they do, it runs the function diff_archive (line 461 at the time of writing), which goes item by item inside the archive, and when it encounters a file*, it will run the function diff_file (line 187). It starts by checking a few easy things, such as file type and size (and others). If all of those are correct, it (for a normal file) goes and verifies each block of the file (in the read_and_process function, line 120). For sparse files, it calls the sparse_diff_file (line 698) in src/sparse.c, which checks each region of the file** using the check_sparse_region function (line 607), also in src/sparse.c.

*It does other things for other types of archived data, such as directories

**It checks each region in a similar way that it checks an entire normal (non-sparse) file

Wayne_Yux avatar
tr flag
Oh wow, so it does way more, than I was expecting - great! Thanks a lot!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.