156
141
(mode, ino, dev, nlink, uid, gid, size, None(atime), mtime, ctime)
158
143
return repr((self.st_mode, 0, 0, 0, 0, 0, self.st_size, None,
159
self.st_mtime, self.st_ctime))
144
self._mtime, self._ctime))
162
147
from bzrlib import osutils
295
274
cdef int stat_result
296
275
cdef _Stat statvalue
300
# Avoid chdir('') because it causes problems on Sun OS, and avoid this if
302
if path != "" and path != '.':
303
# we change into the requested directory before reading, and back at the
304
# end, because that turns out to make the stat calls measurably faster than
305
# passing full paths every time.
306
orig_dir_fd = open(".", O_RDONLY, 0)
307
if orig_dir_fd == -1:
308
raise_os_error(errno, "open: ", ".")
309
if -1 == chdir(path):
310
raise_os_error(errno, "chdir: ", path)
278
cwd = getcwd(NULL, 0)
279
if -1 == chdir(path):
280
raise OSError(errno, strerror(errno))
281
the_dir = opendir(".")
283
raise OSError(errno, strerror(errno))
315
the_dir = opendir(".")
317
raise_os_error(errno, "opendir: ", path)
322
# Unlike most libc functions, readdir needs errno set to 0
323
# beforehand so that eof can be distinguished from errors. See
324
# <https://bugs.launchpad.net/bzr/+bug/279381>
327
entry = readdir(the_dir)
328
if entry == NULL and (errno == EAGAIN or errno == EINTR):
336
if errno == ENOTDIR or errno == 0:
337
# We see ENOTDIR at the end of a normal directory.
338
# As ENOTDIR for read_dir(file) is triggered on opendir,
339
# we consider ENOTDIR to be 'no error'.
342
raise_os_error(errno, "readdir: ", path)
344
if not (name[0] == c"." and (
346
(name[1] == c"." and name[2] == 0))
349
stat_result = lstat(entry.d_name, &statvalue._st)
352
raise_os_error(errno, "lstat: ",
353
path + "/" + entry.d_name)
355
# the file seems to have disappeared after being
356
# seen by readdir - perhaps a transient temporary
357
# file. there's no point returning it.
359
# We append a 5-tuple that can be modified in-place by the C
361
# inode to sort on (to replace with top_path)
363
# kind (None, to set)
364
# statvalue (to keep)
365
# abspath (None, to set)
366
PyList_Append(result, (entry.d_ino, entry.d_name, None,
369
if -1 == closedir(the_dir):
370
raise_os_error(errno, "closedir: ", path)
288
entry = readdir(the_dir)
293
elif errno != ENOTDIR and errno != ENOENT and errno != 0:
294
# We see ENOTDIR at the end of a normal directory.
295
# As ENOTDIR for read_dir(file) is triggered on opendir,
296
# we consider ENOTDIR to be 'no error'.
297
# ENOENT is listed as 'invalid position in the dir stream' for
298
# readdir. We swallow this for now and just keep reading.
299
raise OSError(errno, strerror(errno))
304
if not (name[0] == c"." and (
306
(name[1] == c"." and name[2] == 0))
309
stat_result = lstat(entry.d_name, &statvalue._st)
312
raise OSError(errno, strerror(errno))
316
# We append a 5-tuple that can be modified in-place by the C
318
# inode to sort on (to replace with top_path)
320
# kind (None, to set)
321
# statvalue (to keep)
322
# abspath (None, to set)
323
PyList_Append(result, (entry.d_ino, entry.d_name, None,
372
if -1 != orig_dir_fd:
374
if -1 == fchdir(orig_dir_fd):
375
# try to close the original directory anyhow
377
if -1 == close(orig_dir_fd) or failed:
378
raise_os_error(errno, "return to orig_dir: ", "")
328
raise OSError(errno, strerror(errno))
330
if -1 == closedir(the_dir):
331
raise OSError(errno, strerror(errno))