##// END OF EJS Templates
osutil: more cleanups...
Matt Mackall -
r5423:e5f238a8 default
parent child Browse files
Show More
@@ -215,94 +215,94 b' static PyObject *listdir(PyObject *self,'
215 dfd = dirfd(dir);
215 dfd = dirfd(dir);
216 #endif
216 #endif
217
217
218 if (do_stat || !all_kinds) {
218 if (!(do_stat || !all_kinds))
219 for (i = 0; i < size; i++) {
219 goto done;
220 PyObject *elt = PyList_GetItem(list, i);
221 char *name = PyString_AsString(PyTuple_GET_ITEM(elt, 0));
222 PyObject *py_st = NULL;
223 PyObject *py_kind = PyTuple_GET_ITEM(elt, 1);
224 int kind;
225
226 kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind);
227
228 if (kind != -1 && !do_stat)
229 continue;
230
220
231 strncat(full_path + path_len + 1, name,
221 for (i = 0; i < size; i++) {
232 PATH_MAX - path_len);
222 PyObject *elt = PyList_GetItem(list, i);
233 full_path[PATH_MAX] = 0;
223 char *name = PyString_AsString(PyTuple_GET_ITEM(elt, 0));
234
224 PyObject *py_st = NULL;
235 if (do_stat) {
225 PyObject *py_kind = PyTuple_GET_ITEM(elt, 1);
236 struct listdir_stat *st;
226 int kind;
237
227
238 if (!ctor_args) {
228 kind = py_kind == Py_None ? -1 : PyInt_AsLong(py_kind);
239 ctor_args = PyTuple_New(0);
240 if (!ctor_args)
241 goto bail;
242 }
243
244 st = (struct listdir_stat *)
245 PyObject_CallObject((PyObject *)&listdir_stat_type,
246 ctor_args);
247
229
248 if (!st)
230 if (kind != -1 && !do_stat)
249 goto bail;
231 continue;
250 #ifdef AT_SYMLINK_NOFOLLOW
232
251 ret = fstatat(dfd, name, &st->st, AT_SYMLINK_NOFOLLOW);
233 strncat(full_path + path_len + 1, name, PATH_MAX - path_len);
252 #else
234 full_path[PATH_MAX] = 0;
253 ret = lstat(full_path, &st->st);
235
254 #endif
236 if (do_stat) {
255 if (ret == -1) {
237 struct listdir_stat *st;
256 list = PyErr_SetFromErrnoWithFilename(PyExc_OSError,
238
257 full_path);
239 if (!ctor_args) {
240 ctor_args = PyTuple_New(0);
241 if (!ctor_args)
258 goto bail;
242 goto bail;
259 }
260 if (kind == -1)
261 kind = mode_to_kind(st->st.st_mode);
262 py_st = (PyObject *)st;
263 } else {
264 struct stat buf;
265 #ifdef AT_SYMLINK_NOFOLLOW
266 ret = fstatat(dfd, ent->d_name, &buf, AT_SYMLINK_NOFOLLOW);
267 #else
268 ret = lstat(full_path, &buf);
269 #endif
270 if (ret == -1) {
271 list = PyErr_SetFromErrnoWithFilename(PyExc_OSError,
272 full_path);
273 goto bail;
274 }
275 if (kind == -1)
276 kind = mode_to_kind(buf.st_mode);
277 }
243 }
278
244
279 if (py_kind == Py_None && kind != -1) {
245 st = (struct listdir_stat *)
280 py_kind = PyInt_FromLong(kind);
246 PyObject_CallObject((PyObject *)&listdir_stat_type,
281 if (!py_kind)
247 ctor_args);
282 goto bail;
283 Py_XDECREF(Py_None);
284 PyTuple_SET_ITEM(elt, 1, py_kind);
285 }
286
248
287 if (do_stat) {
249 if (!st)
288 if (!py_st) {
250 goto bail;
289 py_st = Py_None;
251 #ifdef AT_SYMLINK_NOFOLLOW
290 Py_INCREF(Py_None);
252 ret = fstatat(dfd, name, &st->st, AT_SYMLINK_NOFOLLOW);
291 }
253 #else
292 PyTuple_SET_ITEM(elt, 2, py_st);
254 ret = lstat(full_path, &st->st);
255 #endif
256 if (ret == -1) {
257 list = PyErr_SetFromErrnoWithFilename(PyExc_OSError,
258 full_path);
259 goto bail;
293 }
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 }
279
280 if (py_kind == Py_None && kind != -1) {
281 py_kind = PyInt_FromLong(kind);
282 if (!py_kind)
283 goto bail;
284 Py_XDECREF(Py_None);
285 PyTuple_SET_ITEM(elt, 1, py_kind);
286 }
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 }
294 }
295 }
295 }
296
296
297 goto done;
297 goto done;
298
298
299 bail:
299 bail:
300 Py_XDECREF(list);
300 Py_XDECREF(list);
301
301
302 done:
302 done:
303 Py_XDECREF(ctor_args);
303 Py_XDECREF(ctor_args);
304 if (dir)
304 if (dir)
305 closedir(dir);
305 closedir(dir);
306 return list;
306 return list;
307 }
307 }
308
308
General Comments 0
You need to be logged in to leave comments. Login now