Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 从Ant-tar任务打包的.tar.gz中提取时包含非拉丁字符的文件名的编码_Linux_Ant_Encoding_Tar - Fatal编程技术网

Linux 从Ant-tar任务打包的.tar.gz中提取时包含非拉丁字符的文件名的编码

Linux 从Ant-tar任务打包的.tar.gz中提取时包含非拉丁字符的文件名的编码,linux,ant,encoding,tar,Linux,Ant,Encoding,Tar,我正在使用Ant构建tar.gz存档: <tar destfile="${linux86.zip.file}" compression="gzip" longfile="gnu"> <tarfileset dir="${work.dir}/data" dirmode="755" filemode="755" prefix="${app.folder}/data"/> </tar> 存档是建立在Windows上的

我正在使用Ant构建tar.gz存档:

<tar destfile="${linux86.zip.file}" compression="gzip" longfile="gnu">
    <tarfileset dir="${work.dir}/data" dirmode="755" filemode="755"  
                prefix="${app.folder}/data"/>
</tar>

存档是建立在Windows上的。在Ubuntu上解压后,12个文件名中包含非拉丁字符(例如西里尔字母)的文件名被破坏


有没有办法解决这个问题?

没有。Tar归档文件只支持ascii文件名。请参见以下问题:。我认为你需要另一种形式或工具,更现代的设计


请注意,有
编码
属性,也许这种格式可以工作?

我在Ant的开发者邮件列表(,)和ASF Bugzilla(,)中找到了一些有趣的信息。这一问题由来已久,众所周知,主要由于意识形态原因尚未得到解决,因为并非所有联塔权力机构的执行都支持这一点

Bugzilla发行版中提到的补丁已在修订版中应用。tar中的条目名有一个名为encoding的构造函数:

public TarOutputStream(OutputStream os, String encoding) { ... }
但它从未用于Tar任务。因此,我在Tar任务中创建了一个编码属性,从修改过的源代码中重建了Ant,并使用UTF-8作为条目名称的编码

在Ubuntu11/12和Mandriva下进行了提取测试。

我找到了解决方案,非常感谢Jarekczek,但我没有正确地解码名称。我修复了脚本,如下所示:

#!/usr/bin/env python

# Huge thanks to https://superuser.com/questions/60379/how-can-i-create-a-zip-tgz-in-linux-such-that-windows-has-proper-filenames#190786
# and http://stackoverflow.com/questions/12456560/encoding-of-filenames-containing-non-latin-characters-while-extracting-from-tar
import tarfile
import codecs
import sys

def recover(name):
    return codecs.decode(name, 'cp1251')

for tar_filename in sys.argv[1:]:
    tar = tarfile.open(name=tar_filename, mode='r', bufsize=16*1024)
    updated = []
    for m in tar.getmembers():
        m.name = recover(m.name)
        updated.append(m)
    tar.extractall(members=updated)
    tar.close()

我所做的是使用Python的标准库编解码器和命令行界面将Windows中的名称解码为utf,以向其提供归档文件的名称。

我们使用tar/gzip来保存权限。不幸的是,我不能按照你的建议使用zip。我明白了。如果值得的话,你可以分析Ubuntu上创建的tar的内容。然后编写一个程序来编辑Windows tar,并将文件名转换为适合Ubuntu的格式。或者开发自定义untar任务来进行文件名转换。Tar格式的文档链接自我上面链接的答案。有人用Python做了类似的事情:我很高兴你找到了解决方案。我想发布更多信息,但你更快了。无论如何,这里有另一个与您的问题相关的bug条目。如果我读得正确,Ant1.9中可能有某种编码支持,由
longfile=“posix”
触发。