This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: shutil.make_archive() with default "root_dir" parameter raises FileNotFoundError: [Errno 2] No such file or directory: ''
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: hynek, martin.panter, python-dev, serhiy.storchaka, tarek
Priority: normal Keywords: patch

Created on 2014-04-17 08:09 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
shutil_make_archive_in_curdir.patch serhiy.storchaka, 2014-11-18 20:14 review
Messages (3)
msg216672 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2014-04-17 08:09
>>> from shutil import make_archive; make_archive("a", "tar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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.
msg231339 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-18 20:14
Here is a patch.
msg231786 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-11-27 22:53
New changeset 8fa9097eadcb by Serhiy Storchaka in branch '3.4':
Issue #21280: Fixed a bug in shutil.make_archive() when create an archive of
https://hg.python.org/cpython/rev/8fa9097eadcb

New changeset c605dcf9786f by Serhiy Storchaka in branch 'default':
Issue #21280: Fixed a bug in shutil.make_archive() when create an archive of
https://hg.python.org/cpython/rev/c605dcf9786f

New changeset c7d45da654ee by Serhiy Storchaka in branch '2.7':
Issue #21280: Fixed a bug in shutil.make_archive() when create an archive of
https://hg.python.org/cpython/rev/c7d45da654ee
History
Date User Action Args
2022-04-11 14:58:02adminsetgithub: 65479
2014-11-27 22:56:34serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-11-27 22:53:12python-devsetnosy: + python-dev
messages: + msg231786
2014-11-18 20:14:45serhiy.storchakasetfiles: + shutil_make_archive_in_curdir.patch

type: behavior
assignee: serhiy.storchaka
versions: + Python 3.5
keywords: + patch
nosy: + hynek, tarek, serhiy.storchaka

messages: + msg231339
stage: patch review
2014-04-17 08:09:59martin.pantercreate