From 80910564c510ead2b037c92d01525d1038402038 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Mon, 4 Jul 2016 11:48:16 +0200 Subject: [PATCH] Remove code duplication --- deltatar/deltatar.py | 18 +++++++----------- 1 files changed, 7 insertions(+), 11 deletions(-) diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index 8f72897..0a05694 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -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) -- 1.7.1