[PATCH 1 of 2] osutil.c extension for Win32
Petr Kodl
petrkodl at gmail.com
Fri Sep 5 06:24:55 CDT 2008
ad #1 - the file execute flag - this is basically mimicking the standard
Python implementation - if we do not use the st_mode anywhere we can
drop those flags completely. At this point the osutil.listdir stat
matches os.listdir stat fields but technically it is not a requirement
ad #2 - OS detection in setup.py - point taken - you are right - I will
adjust it and resubmit the patch
pk
Patrick Mézard wrote:
> Petr Kodl a écrit :
>
>> # HG changeset patch
>> # User Petr Kodl<petrkodl at gmail.com>
>> # Date 1220485949 14400
>> # Node ID e150128b40c0f80871799c2d8de3684d767729f2
>> # Parent 6c4a08270222569ba906f4f1c7860783eec19225
>> osutil.c extension for Win32
>>
>
> [...]
>
>
>> + if(!isdir || (strcmp(fd.cFileName,".") && strcmp(fd.cFileName,"..") ))
>> + {
>> + PyObject* item = PyTuple_New(keep_stat ? 3 : 2);
>> + if(!item)
>> + {
>> + PyErr_NoMemory();
>> + goto end;
>> + }
>> + PyTuple_SetItem(item,0,PyString_FromString(fd.cFileName));
>> + PyTuple_SetItem(item,1,PyInt_FromLong(isdir ? _S_IFDIR : _S_IFREG));
>> + if(keep_stat)
>> + {
>> + py_st = PyObject_CallObject((PyObject *)&listdir_stat_type,ctor_args);
>> + if(!py_st)
>> + {
>> + PyErr_NoMemory();
>> + goto end;
>> + }
>> + stp = &((struct listdir_stat *)py_st)->st;
>> + stp->st_mtime = to_python_time(&fd.ftLastWriteTime);
>> + stp->st_ctime = to_python_time(&fd.ftCreationTime);
>> + stp->st_dev = 0;
>> + stp->st_size = 0;
>> + stp->st_mode = (isdir ? (S_IFDIR | 0111) : S_IFREG) | (isro ? 0444 : 0666);
>> + if(!isdir)
>> + {
>> + char* dot = strrchr(fd.cFileName,'.');
>> + if (dot)
>> + {
>> + if( !stricmp(dot,".bat")
>> + || !stricmp(dot,".cmd")
>> + || !stricmp(dot,".exe")
>> + || !stricmp(dot,".com"))
>> + stp->st_mode |= 0111;
>>
>
> File execute-bit are not currently handled under Windows, is there any reason we want to fake them here ?
>
> [...]
>
>
>> diff -r 6c4a08270222 -r e150128b40c0 setup.py
>> --- a/setup.py Wed Sep 03 19:03:57 2008 +0200
>> +++ b/setup.py Wed Sep 03 19:52:29 2008 -0400
>> @@ -101,9 +101,10 @@
>> packages = ['mercurial', 'mercurial.hgweb', 'hgext', 'hgext.convert',
>> 'hgext.highlight']
>>
>> +ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
>> +
>> try:
>> import posix
>> - ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
>>
>> if sys.platform == 'linux2' and os.uname()[2] > '2.6':
>> # The inotify extension is only usable with Linux 2.6 kernels.
>>
>
> I don't really agree with [all platforms] == [posix + win32]. I'd rather keep something similar to your previous try/except with mscvrt or test the os.name.
>
> --
> Patrick Mézard
>
>
More information about the Mercurial-devel
mailing list