[meld] Exit early from non-directory and error cases in directory iteration
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Exit early from non-directory and error cases in directory iteration
- Date: Sat, 5 Feb 2011 22:54:59 +0000 (UTC)
commit c9c9d7a3ada7a70e9d702ff7a6ce1ec0091c6054
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Dec 18 15:03:31 2010 +1000
Exit early from non-directory and error cases in directory iteration
meld/dirdiff.py | 77 ++++++++++++++++++++++++++++++------------------------
1 files changed, 43 insertions(+), 34 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 396181f..b72469e 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -464,47 +464,56 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
if s: return s
return tuple([t or first_nonempty(tuples) for t in tuples])
return [fixup(self.items[k]) for k in keys]
+
accumdirs = accum(self, roots)
accumfiles = accum(self, roots)
for pane, root in enumerate(roots):
- if os.path.isdir( root ):
- try:
- entries = os.listdir( root )
+ if not os.path.isdir(root):
+ continue
+
+ try:
+ entries = os.listdir(root)
+ except OSError, err:
+ self.model.add_error(it, err.strerror, pane)
+ differences = True
+ continue
+
+ for f in self.name_filters:
+ entries = filter(f.filter, entries)
+
+ files = []
+ dirs = []
+ for e in entries:
+ try: # Necessary for some broken symlink cases; see bgo#585895
+ s = os.lstat(os.path.join(root, e))
except OSError, err:
- self.model.add_error( it, err.strerror, pane )
- differences = True
- else:
- for f in self.name_filters:
- entries = filter(f.filter, entries)
- files = []
- dirs = []
- for e in entries:
- try: # Necessary for some broken symlink cases; see bgo#585895
- s = os.lstat(os.path.join(root, e))
- except OSError, err:
- print "Ignoring OS error: %s" % err
- continue
- if stat.S_ISLNK(s.st_mode):
- if self.prefs.ignore_symlinks:
- continue
- key = (s.st_dev, s.st_ino)
- if key in symlinks_followed:
- continue
- symlinks_followed.add(key)
- try:
- s = os.stat(os.path.join(root, e))
- if stat.S_ISREG(s.st_mode):
- files.append(e)
- elif stat.S_ISDIR(s.st_mode):
- dirs.append(e)
- except OSError, err:
- print "ignoring dangling symlink", e
- elif stat.S_ISREG(s.st_mode):
+ print "Ignoring OS error: %s" % err
+ continue
+
+ if stat.S_ISLNK(s.st_mode):
+ if self.prefs.ignore_symlinks:
+ continue
+ key = (s.st_dev, s.st_ino)
+ if key in symlinks_followed:
+ continue
+ symlinks_followed.add(key)
+ try:
+ s = os.stat(os.path.join(root, e))
+ if stat.S_ISREG(s.st_mode):
files.append(e)
elif stat.S_ISDIR(s.st_mode):
dirs.append(e)
- accumfiles.add( pane, files )
- accumdirs.add( pane, dirs )
+ except OSError, err:
+ print "ignoring dangling symlink", e
+ elif stat.S_ISREG(s.st_mode):
+ files.append(e)
+ elif stat.S_ISDIR(s.st_mode):
+ dirs.append(e)
+ else:
+ # FIXME: Unhandled stat type
+ pass
+ accumfiles.add(pane, files)
+ accumdirs.add(pane, dirs)
alldirs = accumdirs.get()
allfiles = self._filter_on_state( roots, accumfiles.get() )
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]