$OpenBSD: patch-launcher_fs_uae_launcher_ChecksumTool_py,v 1.1 2013/09/10 10:23:36 edd Exp $

Make checksumtool size aware.

--- launcher/fs_uae_launcher/ChecksumTool.py.orig	Wed Sep  4 10:09:47 2013
+++ launcher/fs_uae_launcher/ChecksumTool.py	Wed Sep  4 10:09:50 2013
@@ -8,8 +8,13 @@ import fs_uae_launcher.fsui as fsui
 from .Archive import Archive
 from .ROMManager import ROMManager
 
+import os.path
+
 class ChecksumTool():
 
+    TOO_BIG = 64*1024*1024
+    ZERO_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
+
     def __init__(self, parent):
         self.parent = parent
         #fsui.Window.__init__(self, parent, "Checksumming")
@@ -21,7 +26,21 @@ class ChecksumTool():
         ##self.center_on_parent()
 
     def checksum(self, path):
-        print("checksum", repr(path))
+        # first check that we even want to checksum
+        size = os.path.getsize(path)
+        if size >= ChecksumTool.TOO_BIG:
+            print("checksumtool: not checksumming large file: %s" % path)
+            return ""
+        elif size == 0:
+            # either a real 0-byte file or a device node on a BSD           
+            # system (could be large). To reliably get the size we could    
+            # use ioctl, but we simply return the checksum for a 0-byte     
+            # file anyway                                               
+            print("checksumtool: not checksumming zero "
+                    "sized file/device: %s" % path)
+            return ChecksumTool.ZERO_SHA1
+
+        print("checksumtool: checksumming ", repr(path))
         archive = Archive(path)
         s = hashlib.sha1()
         f = archive.open(path)
