added a few debug messages to addfile and open_volume
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 9 Jun 2016 15:58:39 +0000 (17:58 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 15 Jun 2016 11:18:02 +0000 (13:18 +0200)
deltatar/tarfile.py

index e0eacde..8e401f3 100644 (file)
@@ -2392,6 +2392,7 @@ class TarFile(object):
         buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
         self.fileobj.write(buf)
         self.offset += len(buf)
+        self._dbg(1, 'tarinfo has size {}'.format(len(buf)))
 
         if self.max_volume_size:
             if isinstance(self.fileobj, _Stream):
@@ -2425,6 +2426,9 @@ class TarFile(object):
             size_can_write = min(target_size_left, source_size_left)
 
             while size_can_write > 0:
+                self._dbg(1, 'source_size_left={}, size_left={} --> write {}'
+                             .format(source_size_left, target_size_left,
+                                     size_can_write))
                 copyfileobj(fileobj, self.fileobj, size_can_write)
                 self.offset += size_can_write
                 source_size_left -= size_can_write
@@ -2432,6 +2436,8 @@ class TarFile(object):
                 size_can_write = min(target_size_left, source_size_left)
 
             # now target_size_left == 0 or source_size_left == 0
+            self._dbg(1, 'source_size_left={}, size_left={} --> end write loop'
+                         .format(source_size_left, target_size_left))
 
             # if there is data left to write, we need to create a new volume
             if source_size_left > 0:
@@ -2460,6 +2466,7 @@ class TarFile(object):
 
                 # write new volume header
                 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
+                self._dbg(1, 'tarinfo has size {}'.format(len(buf)))
                 self.fileobj.write(buf)
                 self.offset += len(buf)
 
@@ -2467,10 +2474,13 @@ class TarFile(object):
                 # --> _size_left should be big again
                 target_size_left = _size_left()
                 size_can_write = min(target_size_left, source_size_left)
+                self._dbg(1, 'new volume')
 
         # now, all data has been written. We may have to fill up the rest of
         # the block in target with 0s
         remainder = (tarinfo.size - tarinfo.volume_offset) % BLOCKSIZE
+        self._dbg(1, 'wrote everything, fill with {} 0s to {}'
+                     .format(BLOCKSIZE - remainder, BLOCKSIZE))
         if remainder > 0:
             self.fileobj.write(NUL * (BLOCKSIZE - remainder))
             self.offset += BLOCKSIZE - remainder
@@ -2491,6 +2501,7 @@ class TarFile(object):
             self._extfileobj = False
 
             if isinstance(self.fileobj, _Stream):
+                self._dbg(1, 'open_volume: create a _Stream')
                 fileobj = _Stream(name=name,
                             mode=self.fileobj.mode,
                             comptype=self.fileobj.comptype,
@@ -2502,6 +2513,7 @@ class TarFile(object):
                             concat_stream=self.fileobj.concat_stream)
             else:
                 # here, we lose information about compression/encryption!
+                self._dbg(1, 'open_volume: builtin open')
                 fileobj = bltn_open(name, self._mode)
         else:
             if name is None and hasattr(fileobj, "name"):
@@ -2509,6 +2521,8 @@ class TarFile(object):
             if hasattr(fileobj, "mode"):
                 self._mode = fileobj.mode
             self._extfileobj = True
+            self._dbg(1, 'open_volume: using external fileobj {}'
+                          .format(fileobj))
         self.name = os.path.abspath(name) if name else None
         self.fileobj = fileobj