Kaydet (Commit) f2abc8f2 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Issue #27998: Fixed bytes path support in os.scandir() on Windows.

Patch by Eryk Sun.
...@@ -70,6 +70,9 @@ Core and Builtins ...@@ -70,6 +70,9 @@ Core and Builtins
Library Library
------- -------
- Issue #27998: Fixed bytes path support in os.scandir() on Windows.
Patch by Eryk Sun.
- Issue #28317: The disassembler now decodes FORMAT_VALUE argument. - Issue #28317: The disassembler now decodes FORMAT_VALUE argument.
- Issue #26293: Fixed writing ZIP files that starts not from the start of the - Issue #26293: Fixed writing ZIP files that starts not from the start of the
......
...@@ -1337,29 +1337,39 @@ win32_error_object(const char* function, PyObject* filename) ...@@ -1337,29 +1337,39 @@ win32_error_object(const char* function, PyObject* filename)
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
static PyObject * static PyObject *
path_error(path_t *path) path_object_error(PyObject *path)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, return PyErr_SetExcFromWindowsErrWithFilenameObject(
0, path->object); PyExc_OSError, 0, path);
#else #else
return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object); return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path);
#endif #endif
} }
static PyObject * static PyObject *
path_error2(path_t *path, path_t *path2) path_object_error2(PyObject *path, PyObject *path2)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
return PyErr_SetExcFromWindowsErrWithFilenameObjects(PyExc_OSError, return PyErr_SetExcFromWindowsErrWithFilenameObjects(
0, path->object, path2->object); PyExc_OSError, 0, path, path2);
#else #else
return PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, return PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, path, path2);
path->object, path2->object);
#endif #endif
} }
static PyObject *
path_error(path_t *path)
{
return path_object_error(path->object);
}
static PyObject *
path_error2(path_t *path, path_t *path2)
{
return path_object_error2(path->object, path2->object);
}
/* POSIX generic methods */ /* POSIX generic methods */
...@@ -11152,41 +11162,26 @@ static PyObject * ...@@ -11152,41 +11162,26 @@ static PyObject *
DirEntry_fetch_stat(DirEntry *self, int follow_symlinks) DirEntry_fetch_stat(DirEntry *self, int follow_symlinks)
{ {
int result; int result;
struct _Py_stat_struct st; STRUCT_STAT st;
PyObject *ub;
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
const wchar_t *path; if (PyUnicode_FSDecoder(self->path, &ub)) {
const wchar_t *path = PyUnicode_AsUnicode(ub);
path = PyUnicode_AsUnicode(self->path);
if (!path)
return NULL;
if (follow_symlinks)
result = win32_stat(path, &st);
else
result = win32_lstat(path, &st);
if (result != 0) {
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError,
0, self->path);
}
#else /* POSIX */ #else /* POSIX */
PyObject *bytes; if (PyUnicode_FSConverter(self->path, &ub)) {
const char *path; const char *path = PyBytes_AS_STRING(ub);
#endif
if (!PyUnicode_FSConverter(self->path, &bytes)) if (follow_symlinks)
result = STAT(path, &st);
else
result = LSTAT(path, &st);
Py_DECREF(ub);
} else
return NULL; return NULL;
path = PyBytes_AS_STRING(bytes);
if (follow_symlinks)
result = STAT(path, &st);
else
result = LSTAT(path, &st);
Py_DECREF(bytes);
if (result != 0) if (result != 0)
return PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, self->path); return path_object_error(self->path);
#endif
return _pystat_fromstructstat(&st); return _pystat_fromstructstat(&st);
} }
...@@ -11356,17 +11351,19 @@ DirEntry_inode(DirEntry *self) ...@@ -11356,17 +11351,19 @@ DirEntry_inode(DirEntry *self)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
if (!self->got_file_index) { if (!self->got_file_index) {
PyObject *unicode;
const wchar_t *path; const wchar_t *path;
struct _Py_stat_struct stat; STRUCT_STAT stat;
int result;
path = PyUnicode_AsUnicode(self->path); if (!PyUnicode_FSDecoder(self->path, &unicode))
if (!path)
return NULL; return NULL;
path = PyUnicode_AsUnicode(unicode);
result = LSTAT(path, &stat);
Py_DECREF(unicode);
if (win32_lstat(path, &stat) != 0) { if (result != 0)
return PyErr_SetExcFromWindowsErrWithFilenameObject(PyExc_OSError, return path_object_error(self->path);
0, self->path);
}
self->win32_file_index = stat.st_ino; self->win32_file_index = stat.st_ino;
self->got_file_index = 1; self->got_file_index = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment