PyFilesystem无法在tar-fs中找到现有文件

时间:2018-04-13 07:32:27

标签: python-3.x tar

我写了一个小脚本来下载并提取VSCode:

#!/usr/bin/env python
import requests
import shutil
from io import BytesIO
from fs.tarfs import TarFS
from fs.copy import copy_fs

target_install_path = "~/Downloads/VSCode"
dl_link = "https://go.microsoft.com/fwlink/?LinkID=620884"

print("Sending Requests")
r = requests.get(dl_link, stream=True)
if not r.status_code == 200:
    print("Error, status code: ", r.status_code)
    exit()

tar_data = BytesIO()
print("Downloading Data")
shutil.copyfileobj(r.raw, tar_data)
tar_data.seek(0)
tar_fs = TarFS(tar_data)
print("Extracting")
copy_fs(tar_fs, target_install_path)

问题是,在执行期间会发生以下错误:

Traceback (most recent call last):
  File "~/miniconda3/lib/python3.6/site-packages/fs/tarfs.py", line 259, in getinfo
    member = self._tar.getmember(self._encode(_path))
  File "/~/miniconda3/lib/python3.6/tarfile.py", line 1749, in getmember
    raise KeyError("filename %r not found" % name)
KeyError: "filename 'VSCode-linux-x64/resources/app/extensions/typescript-language-features/node_modules/diagnostic-channel' not found"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./update_vscode", line 23, in <module>
    copy_fs(tar_fs, target_install_path)
  File "~/miniconda3/lib/python3.6/site-packages/fs/copy.py", line 31, in copy_fs
    walker=walker, on_copy=on_copy)
  File "~/miniconda3/lib/python3.6/site-packages/fs/copy.py", line 225, in copy_dir
    for dir_path, dirs, files in walker.walk(src_fs, _src_path):
  File "~/miniconda3/lib/python3.6/site-packages/fs/walk.py", line 269, in walk
    for dir_path, info in _walk:
  File "~/miniconda3/lib/python3.6/site-packages/fs/walk.py", line 340, in _walk_breadth
    for info in self._scan(fs, dir_path, namespaces=namespaces):
  File "~/miniconda3/lib/python3.6/site-packages/fs/walk.py", line 236, in _scan
    six.reraise(type(error), error)
  File "~/miniconda3/lib/python3.6/site-packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
fs.errors.ResourceNotFound: resource '/VSCode-linux-x64/resources/app/extensions/typescript-language-features/node_modules/diagnostic-channel' not found

如果我将r.raw复制到磁盘上的文件对象,然后使用tar提取它,那么fs_copy找不到的文件就在那里。

有人有想法,问题可能是什么? 我使用python 3.6和fs 2.0.20

1 个答案:

答案 0 :(得分:1)

这是PyFilesystem库中的一个错误,有关详细信息,请参阅:https://github.com/PyFilesystem/pyfilesystem2/issues/160