Show More
@@ -223,6 +223,9 b' static PyObject *listdir(PyObject *self,' | |||||
223 | char *name = PyString_AsString(PyTuple_GET_ITEM(elt, 0)); |
|
223 | char *name = PyString_AsString(PyTuple_GET_ITEM(elt, 0)); | |
224 | PyObject *py_st = NULL; |
|
224 | PyObject *py_st = NULL; | |
225 | PyObject *py_kind = PyTuple_GET_ITEM(elt, 1); |
|
225 | PyObject *py_kind = PyTuple_GET_ITEM(elt, 1); | |
|
226 | struct listdir_stat *st; | |||
|
227 | struct stat buf; | |||
|
228 | struct stat *stp = &buf; | |||
226 | int kind; |
|
229 | int kind; | |
227 |
|
230 | |||
228 | kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind); |
|
231 | kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind); | |
@@ -234,48 +237,33 b' static PyObject *listdir(PyObject *self,' | |||||
234 | full_path[PATH_MAX] = 0; |
|
237 | full_path[PATH_MAX] = 0; | |
235 |
|
238 | |||
236 | if (do_stat) { |
|
239 | if (do_stat) { | |
237 | struct listdir_stat *st; |
|
|||
238 |
|
||||
239 | if (!ctor_args) { |
|
240 | if (!ctor_args) { | |
240 | ctor_args = PyTuple_New(0); |
|
241 | ctor_args = PyTuple_New(0); | |
241 | if (!ctor_args) |
|
242 | if (!ctor_args) | |
242 | goto bail; |
|
243 | goto bail; | |
243 | } |
|
244 | } | |
244 |
|
245 | |||
245 | st = (struct listdir_stat *) |
|
246 | py_st = PyObject_CallObject((PyObject *)&listdir_stat_type, | |
246 | PyObject_CallObject((PyObject *)&listdir_stat_type, |
|
|||
247 | ctor_args); |
|
247 | ctor_args); | |
248 |
|
248 | st = (struct listdir_stat *)py_st; | ||
249 | if (!st) |
|
249 | if (!st) | |
250 | goto bail; |
|
250 | goto bail; | |
|
251 | stp = &st->st; | |||
|
252 | PyTuple_SET_ITEM(elt, 2, py_st); | |||
|
253 | } | |||
|
254 | ||||
251 | #ifdef AT_SYMLINK_NOFOLLOW |
|
255 | #ifdef AT_SYMLINK_NOFOLLOW | |
252 |
|
|
256 | ret = fstatat(dfd, name, stp, AT_SYMLINK_NOFOLLOW); | |
253 | #else |
|
257 | #else | |
254 |
|
|
258 | ret = lstat(full_path, stp); | |
255 | #endif |
|
259 | #endif | |
256 |
|
|
260 | if (ret == -1) { | |
257 |
|
|
261 | list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, | |
258 |
|
|
262 | full_path); | |
259 |
|
|
263 | goto bail; | |
260 | } |
|
|||
261 | if (kind == -1) |
|
|||
262 | kind = mode_to_kind(st->st.st_mode); |
|
|||
263 | py_st = (PyObject *)st; |
|
|||
264 | } else { |
|
|||
265 | struct stat buf; |
|
|||
266 | #ifdef AT_SYMLINK_NOFOLLOW |
|
|||
267 | ret = fstatat(dfd, ent->d_name, &buf, AT_SYMLINK_NOFOLLOW); |
|
|||
268 | #else |
|
|||
269 | ret = lstat(full_path, &buf); |
|
|||
270 | #endif |
|
|||
271 | if (ret == -1) { |
|
|||
272 | list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, |
|
|||
273 | full_path); |
|
|||
274 | goto bail; |
|
|||
275 | } |
|
|||
276 | if (kind == -1) |
|
|||
277 | kind = mode_to_kind(buf.st_mode); |
|
|||
278 | } |
|
264 | } | |
|
265 | if (kind == -1) | |||
|
266 | kind = mode_to_kind(stp->st_mode); | |||
279 |
|
267 | |||
280 | if (py_kind == Py_None && kind != -1) { |
|
268 | if (py_kind == Py_None && kind != -1) { | |
281 | py_kind = PyInt_FromLong(kind); |
|
269 | py_kind = PyInt_FromLong(kind); | |
@@ -284,14 +272,6 b' static PyObject *listdir(PyObject *self,' | |||||
284 | Py_XDECREF(Py_None); |
|
272 | Py_XDECREF(Py_None); | |
285 | PyTuple_SET_ITEM(elt, 1, py_kind); |
|
273 | PyTuple_SET_ITEM(elt, 1, py_kind); | |
286 | } |
|
274 | } | |
287 |
|
||||
288 | if (do_stat) { |
|
|||
289 | if (!py_st) { |
|
|||
290 | py_st = Py_None; |
|
|||
291 | Py_INCREF(Py_None); |
|
|||
292 | } |
|
|||
293 | PyTuple_SET_ITEM(elt, 2, py_st); |
|
|||
294 | } |
|
|||
295 | } |
|
275 | } | |
296 |
|
276 | |||
297 | goto done; |
|
277 | goto done; |
General Comments 0
You need to be logged in to leave comments.
Login now