Title: shutil make_archive create wrong file when base name contains dots at end
Type: behavior Stage:
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, matrixise, paul.moore, steve.dower, tim.golden, xtreak, zach.ware
Priority: normal Keywords:

Created on 2019-02-13 07:15 by highwind, last changed 2019-09-11 13:17 by steve.dower.

Messages (6)
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 triager) 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 triager) 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 triager) 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).
Date User Action Args
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 ->
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