-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extractAll() for Tarballs in tarPath not extracting files #6
Comments
Picking up where we left off over here: 9a0482b Before I merge a fix in for this issue, I'd like to have a repro so I can see it, keep it in mind as I work, and also to add a test for it, etc. Currently I cannot repro the issue but I believe it is real. To start off, if you don't mind, could you checkout to master of guzba/zippy (head at 1f9fa49), cd to the project base dir, and run Does this also pass for you without changes or do you run into the empty Tarball issue? |
My current theory is that the issue is typeFlag can be '\0' in addition to '0' for normal files (per https://www.gnu.org/software/tar/manual/html_node/Standard.html), but that I currently do not include '\0' here: Line 109 in bd02047
So I'm thinking this may be the fix: if typeFlag == '0' or typeFlag == '\0':
tarball.contents[(fileNamePrefix / fileName).toUnixPath()] =
TarballEntry(
kind: ekNormalFile,
contents: data[pos ..< pos + fileSize]
)
elif typeFlag == '5':
tarball.contents[(fileNamePrefix / fileName).toUnixPath()] =
TarballEntry(
kind: ekDirectory
) This would happen for tarballs created by something other than Zippy since I should always be using '0' for files. |
I have merged and released the above change to address this issue a while back. Feel free to re-open if this issue persists. |
I want to extract a Tarball located at
tarPath
totmpDir
(not existing sub-directory). However, nothing gets extracted.When I extract this Tarball with PeaZip, everything gets extracted perfectly and works fine. However, when I do it with this procedure
the files never get extracted.
There is no exception, no message, nothing. No idea what is going on there.
The Tarball is named properly, suffixed with a
.tar
and works perfectly fine.Update 1
After debugging
tarball.nim
I found out that inside theextractAll
procedure, the loop afterzippy/src/zippy/tarballs.nim
Line 200 in bd02047
Watching
open
, this procedure seems to work fine (but perhaps is not adding the files properly to thetarball
) and finds all filenames from the tarball.Update 2
As expected, the provided
Tarball()
does not have contents, so nothing is extracted, as nothing is provided byopen()
:Getting the above when running
echo tarball.repr
here:zippy/src/zippy/tarballs.nim
Line 200 in bd02047
Update 3
Through further debugging
open()
my suspicion was confirmed:open()
never fills thetarball.contents
; they always remain empty.Update 4
zippy/src/zippy/tarballs.nim
Line 109 in bd02047
The above line ensures that
tarball.contents
are only filled, when thetypeFlag
either equals0
or5
.The problem is:
typeFlag
is always empty!Update 5
zippy/src/zippy/tarballs.nim
Line 100 in bd02047
The above line should ensure, that a valid
fileNamePrefix
is given, if the header is specifying austar
archive.The issue is, that
fileNamePrefix
always remains empty. because neitherheader[345 ..< 500].trim()
norheader[345 ..< 500]
returns any output. Not sure if this is required or optional. It however does not seem to be directly related to the bigger problem at hand, but it's worth noting.Update 6
I found the mistake!
When using
writeTarball()
, the headers for each file are built manually:zippy/src/zippy/tarballs.nim
Lines 136 to 153 in bd02047
Now, when we look at the
tar
standard format, we see that the header byte 156 needs to containchar typeflag;
. Thistypeflag
is meant to be set here:zippy/src/zippy/tarballs.nim
Line 146 in bd02047
Now in this case, the number (from
ord()
) does not get converted to achar
; it returns nothing. That's why thetypeFlag
is missingzippy/src/zippy/tarballs.nim
Line 99 in bd02047
and that is why the files never are put into the
tarball.contents
zippy/src/zippy/tarballs.nim
Lines 109 to 114 in bd02047
and that is why the
Tarball()
is never actually extracted:zippy/src/zippy/tarballs.nim
Lines 201 to 220 in bd02047
The text was updated successfully, but these errors were encountered: