From 6f422b65e36c243e0b63c08af62ef96957e89c9a Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Wed, 9 Oct 2013 11:52:02 +0200 Subject: [PATCH] fixing memory leaks, now memory usage remains nearly constant when creating a full backup --- deltatar/deltatar.py | 7 +++++++ deltatar/tarfile.py | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index fcc09c5..bab22f4 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -586,7 +586,13 @@ class DeltaTar(object): os.chdir(source_path) # for each file to be in the backup, do: + i = 0 for path in self._recursive_walk_dir('.'): + i += 1 + if i % 2000 == 0: + import gc + gc.collect() + # calculate stat dict for current file stat = self._stat_dict(path) stat['path'] = u'snapshot://' + stat['path'] @@ -602,6 +608,7 @@ class DeltaTar(object): s = json.dumps(stat) + '\n' crc = binascii.crc32(s, crc) & 0xffffffff index_fd.write(s) + del stat s = '{"type": "END-FILE-LIST"}\n' crc = binascii.crc32(s, crc) & 0xffffffff diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 573e66d..f9c8e79 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -2171,7 +2171,8 @@ class TarFile(object): if arcname is None: arcname = name drv, arcname = os.path.splitdrive(arcname) - arcname = arcname.replace(os.sep, "/") + if os.sep != "/": + arcname = arcname.replace(os.sep, "/") arcname = arcname.lstrip("/") # Now, fill the TarInfo object with @@ -2203,7 +2204,7 @@ class TarFile(object): # The inode is added only if its valid. # For win32 it is always 0. type = REGTYPE - if inode[0]: + if inode[0] and self.save_to_members: self.inodes[inode] = arcname elif stat.S_ISDIR(stmd): type = DIRTYPE -- 1.7.1