RKrahl / archive-tools

Tools for managing archives
Apache License 2.0
1 stars 2 forks source link

Spurious FileNotFoundError from Archive.create() when passing a relative path as workdir argument #53

Closed RKrahl closed 3 years ago

RKrahl commented 3 years ago

The Archive.create() features a workdir keyword argument, the method is supposed to temporarily change to that directory if given, see #20. This works as expected if the working directory is absolute, but fails when passing a relative path.

Consider the following setup:

$ ls -laR work
work:
total 0
drwxr-xr-x 1 rolf rk   8 May  1 12:35 .
drwxr-xr-x 1 rolf rk 278 May  1 12:35 ..
drwxr-xr-x 1 rolf rk   8 May  1 12:35 base

work/base:
total 0
drwxr-xr-x 1 rolf rk  8 May  1 12:35 .
drwxr-xr-x 1 rolf rk  8 May  1 12:35 ..
drwxr-xr-x 1 rolf rk 14 May  1 12:35 data

work/base/data:
total 4
drwxr-xr-x 1 rolf rk  14 May  1 12:35 .
drwxr-xr-x 1 rolf rk   8 May  1 12:35 ..
-rw-r--r-- 1 rolf rk 385 Apr 18 23:11 rnd.dat

Now, creating an archive passing an absolute path as workdir works as expected:

>>> workdir = Path.cwd() / "work"
>>> Archive().create(Path("archive-abs.tar"), "", [Path("base")], workdir=workdir)
>>> (workdir / "archive-abs.tar").is_file()
True

Trying the same using a relative path fails:

>>> workdir = Path("work")
>>> Archive().create(Path("archive-rel.tar"), "", [Path("base")], workdir=workdir)
Traceback (most recent call last):
  ...
FileNotFoundError: [Errno 2] No such file or directory: 'work/archive-rel.tar'