[Patches] [ python-Patches-1314067 ] os.makedirs - robust against partial path

SourceForge.net noreply at sourceforge.net
Sat Dec 9 10:26:59 CET 2006


Patches item #1314067, was opened at 2005-10-05 17:08
Message generated for change (Comment added) made by gbrandl
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1314067&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.4
>Status: Closed
>Resolution: Rejected
Priority: 5
Private: No
Submitted By: Jim Jewett (jimjjewett)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.makedirs - robust against partial path

Initial Comment:
os.py function makedirs is intended to create a 
directory, including any required parent directories.

Unfortunately, at least on windows, it fails is some of 
those parent directories already exist.  This patch 
says "if the directory I'm about to create is already an 
existing directory, then pretend I succeeded and 
continue with the next step."

----------------------------------------------------------------------

>Comment By: Georg Brandl (gbrandl)
Date: 2006-12-09 09:26

Message:
Logged In: YES 
user_id=849994
Originator: NO

I agree with rbarran. Closing as Rejected.

----------------------------------------------------------------------

Comment By: Richard Barran (rbarran)
Date: 2005-12-05 12:39

Message:
Logged In: YES 
user_id=1207189

I think that the current behavior of the function is correct.
It tries to mimic os.mkdir - if the dir to create ("c" in
your example) already exists, it will raise an error.
However, errors on intermediate dirs are ignored.
This makes sense, but I think the documentation is not clear
on this (or maybe I'm just slow :-)
BTW - there's another patch ([ 1239890 ] Prevent race
condition in os.makedirs) to rewrite the whole function and
it might make your patch in its current form obsolete.
Maybe your work can be merged into this other patch?


----------------------------------------------------------------------

Comment By: Jim Jewett (jimjjewett)
Date: 2005-12-02 20:11

Message:
Logged In: YES 
user_id=764593

slight misdiagnosis on my part -- it only fails if the 
*entire* directory tree already exists.  
 
"""
>>> os.makedirs('c:/temp/a/b/c')

>>> os.makedirs('c:/temp/a/b/c')

Traceback (most recent call last):
  File "<pyshell#64>", line 1, in -toplevel-
    os.makedirs('c:/temp/a/b/c')
  File "C:\Python24\lib\orig_os.py", line 159, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: 'c:/temp/a/b/c'
"""

My use case was generating java files in the proper package 
- and possibly regenerating them if something changed.  I 
want to put them in the right directory, which will usually 
(but not always) already exist.

The patch still works, but I now wonder if it might be 
better to put a guard at the top along the lines of "if 
path.exists(name): return" (or something fancier to ensure 
that it is a directory with appropriate permissions).


----------------------------------------------------------------------

Comment By: Richard Barran (rbarran)
Date: 2005-12-01 16:39

Message:
Logged In: YES 
user_id=1207189

Hi,

Could you provide some example code that shows up the error?
If I understand you correctly, the following should fail:

import os
os.mkdir('c:/temp/a')
os.makedirs('c:/temp/a/b/c')

But it works fine on my WinXP pro SP2 machine.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1314067&group_id=5470


More information about the Patches mailing list