Title: shutil make_archive create wrong file when base name contains dots at end
Type: behavior Stage: patch review
Components: Distutils, Windows Versions: Python 3.9, Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dstufft, eric.araujo, highwind, kinow, matrixise, paul.moore, steve.dower, tim.golden, xtreak, zach.ware
Priority: normal Keywords: patch, patch

Created on 2019-02-13 07:15 by highwind, last changed 2019-12-02 03:18 by kinow.

Pull Requests
URL Status Linked Edit
PR 17435 open kinow, 2019-12-02 03:16
PR 17435 open kinow, 2019-12-02 03:16
Messages (7)
msg335388 - (view) Author: maokk (highwind) Date: 2019-02-13 07:15
shutil.make_archive("", "zip", os.path.abspath("c:/test"))

create zipfile called "" not ""
msg335396 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-02-13 09:47
I have just tried with 3.7.2 and I don't get your error.

Python 3.7.2 (default, Jan 16 2019, 19:49:22) 
[GCC 8.2.1 20181215 (Red Hat 8.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> import os
>>> shutil.make_archive('', 'zip', os.path.abspath('/tmp/demo'))

ls -l /tmp/demo
-rw-r--r--. 1 stephane stephane 226 13 fév 10:45
msg335397 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-02-13 09:49
Is this Windows specific? I am unable to reproduce this on Mac and Ubuntu with master and Python 3.7 .

➜  cpython git:(master) ./python.exe -c 'import os, shutil; shutil.make_archive("", "zip", os.path.abspath("./Tools"))'
➜  cpython git:(master) ✗ ls
➜  cpython git:(master) ✗ rm
➜  cpython git:(master) python3.7 -c 'import os, shutil; shutil.make_archive("", "zip", os.path.abspath("./Tools"))'
➜  cpython git:(master) ✗ ls
msg335422 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-02-13 11:51
Could be the case that it's windows specific. For "" abspath returns "" in Python on Mac. I don't have access to Windows but checking this on dotnet fiddle with C# which I hope uses Windows full path strips out the leading dots which I think could be a case with os.path.abspath used in make_archive.

Sample fiddle :
msg335446 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-02-13 14:26
On windows os.path.abspath("") returns "" which is used in shutil.make_archive [0] returning @matrixise , I am reopening this and adding Windows so that this can be confirmed as known behavior and closed.
msg351860 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-09-11 13:17
We can fix this - trailing dots before an extension are supported.

Probably the best fix is to defer the "abspath" call until after the extension has been added (or apply "abspath" to the directory and then put the base name back on).
msg357700 - (view) Author: Bruno P. Kinoshita (kinow) * Date: 2019-12-02 03:18
Tested locally on Win10 pro, and both suggestions of steve.dower worked. I've put a PR ( based on his second suggestion.

The rationale being that that way, the format function (zip/bztar/etc) will get the absolute file name. I thought this was less risk then trusting that the format function would work with the relative paths in win/linux/etc.
Date User Action Args
2019-12-02 03:18:32kinowsetnosy: + kinow
messages: + msg357700
2019-12-02 03:16:30kinowsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16915
2019-12-02 03:16:30kinowsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request16914
2019-09-11 13:17:15steve.dowersetmessages: + msg351860
versions: + Python 3.8, Python 3.9
2019-02-13 14:26:23xtreaksetstatus: closed -> open

components: + Windows

nosy: + tim.golden, paul.moore, zach.ware, steve.dower
messages: + msg335446
resolution: rejected ->
stage: resolved -> (no value)
2019-02-13 11:51:24xtreaksetmessages: + msg335422
2019-02-13 09:49:59xtreaksetnosy: + xtreak
messages: + msg335397
2019-02-13 09:47:20matrixisesetstatus: open -> closed

nosy: + matrixise
messages: + msg335396

resolution: rejected
stage: resolved
2019-02-13 07:15:24highwindcreate