fixing memory leaks, now memory usage remains nearly constant when creating a full...
authorEduardo Robles Elvira <edulix@wadobo.com>
Wed, 9 Oct 2013 09:52:02 +0000 (11:52 +0200)
committerEduardo Robles Elvira <edulix@wadobo.com>
Wed, 9 Oct 2013 09:52:02 +0000 (11:52 +0200)
deltatar/deltatar.py
deltatar/tarfile.py

index fcc09c5..bab22f4 100644 (file)
@@ -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
index 573e66d..f9c8e79 100644 (file)
@@ -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