snoyberg / tar-conduit

Conduit based tar extraction mechanism
MIT License
8 stars 9 forks source link

Create intermediate directories when expanding #27

Closed luispedro closed 5 years ago

luispedro commented 5 years ago

This matches the behaviour of command-line tar as well as other tar utilities.

closes #26

I tested it on Linux, but also created a Windows version of the code (which I cannot test). Are there automated tests on Windows?

lehins commented 5 years ago

@luispedro thanks for the PR. You are right that it be good to have the prefix directory created whenever a directory type entry is missing from the tarball itself. That said, such a scenario isn't a well formed tarball, for that reason, IMHO, it is better to create that directory only when lenient untarring is taking place. I'll comment directly on the commits with the few minor adjustments.

lehins commented 5 years ago

Also, to answer your question question:

Are there automated tests on Windows?

Yes there are. AppVeyor is setup and is currently failing for this PR due to my comment

I do have a question about the test file subdir.tar. What program did you use to create that tarball? It is really odd (note the 10K size on a single file tarball with "Hello World" in it), since instead of two blank 512 blocks in it at the end, it is padded with 18 of them.

luispedro commented 5 years ago

I do have a question about the test file subdir.tar. What program did you use to create that tarball?

tar (GNU tar) 1.29

On my Ubuntu machine:

$ mkdir -p dir/subdir
$ echo "Hello World" > dir/subdir/file.txt
$ tar cf testing.tar dir/subdir/file.txt
$ ls -l testing.tar 
-rw-rw-r-- 1 luispedro luispedro 10240 Jan 14 01:02 testing.tar

Note, if I use tar cf testing.tar dir, then tar will create the entries for the subdirectories. In either case, when expanding, tar always creates the intermediate dirs.

lehins commented 5 years ago

Very interesting, didn't know about the default record size of 20 blocks for gnu tar:

In a standard tar file (no options), the block size is 512 and the record size is 10240, for a blocking factor of 20.

So, doing:

$ tar cf testing.tar dir/subdir/file.txt --blocking-factor=1

would create a 2K file, instead of 10K. Here is the history behind it, in case you are interested: https://www.gnu.org/software/tar/manual/html_node/Blocking.html

In any case, travis CI is still failing, cause the test file wasn't added to the cabal file's extra-source-files. But don't worry about, I'll fix that and make a release in a little bit.