New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shutil.make_archive() root_dir do not work #66220
Comments
set root_dir do not work output: Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25:23) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import shutil
>>> shutil.make_archive("tmp.tar.gz", "gztar", "c:/xjtu", "c:/tmp")
'C:\\Python34\\tmp.tar.gz.tar.gz' ===================================================== source code of make_archive() base_name is set before chdir, so the archive always be created in cwd, whether set root_dir or not. |
Thanks for the report, do you want to provide a patch? |
I believe this is working as designed, although the documentation does not make that clear. root dir is the root directory of the *created archive*, it has nothing to do with where the archive file itself is placed. |
I don't think so. In source code, it just change work dir to root_dir, do nothing, and then the change word dir back. If it works as design, the "root_dir" will be meaningless. should be remove. |
Here's the path |
The point *should* be that if you have something like: /home/me/some/directory/my/stuff/a and you set rootdir to '/home/me/some' and base_dir='/home/me/some/directory/my' then the file paths in the archive will be:
At least, that's how I read the docs, though as I said they are *not* clear. (I can't otherwise imagine any reason to have the root_dir parameter, with that name.) Is this not what happens? |
that sounds reasonable |
Sorry to bother. But This patch is still not accepted. I still suffer this issue. Is anyone willing to review this patch? Thanks |
Or, Is there anything I could help? I am glad to help fixing this issue. |
Hi bananaapple, there are two things that need to be addressed:
We can rephrase make_archive() documentation to clarify what root_dir exactly does.
|
Agree with David, this is working as designed (and matching the behavior of say "tar -C"). But the documentation is not clear if not confusing. |
Hello Berker Peksag,
This is not a bug of make_archive() implementation. However, I think documentation is not clear to understand at the first time reading it. Maybe it should be rephrased.
But, this functionality is not provided. I think this functionality will be useful if implemented. What do you think about this? Thank you for your explaination. |
"base_name is the name of the file to create, including the path". So you should be able to specify the path to where you want it created. If that doesn't work, that's a bug. |
I am sorry. I understand now. Thank you. |
I'm similarly confused by this issue. If somebody can help me understand what's going on, I'll put my understanding into a documentation patch. I have created this minimal example to demonstrate what I don't understand: I've created a directory structure within /tmp like this: bpo-22021 Now I'd like to create a zip archive that contains the directories "structure" and "content", and the file "please_add.txt", but not the file "do_not_add.txt". My understanding of the documentation was that I'd have to do this:
But on my system, the created file (/tmp/issue22021archive.zip) looks like this according to unzip -l: Archive: issue22021archive.zip This is consistent with my experience that created archives will always contain directories from / on, which is unexpected to me. It appears this happens whenever base_dir and root_dir is set, but to my understanding the documentation does not warn against this. I've confirmed this behaviour with Python 3.6.5 and Python 3.5.3, but I suspect that doesn't really matter, as it seems to be a documentation issue. |
I think this snippet might help you. shutil.make_archive(base_name='/tmp/issue22021archive', format='zip', root_dir='/tmp/issue22021/root/', base_dir='structure/content/') unzip -l /tmp/issue22021archive.zip Archive: /tmp/issue22021archive.zip |
Thank you, that's what I figured out later last evening. To my understanding, the docs don't give any indication that base_dir is supposed to be relative to root_dir, so I'd add this information, and maybe add a similar example to the one above, if that's appropriate? |
Sounds reasonable to me. |
FYI. Joannah Nanjekye converted bpo-22021.patch into a PR: PR 10191. Serhiy Storchaka closed the PR: "The current behavior looks correct to me. It is consistent with the behavior of the tar command. This change breaks tests and I think it will break user code. Read the discussion on bpo-22021." |
This is a documentation issue. |
Is anybody working on this or can I submit a PR? |
Since Serhiy said that this is a pure documentation issue, I thought that a doc PR is all that was needed, which I would be happy to make. Am I missing something here? |
Yes, this is a documentation issue: A patch clarifying what root_dir and base_dir do, and how they interact (or how they are to be used in combination) would be sufficient to close this issue. |
Ping. |
Pinging once more for review. |
@giampaolo.rodola, would you be able to provide a review of this doc change? Thanks! |
@cheryl.sabella don't have the bandwidth right now (traveling), sorry. |
@giampaolo.rodola, no problem. I intended this more as a general request rather than something for right now. If you do have any availability at some point, please keep this one in mind. Thanks! |
Since #54576 is now merged, should we close this? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: