Fix #11939. Set st_dev attribute on Windows to simplify os.path.samefile.

By setting the st_dev attribute, we can then remove some Windows-specific
code and move os.path.samefile/sameopenfile/samestat to Lib/genericpath.py
so all platforms share the same implementation.
This commit is contained in:
Brian Curtin 2012-12-26 07:03:03 -06:00
parent 2bf61abe02
commit 490b32a397
7 changed files with 104 additions and 139 deletions

View file

@ -1249,6 +1249,8 @@ attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag, stru
memset(result, 0, sizeof(*result));
result->st_mode = attributes_to_mode(info->dwFileAttributes);
result->st_size = (((__int64)info->nFileSizeHigh)<<32) + info->nFileSizeLow;
result->st_dev = info->dwVolumeSerialNumber;
result->st_rdev = result->st_dev;
FILE_TIME_to_time_t_nsec(&info->ftCreationTime, &result->st_ctime, &result->st_ctime_nsec);
FILE_TIME_to_time_t_nsec(&info->ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec);
FILE_TIME_to_time_t_nsec(&info->ftLastAccessTime, &result->st_atime, &result->st_atime_nsec);
@ -3503,31 +3505,6 @@ posix__getfinalpathname(PyObject *self, PyObject *args)
} /* 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))
return posix_error();
hFile = (HANDLE)_get_osfhandle(fd);
if (hFile == INVALID_HANDLE_VALUE)
return posix_error();
if (!GetFileInformationByHandle(hFile, &info))
return PyErr_SetFromWindowsErr(0);
return Py_BuildValue("iii", info.dwVolumeSerialNumber,
info.nFileIndexHigh,
info.nFileIndexLow);
}
PyDoc_STRVAR(posix__isdir__doc__,
"Return true if the pathname refers to an existing directory.");
@ -10606,7 +10583,6 @@ 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},
{"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__},
{"_getdiskusage", win32__getdiskusage, METH_VARARGS, win32__getdiskusage__doc__},
#endif