bash 解压缩 - 警告和地图名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21322416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:21:11  来源:igfitidea点击:

Unzip - Warning and Mapname

bashcurlwarningsunzipdirectory-structure

提问by USCFan13

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:

我有一个文件夹,我使用共享链接(不是公共链接)和 curl 从 Dropbox 下载。它作为压缩文件夹下载。我需要在 bash shell 脚本中使用 unzip 解压缩此文件夹。每当解压缩文件夹时,我都会收到以下错误:

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.

为了确保这不是 curl 的奇怪问题,我直接从 Dropbox 下载了该文件夹并再次尝试。我得到了同样的错误。所有文件和子目录都出现了,它们的完整性似乎没有任何问题。使用 GUI 解压缩任一文件夹不会导致任何错误消息。

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

我运行 unzip -l 并注意到一个奇怪的第一个条目:

     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?

我相信正是这个空目录导致了这些问题。我的问题是,有没有办法忽略这个空目录或抑制错误消息(我试过 -qq 没有运气)?或者,我做错了什么/遗漏了什么?

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

我已经对此进行了测试,Mac OSX 10.9.1Ubuntu Linux (Version Unknown)得到了相同的结果。

EDIT: I also tested it with jar xfand it works fine without any errors. Running jar xvfshows 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.

编辑:我也用jar xf它进行了测试,它工作正常,没有任何错误。运行jar xvf表明它created: /。我仍然认为是这个空的、未命名的目录导致了问题,但我似乎无法正确使用我的语法,因此解压缩将忽略它。我只想使用 jar,但我需要能够指定一个输出目录。

回答by Anfuca

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

尝试从命令行解压缩 Dropbox 自动生成的 zip,我也发现了以下消息:

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

I compared Dropbox's zip with a normalzip.

我将 Dropbox 的 zip 与普通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 /.

不同之处在于,在解压时,在 Dropbox 的第一个位置出现了一种类似/.

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

我只是将选项添加-x /到 unzip 命令试图排除它,它对我有用。

回答by mcoolive

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

在我看来,根本问题是存档,而不是您的命令。

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

默认情况下,我们将相对路径存储在 ZIP 文件中。例子:

$ 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.

在您的情况下,存档包含绝对路径。这是邪恶的。因此,您的客户端将绝对路径转换为带有警告的相对路径。