Implement #7566 - os.path.sameopenfile for Windows.

This uses the GetFileInformationByHandle function to return a tuple of values
to identify a file, then ntpath.sameopenfile compares file tuples, which
is exposed as os.path.sameopenfile.
This commit is contained in:
Brian Curtin 2010-09-06 17:07:27 +00:00
parent 5c997b8d90
commit 6285774f06
5 changed files with 52 additions and 2 deletions

View file

@ -2758,6 +2758,33 @@ posix__getfinalpathname(PyObject *self, PyObject *args)
return result;
} /* end of posix__getfinalpathname */
static PyObject *
posix__getfileinformation(PyObject *self, PyObject *args)
{
HANDLE hFile;
BY_HANDLE_FILE_INFORMATION info;
int fd;
if (!PyArg_ParseTuple(args, "i:_getfileinformation", &fd))
return NULL;
if (!_PyVerify_fd(fd)) {
PyErr_SetString(PyExc_ValueError, "received invalid file descriptor");
return NULL;
}
hFile = (HANDLE)_get_osfhandle(fd);
if (hFile == INVALID_HANDLE_VALUE)
return win32_error("_getfileinformation", NULL);
if (!GetFileInformationByHandle(hFile, &info))
return win32_error("_getfileinformation", NULL);
return Py_BuildValue("iii", info.dwVolumeSerialNumber,
info.nFileIndexHigh,
info.nFileIndexLow);
}
#endif /* MS_WINDOWS */
PyDoc_STRVAR(posix_mkdir__doc__,
@ -7908,6 +7935,7 @@ static PyMethodDef posix_methods[] = {
#ifdef MS_WINDOWS
{"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
{"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL},
{"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL},
#endif
#ifdef HAVE_GETLOADAVG
{"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},