Issue1110

classification
Title: stat fails on directory path with trailing backslash on Windows
Type: behaviour Severity: normal
Components: Library Versions: 2.5alpha3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: thobes Nosy List: acdha, amak, bupjae, jy123, nriley, thobes
Priority: high Keywords: patch

Created on 2008-08-22.16:52:23 by jy123, last changed 2009-04-05.17:41:16 by thobes.

Files
File name Uploaded Description Edit Remove
ntpathbug.py jy123, 2008-08-22.16:52:22 testfile contained error message
install_egg_info_py.patch amak, 2009-01-10.17:42:11 A patch to distutils\command\install_egg_info.py which solves the problem on my windows machine,.
Messages
msg3446 (view) Author: (jy123) Date: 2008-08-22.16:52:22
when I try to install lastest version django on lastest jython version, 
get "couldn't make directories". It seems ntpath.isdir failed.
msg3460 (view) Author: Nicholas Riley (nriley) Date: 2008-08-29.20:57:29
This is a bug/"feature" in the MSVCRT stat function, which Jython uses through jna-
posix.

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(void) {
  struct stat foo;
  int retval = stat("c:\\Documents and Settings\\", &foo);
  fprintf(stderr, "stat returned %d\n", retval);
  perror("stat");
}

% ./stat
stat returned -1
stat: No such file or directory

If you remove the trailing \, it works fine.
msg3694 (view) Author: Bupjae Lee (bupjae) Date: 2008-10-20.00:11:02
I think this problem still exists in 2.5alpha3
msg3696 (view) Author: Bupjae Lee (bupjae) Date: 2008-10-20.00:27:41
Here is my workarounds

in lib\os.py:

def makedirs(path, mode='ignored'):
    """makedirs(path [, mode=0777])

    Super-mkdir; create a leaf directory and all intermediate ones.

    Works like mkdir, except that any intermediate path segment (not
    just the rightmost) will be created if it does not exist.
    The optional parameter is currently ignored.
    """
    sys_path = sys.getPath(path)
    if File(sys_path).mkdirs():
        return
    if(sys_path[-1]=='\\'):
        if File(sys_path[:-2]).mkdirs():
            return

    # if making a /x/y/z/., java.io.File#mkdirs inexplicably fails. So 
we need
    # to force it
    
    # need to use _path instead of path, because param is hiding
    # os.path module in namespace!
    head, tail = _path.split(sys_path)
    if tail == curdir:
        if File(_path.join(head)).mkdirs():
            return
        if(_path.join(head)[-1]=='\\'):
            if File(_path.join(head)[:-2]).mkdirs():
                return
                
    raise OSError(0, "couldn't make directories", path)
msg4022 (view) Author: Alan Kennedy (amak) Date: 2009-01-10.17:42:10
This issue still exists in 2.5b1; I am experiencing the issue when
trying to install Django on jython.

I am attaching a patch to install_egg_info.py which solves the problem
on my Windows machine.
msg4447 (view) Author: Tobias Ivarsson (thobes) Date: 2009-04-05.17:41:15
Fix implemented in revision 6164.
History
Date User Action Args
2009-04-05 17:41:16thobessetstatus: open -> closed
assignee: thobes
messages: + msg4447
nosy: + thobes
2009-03-14 14:29:01fwierzbickisetpriority: high
2009-02-17 15:59:54acdhasetnosy: + acdha
2009-01-28 13:41:52leosotolinkissue1233 superseder
2009-01-10 17:42:11amaksetfiles: + install_egg_info_py.patch
keywords: + patch
messages: + msg4022
nosy: + amak
2008-10-20 00:27:41bupjaesetmessages: + msg3696
2008-10-20 00:11:03bupjaesetnosy: + bupjae
messages: + msg3694
versions: + 2.5alpha3, - 2.5alpha1
2008-08-29 20:57:30nrileysettype: behaviour
messages: + msg3460
nosy: + nriley
title: ntpath.isdir failed in vista -> stat fails on directory path with trailing backslash on Windows
2008-08-22 16:52:23jy123create