gpt4 book ai didi

python - maven- assembly-plugin 生成与 python 的 tarfile 不兼容的 tar (与 bsdtar 一起使用)

转载 作者:行者123 更新时间:2023-11-30 23:26:55 25 4
gpt4 key购买 nike

作为自动化部署管道的一部分,我正在创建一个 tar.gz文件 maven-assembly-plugin然后用 python 的 tarfile 解压它模块。

提取失败,但出现以下异常:


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.3 对其进行了测试和tar (GNU tar) 1.26 。我正在使用python 2.7 .

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

有什么想法可以做 maven-assembly-plugin和Python的tarfile一起玩得好吗?

最佳答案

我发现了问题。复制我找到的解决方案 here (see "Version pinning" paragraph)在 Stackoverflow 中为子孙后代提供帮助。

从版本 2.4 开始,maven-assemble-plugin 导入了有错误的 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>

关于python - maven- assembly-plugin 生成与 python 的 tarfile 不兼容的 tar (与 bsdtar 一起使用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22333243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com