[meld] Show errors for invalid encodings in filenames (closes bgo#621423)



commit 6ff60cefe9a4c731e8cd272098e96c645988f3bd
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Jan 13 06:54:17 2011 +1000

    Show errors for invalid encodings in filenames (closes bgo#621423)

 meld/dirdiff.py |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index 23b98cf..2d54c78 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -460,6 +460,7 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
                 canonicalize = lambda x : x.lower()
             dirs = CanonicalListing(self.num_panes, canonicalize)
             files = CanonicalListing(self.num_panes, canonicalize)
+            invalid_filenames = False
 
             for pane, root in enumerate(roots):
                 if not os.path.isdir(root):
@@ -477,6 +478,12 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
 
                 for e in entries:
                     try:
+                        e = e.decode('utf8')
+                    except UnicodeDecodeError, err:
+                        invalid_filenames = True
+                        continue
+
+                    try:
                         s = os.lstat(os.path.join(root, e))
                     # Covers certain unreadable symlink cases; see bgo#585895
                     except OSError, err:
@@ -512,6 +519,9 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
                         # FIXME: Unhandled stat type
                         pass
 
+            if invalid_filenames:
+                misc.run_dialog(_("Filenames with invalid encodings were found; these have been ignored"), self)
+
             for pane, f1, f2 in dirs.errors + files.errors:
                 shadowed_entries.append((pane, roots[pane], f1, f2))
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]