1

作为自动化部署管道的一部分,我正在创建一个tar.gz文件,maven-assembly-plugin然后使用 pythontarfile模块将其解包。

提取失败,但有以下异常:

Traceback (most recent call last): File "tarfile-assembly-testcase/extract_tar.py", line 20, in <module> tarfile.open(fileobj=f, mode='r:gz') File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1676, in open return func(name, filemode, fileobj, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1725, in gzopen **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1703, in taropen return cls(name, mode, fileobj, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1572, in __init__ self.firstmember = self.next() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 2335, in next raise ReadError(str(e)) ReadError: invalid header

压缩和未压缩的 tar 文件都会发生这种情况。可以从命令行解压缩相同的文件。我已经用bsdtar 2.8.3and对其进行了测试tar (GNU tar) 1.26。我正在使用python 2.7.

请尝试我在 github 上发布的演示。这是一个 maven 项目,运行 mvn package 它将创建一个包含项目源的 tar.gz(仅 pom.xml)。包含的 python 脚本尝试使用tarfile.

有什么想法可以maven-assembly-plugin和 pythontarfile一起玩吗?

4

1 回答 1

3

我发现了问题。复制我在 Stackoverflow 中找到的解决方案(请参阅“版本固定”段落)以供后代使用。

maven-assembly-plugin2.4 版开始导入一个有缺陷的plexus-archiver. 强制maven-assembly-plugin使用最新plexus-archiver的就行了。正如链接帖子中所建议的那样,我也升级了plexus-io.

这是代码

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-archiver</artifactId>
            <version>2.4.4</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-io</artifactId>
            <version>2.0.10</version>
        </dependency>
    </dependencies>
</plugin>
于 2014-03-11T18:57:16.493 回答