[Python-bugs-list] [ python-Bugs-829532 ] os.makedirs() cannot handle "."

SourceForge.net noreply at sourceforge.net
Fri Oct 31 17:10:31 EST 2003


Bugs item #829532, was opened at 2003-10-24 13:44
Message generated for change (Comment added) made by vimboss
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=829532&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Bram Moolenaar (vimboss)
Assigned to: A.M. Kuchling (akuchling)
Summary: os.makedirs() cannot handle "."

Initial Comment:
Invoking os.makedirs() with an argument that contains a
directory name with a single dot fails.  The resulting
error is confusing: "File exists".

The problem is that the path is split up in pieces and
an attempt is made to create the "." directory.  This
always exists, of course.  It happens anyway, because
the test for existence is done before creating the
directory that contains ".".

There are various possible solutions:
1. First normalize the path so that "." entries are
removed.  This would also work for ".." entries.  But
it might cause trouble for symbolic links and there is
a performance penalty.
2. Check for existence of the directory again after the
recursive call to create the directory that contains
the entry.  This will cause the normal error for an
existing directory to be skipped, unless an extra flag
is added.  This gets complicated.
3. Simply skip creating a directory with the name ".".

I propose to use the third solution.  I have attached a
patch for this.

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

>Comment By: Bram Moolenaar (vimboss)
Date: 2003-10-31 23:10

Message:
Logged In: YES 
user_id=57665

The patch suggested by akuchling doesn't work for "dir/./.".
And the remark is false anyway, the patch I suggested does
generate an exception for makedirs(".").



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

Comment By: A.M. Kuchling (akuchling)
Date: 2003-10-31 20:41

Message:
Logged In: YES 
user_id=11375

Note that the documentation for os.makedirs() says it raises an exception if the 
directory already exists, so os.makedirs('.') has to continue to be an error, 
though os.makedirs('/foo/bar/.') should be made to work properly.

The attached patch implements this.

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

Comment By: Christos Georgiou (tzot)
Date: 2003-10-28 01:54

Message:
Logged In: YES 
user_id=539787

Minor correction (in ex cmdline style :):

:%s/"\."/curdir/g

 in the 'diff' patch (making it more OS independent).

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

Comment By: A.M. Kuchling (akuchling)
Date: 2003-10-24 19:46

Message:
Logged In: YES 
user_id=11375

There's no uploaded file!  You have to check the
checkbox labeled "Check to Upload & Attach File"
when you upload a file.

Please try again.

(This is a SourceForge annoyance that we can do
nothing about. :-( )

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

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



More information about the Python-bugs-list mailing list