classification
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
process
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("foo...bar..", "zip", os.path.abspath("c:/test"))

create zipfile called "foo...bar.zip" not "foo...bar...zip"
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('demo...bar..', 'zip', os.path.abspath('/tmp/demo'))
'/tmp/demo/demo...bar...zip'
>>> 

ls -l /tmp/demo
-rw-r--r--. 1 stephane stephane 226 13 fév 10:45 demo...bar...zip
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("foo...bar..", "zip", os.path.abspath("./Tools"))'
➜  cpython git:(master) ✗ ls foo...bar...zip
foo...bar...zip
➜  cpython git:(master) ✗ rm foo...bar...zip
➜  cpython git:(master) python3.7 -c 'import os, shutil; shutil.make_archive("foo...bar..", "zip", os.path.abspath("./Tools"))'
➜  cpython git:(master) ✗ ls foo...bar...zip
foo...bar...zip
msg335422 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-02-13 11:51
Could be the case that it's windows specific. For "foo...bar..." abspath returns "foo...bar..." 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 : https://dotnetfiddle.net/PhRr98.
msg335446 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-02-13 14:26
On windows os.path.abspath("foo...bar..") returns "foo...bar" which is used in shutil.make_archive [0] returning foo...bar.zip. @matrixise , I am reopening this and adding Windows so that this can be confirmed as known behavior and closed.

https://github.com/python/cpython/blob/dcb68f47f74b0cc8a1896d4a4c5a6b83c0bbeeae/Lib/shutil.py#L964
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 (https://github.com/python/cpython/pull/17435) 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.
History
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