Issue 21280: shutil.make_archive() with default "root_dir" parameter raises FileNotFoundError: [Errno 2] No such file or directory: '' (original) (raw)

from shutil import make_archive; make_archive("a", "tar") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/shutil.py", line 783, in make_archive filename = func(base_name, base_dir, **kwargs) File "/usr/lib/python3.4/shutil.py", line 605, in _make_tarball os.makedirs(archive_dir) File "/usr/lib/python3.4/os.py", line 244, in makedirs mkdir(name, mode) FileNotFoundError: [Errno 2] No such file or directory: ''

Looking at the code, it calls os.path.dirname("a.tar") -> "", which would be the cause of this bug.

The workaround for me was adding an explicit make_archive(root_dir=".") parameter.

I was also surprised to see the code calling os.makedirs(archive_dir). Usually if you try to make a file in a non-existent directory, it fails, rather than automatically creating the directory for you. But maybe that’s just a general spirit of the “shutil” module that I didn’t pick up on.