Unzip - Warning and Mapname
Asked Answered
C

2

19

I have a folder that I download from Dropbox using a shared link (not public link) and curl. It is downloaded as a zipped folder. I need to unzip this folder using unzip in a bash shell script. Whenever the folder is unzipped, I get the following errors:

warning:  stripped absolute path spec from /
mapname:  conversion of  failed

Just to make sure that it was not a weird issue with curl, I downloaded the folder directly from Dropbox and tried it again. I got the same error. All of the files and subdirectories appear, and there does not seem to be any problem with their integrity. Unzipping either folder with the GUI results in no error messages.

I ran unzip -l and noticed an odd first entry:

     Length   Method    Size  Ratio   Date   Time   CRC-32    Name
    --------  ------  ------- -----   ----   ----   ------    ----
           0  Defl:N        2   0%  01-23-14 19:38  00000000  /

I believe that it is this empty directory that is causing the issues. My question is, is there any way to ignore this empty directory or to suppress the error messages (I tried -qq with no luck)? Or, is there something that I am doing wrong/missing?

I have tested this on Mac OSX 10.9.1 and Ubuntu Linux (Version Unknown) with the same results.

EDIT: I also tested it with jar xf and it works fine without any errors. Running jar xvf shows that it created: /. I still think it is this empty, unnamed directory that is causing the issue, but I can't seem to get my syntax right so that unzip will ignore it. I would just use jar, but I need to be able to specify an output directory.

Castaneda answered 24/1, 2014 at 0:55 Comment(6)
You could try explicitly extracting the other files in the archive by name, e. g. unzip /path/to/filename.zip filename.ext file2.ext to extract filename.ext and file2.ext from the archive.Rapscallion
Thanks! I did consider this, but once the shell script is finished it will be handed off and I will not be able to maintain it. There is a good possibility that the contents of the folder could change. It actually works fine the way it is now, the errors/warnings are just annoying and may alarm the end user.Castaneda
You can always suppress the warnings with 2> /dev/null. Also, you can exclude the problem children with -x as another option.Rapscallion
I had forgotten about /dev/null. I tried the -x option, but the problem child is an empty directory "/" and I could not seem to get it to work. It may have just been an issue with my syntax though. How would you do it?Castaneda
Would it be safe to send all output to null? What if a legitimate error occurred?Castaneda
If a legit error occurs, it will terminate with a non-zero exit code; you can check $? to verify that the exit code is 0. It's possible that warnings will also give nonzero exit codes, but you can see what the exit code for warnings is and check for that also.Rapscallion
O
16

Trying to unzip from the command line a Dropbox autogenerated zip, I found this message too:

warning:  stripped absolute path spec from /
mapname:  conversion of  failed

I compared Dropbox's zip with a normal zip.

The difference was that, at the time of the unzipping, in the Dropbox's one appears in a first position a kind of file like /.

I just add the option -x / to the unzip command trying to exclude it, and it works for me.

Openeyed answered 12/9, 2016 at 10:25 Comment(2)
-x / should be placed at the end of the unzip command, but before -d argument, if it is used. E.g. unzip INPUT.zip -x / -d OUTPUTDIRSalmonoid
unzip ARCHIVE.zip -x / ### — This works.Tallage
P
2

In my opinion, the root issue is the archive, not your command.

By default, we store relative paths in a ZIP file. Example:

$ zip tmp.zip /home/mcoolive/*txt
adding: home/mcoolive/file1.txt (deflated 73%)
adding: home/mcoolive/file2.txt (deflated 76%)

By default, unzip recreates all files and subdirectories are recreated in the current directory.

In your case, the archive contains absolut paths. It's evil. So your client converts absolut paths into relative paths with a warning.

Personality answered 27/5, 2014 at 23:15 Comment(1)
With some version of UNZIP, it can extract all files with a warning to say the root (first /) is ignored. If you really need a root, you can "chroot" to isolate your process. If you can, prefer ZIP archive with relative paths.Personality

© 2022 - 2024 — McMap. All rights reserved.