156
145
(mode, ino, dev, nlink, uid, gid, size, None(atime), mtime, ctime)
158
147
return repr((self.st_mode, 0, 0, 0, 0, 0, self.st_size, None,
159
self.st_mtime, self.st_ctime))
148
self._mtime, self._ctime))
162
151
from bzrlib import osutils
295
278
cdef int stat_result
296
279
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)
282
cwd = getcwd(NULL, 0)
283
if -1 == chdir(path):
284
raise OSError(errno, strerror(errno))
285
the_dir = opendir(".")
287
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)
292
entry = readdir(the_dir)
297
elif errno != ENOTDIR and errno != ENOENT and errno != 0:
298
# We see ENOTDIR at the end of a normal directory.
299
# As ENOTDIR for read_dir(file) is triggered on opendir,
300
# we consider ENOTDIR to be 'no error'.
301
# ENOENT is listed as 'invalid position in the dir stream' for
302
# readdir. We swallow this for now and just keep reading.
303
raise OSError(errno, strerror(errno))
308
if not (name[0] == c"." and (
310
(name[1] == c"." and name[2] == 0))
313
stat_result = lstat(entry.d_name, &statvalue._st)
316
raise OSError(errno, strerror(errno))
320
# We append a 5-tuple that can be modified in-place by the C
322
# inode to sort on (to replace with top_path)
324
# kind (None, to set)
325
# statvalue (to keep)
326
# abspath (None, to set)
327
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: ", "")
332
raise OSError(errno, strerror(errno))
334
if -1 == closedir(the_dir):
335
raise OSError(errno, strerror(errno))