fixing a bug when a page is blanked
[mw] / src / mw / metadir.py
index 4bf8c426a8488755312a7e18731cbdc589752671..9aae09146c7154aaf2647fa9b5d34218687263d8 100644 (file)
@@ -131,14 +131,18 @@ class Metadir(object):
         pagedata = json.loads(fd.read())
         return pagedata[str(rvid)]
 
-    def working_dir_status(self):
+    def working_dir_status(self, files=None):
         status = {}
         check = []
-        for root, dirs, files in os.walk(self.root):
-            if root == self.root:
-                dirs.remove('.mw')
-            for name in files:
-                check.append(os.path.join(root, name))
+        if files == None or files == []:
+            for root, dirs, files in os.walk(self.root):
+                if root == self.root:
+                    dirs.remove('.mw')
+                for name in files:
+                    check.append(os.path.join(root, name))
+        else:
+            for file in files:
+                check.append(os.path.join(os.getcwd(), file))
         check.sort()
         for full in check:
             name = os.path.split(full)[1]
@@ -151,7 +155,7 @@ class Metadir(object):
                     rvid = self.pages_get_rv_list(pageid)[-1]
                     rv = self.pages_get_rv(pageid, rvid)
                     cur_content = codecs.open(full, 'r', 'utf-8').read()
-                    if cur_content[-1] == '\n':
+                    if (len(cur_content) != 0) and (cur_content[-1] == '\n'):
                         cur_content = cur_content[:-1]
                     if cur_content != rv['content']:
                         status[os.path.relpath(full, self.root)] = 'U'
@@ -172,7 +176,7 @@ class Metadir(object):
             old = [i + '\n' for i in oldrv['content'].split('\n')]
             if newrvid == 0:
                 cur_content = codecs.open(filename, 'r', 'utf-8').read()
-                if cur_content[-1] == '\n':
+                if (len(cur_content) != 0) and (cur_content[-1] == '\n'):
                     cur_content = cur_content[:-1]
                 newname = 'b/%s (working copy)' % filename
                 new = [i + '\n' for i in cur_content.split('\n')]

Benjamin Mako Hill || Want to submit a patch?