aiidateam/archive-path

Doen't works with rooted archives ('/' not stripped from names)

Opened this issue · 0 comments

Example code

>>> import archive_path,tarfile,os,sys,io
>>> randbytes=io.BytesIO()
>>> randbytes.write(secrets.token_bytes(100))
100
>>> randbytes.seek(0)
0
>>> randbytes=BytesIO()
>>> fd=BytesIO()
>>> tf=tarfile.TarFile(':memory:','w',fileobj=fd)
>>> tf.addfile(tarfile.TarInfo('/bin/garbage'),randbytes)
>>> tf.getmembers()
[<TarInfo '/bin/garbage' at 0x6fffff04c1c0>]
>>> tf._filepath=tf.name
>>> tf._tarfile=tf
>>> tp=archive_path.TarPath(tf,at='/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/archive_path/tar_path.py", line 86, in __init__
    raise ValueError(f"'at' cannot be an absolute path: {at}")
ValueError: 'at' cannot be an absolute path: /
>>> tp=archive_path.TarPath(tf,at='')
>>> list(tp.iterdir())
[]
>>> list(tp._all_at_set())
['', '/bin/garbage', '/bin']

Real result

Empty result of iterdir().

Expected result

All directories under root (`['bin'] in example above).

Real life example

Following command generates rooted archive:

docker cp container_name:/ - >export.tar