使用python的tarfile模块,有没有办法指定tar的Q选项的等价物(注意:Haiku具体)?
tar --help
-Q, --replace-hardlinks replace hardlinks with corresponding symlink when
extracting
目前代码基本上是:
tarFile = tarfile.open(archiveFile, 'r')
members = None
if subdir:
members = [
member for member in tarFile.getmembers()
if member.name.startswith(subdir)
]
tarFile.extractall(targetBaseDir, members)
tarFile.close()
答案 0 :(得分:0)
您可以使用成员返回的islink()
对象的TarInfo
方法解决此问题。如下所示:
tarFile = tarfile.open(archiveFile, 'r')
for member in tarFile.getmembers():
if member.islnk():
# code for handling links
else:
tarFile.extract(targetBaseDir, member)
tarFile.close()