]> projects.mako.cc - mw/commitdiff
Fixes to Metadir:pages_add_rev
authorIan Weller <ian@ianweller.org>
Tue, 22 Dec 2009 02:28:39 +0000 (20:28 -0600)
committerIan Weller <ian@ianweller.org>
Tue, 22 Dec 2009 02:28:39 +0000 (20:28 -0600)
src/mw/metadir.py

index 49a91cf588f943c719a71845f9fc97e9b81523aa..3988d78981c535f4539330a5dd80dd20e448e308 100644 (file)
@@ -82,11 +82,13 @@ class Metadir(object):
     def pages_add_rev(self, pageid, rv):
         pagefile = os.path.join(self.location, 'cache', 'pages', str(pageid))
         fd = file(pagefile, 'w+')
     def pages_add_rev(self, pageid, rv):
         pagefile = os.path.join(self.location, 'cache', 'pages', str(pageid))
         fd = file(pagefile, 'w+')
-        pagedata = json.loads(fd.read())
+        pagedata_raw = fd.read()
+        if pagedata_raw == '':
+            pagedata = {}
+        else:
+            pagedata = json.loads(pagedata_raw)
         rvid = int(rv['revid'])
         rvid = int(rv['revid'])
-        if pageid not in pagedata.keys():
-            pagedata[pageid] = {}
-        pagedata[pageid][rvid] = {
+        pagedata[rvid] = {
                 'user': rv['user'], 'timestamp': rv['timestamp'],
                 'content': rv['*'],
         }
                 'user': rv['user'], 'timestamp': rv['timestamp'],
                 'content': rv['*'],
         }

Benjamin Mako Hill || Want to submit a patch?