[meld] When comparing directories don't fail on large files (closes bgo#585339)



commit 2344837534e191e2e7abea0eddee15b34945fbb6
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jul 5 16:58:21 2009 +1000

    When comparing directories don't fail on large files (closes bgo#585339)
    
    In directory comparisons, Meld would choke on very large files due to
    trying to read the whole file in at once. If this happens, we now fall
    back to the filecmp module. This fixes the immediate bug, though filters
    will unfortunately not be applied in this case.

 meld/dirdiff.py |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index e078d8d..8843eae 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -14,6 +14,7 @@
 ### along with this program; if not, write to the Free Software
 ### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import filecmp
 import paths
 from ui import gnomeglade
 import gobject
@@ -78,7 +79,17 @@ def _files_same(lof, regexes):
         if cache.sigs == sigs: # up to date
             return cache.result
     # do it
-    contents = [ open(f, "r").read() for f in lof ]
+    try:
+        contents = [open(f, "r").read() for f in lof]
+    except (MemoryError, OverflowError): # Files are too large
+        # FIXME: Filters are not current applied in this case. If that was
+        # to be fixed, we could drop the all-at-once loading.
+        for i in range(len(lof) - 1):
+            same = filecmp.cmp(lof[i], lof[i + 1], False)
+            if not same:
+                return 0
+        return 1
+
     if all_same(contents):
         result = 1
     else:



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