Remove code duplication
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 4 Jul 2016 09:48:16 +0000 (11:48 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 4 Jul 2016 10:18:46 +0000 (12:18 +0200)
deltatar/deltatar.py

index 8f72897..0a05694 100644 (file)
@@ -834,11 +834,6 @@ class DeltaTar(object):
 
                 # retrieve file offset
                 stat['offset'] = tarobj.get_last_member_offset()
-
-                # store in the index the stat dict
-                s = bytes(json.dumps(stat) + '\n', 'UTF-8')
-                crc = binascii.crc32(s, crc) & 0xffffffff
-                index_fd.write(s)
             elif action == 'delete':
                 path = self.unprefixed(ipath['path'])
                 stat = {
@@ -849,19 +844,20 @@ class DeltaTar(object):
 
                 # mark it as deleted in the backup
                 tarobj.add("/dev/null", arcname=stat['path'])
-
-                # store in the index the stat dict
-                s = bytes(json.dumps(stat) + '\n', 'UTF-8')
-                crc = binascii.crc32(s, crc) & 0xffffffff
-                index_fd.write(s)
             elif action == 'list':
                 stat = dpath.copy()
                 path = self.unprefixed(ipath['path'])
                 stat['path'] = u'list://' + path
                 # unchanged files do not enter in the backup, only in the index
                 self.logger.debug("[UNCHANGED] %s" % path)
+            else:
+                # should not happen
+                self.logger.warn('unknown action in create_diff_backup: {0}'
+                                 ''.format(action))
+                stat = None
 
-                # store in the index the stat dict
+            if stat:
+                # store the stat dict in the index
                 s = bytes(json.dumps(stat) + '\n', 'UTF-8')
                 crc = binascii.crc32(s, crc) & 0xffffffff
                 index_fd.write(s)