Skip to contentSkip to conversation

Add error handling to read_cache in stage-manager

PATCH New Mickaël Chazaux 1 participant 1 message Apr 30, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add error handling to read_cache in stage-manager

Sometimes stage-manager crashes with this message :
Traceback (most recent call last):
File "/home/mchazaux/projet/OE/openembedded/recipes/stage-manager/files/stage-manager",
line 79, in <module>
cache = read_cache(options.cachefile)
File "/home/mchazaux/projet/OE/openembedded/recipes/stage-manager/files/stage-manager",
line 34, in read_cache
cache[data[0]]['ts'] = int(data[1])
IndexError: list index out of range

This is due to a corrupted cache file. This patch adds an error message and continues parsing ignoring the wrong line. The file is then properly regenerated.

---
 recipes/stage-manager/files/stage-manager          |   14 +++++++++-----
 recipes/stage-manager/stagemanager-native_0.0.1.bb |    2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)
recipes/stage-manager/files/stage-manager +9 -5
index 536d1af..039614f 100755
@@ -29,11 +29,15 @@ def read_cache(cachefile):
     lines = f.readlines()
     f.close()
     for l in lines:
-        data = l.split('|')
-        cache[data[0]] = {}
-        cache[data[0]]['ts'] = int(data[1])
-        cache[data[0]]['size'] = int(data[2])
-        cache[data[0]]['seen'] = False
+	try:
+            data = l.split('|')
+            d = {}
+            d['ts'] = int(data[1])
+            d['size'] = int(data[2])
+            d['seen'] = False
+            cache[data[0]] = d
+	except (IndexError, ValueError):
+            print("Corrupted line in cachefile " + cachefile + " : " + l)
     return cache
 
 def mkdirhier(dir):
recipes/stage-manager/stagemanager-native_0.0.1.bb +1 -1
index 5708045..4357517 100644
@@ -1,5 +1,5 @@
 DESCRIPTION = "Helper script for packaged-staging.bbclass"
-PR = "r11"
+PR = "r13"
 
 SRC_URI = "file://stage-manager \
            file://stage-manager-ipkg \
Signature · 1 line
1.6.3.3