[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There are possible race conditions. Other process can create the same target directory (if it does not exist yet) by calling os.makedirs() for example. It will be impolite to remove the directory just after the second process checked that it exists (or

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-17 Thread Chris Jerdonek
Chris Jerdonek added the comment: > And since it seems that it can not be solved completely, You may be right only to document, but you didn't note any problems with the possibility I suggested. A cleanup pruning step could be done on failure that is similar to the cleanup pruning step on

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I agree with Giampaolo. The proposed change does not solve the problem completely. And since it seems that it can not be solved completely, I suggest to just better document the current behavior. -- nosy: +serhiy.storchaka

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-13 Thread Joannah Nanjekye
Joannah Nanjekye added the comment: @giampaolo.rodola thanks for insight on tests. I dint catch that at all :) I am working on tests for os.renames() I opened an issue to track that here : https://bugs.python.org/issue35982. IMHO, I think we need to improve the current behavior. This

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-12 Thread Chris Jerdonek
Chris Jerdonek added the comment: > As such the cleanup in case of failure should not be expected, Given that the documentation specifically calls out permissions errors as a cause of leaving the new directory in place, it wouldn't be unreasonable for someone to think the function does a

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-12 Thread Giampaolo Rodola'
Giampaolo Rodola' added the comment: The proposed change makes the problem a lot less likely to occur, but technically it doesn't fix it because if the src file/dir disappears between "os.path.exists(src)" and os.rename(src, dst)" calls you'll end up with a race condition. We may still want

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-12 Thread STINNER Victor
Change by STINNER Victor : -- versions: +Python 3.8 -Python 3.6 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-12 Thread Joannah Nanjekye
Change by Joannah Nanjekye : -- keywords: +patch pull_requests: +11858 stage: -> patch review ___ Python tracker ___ ___

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-10 Thread Ammar Askar
Ammar Askar added the comment: Aah, I interpreted the combination of the warning and the fact that it says "attempted first" to mean that any failures in the actual renaming will leave the new directory in place. That is, no cleanup is ever performed. A quick glance at the code seems to

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-10 Thread Chris Jerdonek
Chris Jerdonek added the comment: Lacking permissions seems very different to me from the source directory or file not existing. For example, in the example I provided, I did have the needed permissions. Incidentally (and this is a separate documentation issue), the note seems unclear as

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-10 Thread Ammar Askar
Ammar Askar added the comment: It seems this behavior is somewhat documented: https://docs.python.org/3/library/os.html#os.renames >Works like rename(), except creation of any intermediate directories needed to >make the new pathname good is attempted first. >This function can fail with the

[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-09 Thread Chris Jerdonek
New submission from Chris Jerdonek : os.renames() creates and leaves behind the intermediate directories if the original (source) path doesn't exist. >>> import os >>> os.mkdir('temp') >>> os.mkdir('temp/test') >>> os.renames('temp/not-exists', 'temp/test2/test3/test4') Traceback (most recent