classification
Title: importing from UNC roots doesn't work
Type: behavior Stage:
Components: Interpreter Core, Windows Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, ggenellina, kristjan.jonsson, loewis, ocean-city
Priority: normal Keywords: patch

Created on 2008-08-25 15:00 by kristjan.jonsson, last changed 2009-01-24 13:57 by ocean-city. This issue is now closed.

Files
File name Uploaded Description Edit
not_use_stat_in_import_on_windows.patch ocean-city, 2008-10-08 00:14 trunk
not_use_stat_in_import_on_windows.patch kristjan.jonsson, 2009-01-05 10:18 reviewed by Kristjan, fixes this issue and
Messages (19)
msg71932 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2008-08-25 15:00
When executing a script from a UNC path, e.g. //myhost/exports/a.py, 
r"\\myhost\exports" gets prepended to sys.path.  But it doesn't work.  
This means that in a.py, "import b" will fail even though b.py is 
present in the same directory.

The workaround is to manually prepend a backslass to the UNC path in 
sys.path.

Note the related defect: http://bugs.python.org/issue954115
This intdoruces two functions for testing UNC paths, but it appears 
that these functions are nowhere used!
msg71941 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2008-08-25 15:32
Correction: The workaround is to _append_ a backslash.
msg74478 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-10-07 20:15
Kristjan, you suggested this issue for consideration for 2.5.3.

Is there an actual patch to apply?

If not, the issue should get forwarded to 2.7 (and then to 2.8, and so
on, until somebody actually comes up with a patch).
msg74490 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2008-10-07 21:29
No, not really.
Again, I refer to defect 954115 by glchapman.  And note that those 
functions added there are actually not used.
I was hoping that there was someone here more familiar with importing 
on PC.
I'll go and see if the old defect still applies and if there is perhaps 
a more general fix to be made.
msg74491 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-10-07 21:46
Ok, un-targetting this from 2.5.3 then. 

Usage of IsUNCRoot disappeared as part of r42230, which dropped usage of
the C library for stat implementations. This only affects os.stat,
though, so I don't see the relation to this issue.

For the record: What *exactly* is the problem? I.e. specifically, what
do you do, what happens, what do you expect to happen instead?
msg74495 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-07 23:12
I think this is stat(2) problem on windows. Please try following test
program.

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

void test(const char *path)
{
    struct stat st;

    printf("%s %d %d\n", path, stat(path, &st), GetFileAttributes(path));
}

int main()
{
    test("e:\\shared");
    test("e:\\shared\\"); /* issue1293 */
    test("e:\\shared\\a.py");
    test("\\\\whiterab-c2znlh\\shared"); /* this issue */
    test("\\\\whiterab-c2znlh\\shared\\");
    test("\\\\whiterab-c2znlh\\shared\\a.py");
}

And this is result.

e:\shared 0 16
e:\shared\ -1 16
e:\shared\a.py 0 32
\\whiterab-c2znlh\shared -1 16
\\whiterab-c2znlh\shared\ 0 16
\\whiterab-c2znlh\shared\a.py 0 32

As discussed in issue1293, stat(2) fails for the normal folder path with
trailing slash, and also fails for the UNC folder path without trailing
slash. I'm using VC6, but same behavior on VC9?

trunk/Python/import.c(3160) and trunk/Modules/zipimport.c(99) is using
stat(2).

I'll create patch to prove my observation. :-)
msg74496 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-07 23:14
Ah, of cource, please change path to fit you environment. > test prog
msg74500 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-08 00:11
zipimport.c seems fine, because stat(2) succeeds for UNC file. It fails
for UNC folder. (zip file is absolutely file)

Already fix for issue1293 was in, so maybe I should create the patch for
that direction but... anyway this issue seems to be fixed by my patch. I
also confirmed the test script in http://bugs.python.org/msg56523 works.
msg74501 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2008-10-08 00:18
Just humble thought...
If we can replace stat(2) + S_ISDIR/S_ISREG check with
GetFileAttributesEx, maybe we are safe for this kind of problem, and can
solve issue3099 same time? :-)
msg79118 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2009-01-05 10:18
Okay, I've tested the patch and made some beauty fixes.
Can we have this in, please?
msg79500 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2009-01-09 20:11
Checked in as revision: 68457
msg80397 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-01-23 03:35
This fix needs to be ported to the py3k branch. Can somebody please do it?
msg80399 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-01-23 07:24
Merged in r68873(py3k).
msg80434 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-01-24 02:09
The path variable should be PyMem_Free'd (in both trunk and py3k)
(also, I don't see any specific test - is there any?)
msg80442 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2009-01-24 10:33
added the mem release in r68882.
I'll try to add test cases too.
msg80443 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2009-01-24 10:52
Added tests for UNC path imports in r68883 and r68884
msg80444 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-01-24 11:07
>The path variable should be PyMem_Free'd

Sorry if I'm missing something, but is this really needed?
Other PyArg_ParseTuple(args, "s... doesn't seem to have
corresponding PyMem_Free.

static PyObject *
imp_new_module(PyObject *self, PyObject *args)
{
	char *name;
	if (!PyArg_ParseTuple(args, "s:new_module", &name))
		return NULL;
	return PyModule_New(name);
}
msg80446 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-24 12:42
> Sorry if I'm missing something, but is this really needed?

Yes, the "es" converter allocates memory.
msg80448 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-01-24 13:57
Ah, "es" is used in py3k, thanks. And sorry about my merge which had 
memory leak.
History
Date User Action Args
2009-01-24 13:57:44ocean-citysetmessages: + msg80448
2009-01-24 12:42:27loewissetmessages: + msg80446
2009-01-24 11:07:41ocean-citysetmessages: + msg80444
2009-01-24 10:52:47kristjan.jonssonsetmessages: + msg80443
2009-01-24 10:33:49kristjan.jonssonsetmessages: + msg80442
2009-01-24 02:09:34ggenellinasetnosy: + ggenellina
messages: + msg80434
2009-01-23 07:24:01ocean-citysetmessages: + msg80399
2009-01-23 03:35:20benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg80397
2009-01-09 20:11:28kristjan.jonssonsetstatus: open -> closed
resolution: fixed
messages: + msg79500
2009-01-05 10:18:53kristjan.jonssonsetfiles: + not_use_stat_in_import_on_windows.patch
messages: + msg79118
2008-10-10 23:06:31ocean-citysetcomponents: + Windows
2008-10-08 00:18:37ocean-citysetmessages: + msg74501
2008-10-08 00:14:24ocean-citysetfiles: + not_use_stat_in_import_on_windows.patch
2008-10-08 00:14:09ocean-citysetfiles: - not_use_stat_in_import_on_windows.patch
2008-10-08 00:11:29ocean-citysetfiles: + not_use_stat_in_import_on_windows.patch
keywords: + patch
messages: + msg74500
2008-10-07 23:14:37ocean-citysetmessages: + msg74496
2008-10-07 23:12:17ocean-citysetnosy: + ocean-city
messages: + msg74495
2008-10-07 21:46:58loewissetmessages: + msg74491
versions: - Python 2.5.3
2008-10-07 21:29:42kristjan.jonssonsetmessages: + msg74490
2008-10-07 20:15:51loewissetnosy: + loewis
messages: + msg74478
versions: + Python 2.5.3
2008-08-25 15:32:31kristjan.jonssonsetmessages: + msg71941
2008-08-25 15:00:27kristjan.jonssoncreate