clean up multi-index handling
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 2 May 2017 14:14:44 +0000 (16:14 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
WIP

deltatar/deltatar.py

index 71912b6..27c0630 100644 (file)
@@ -1446,18 +1446,28 @@ class RestoreHelper(object):
     # tarfile.extractall for details.
     _directories = []
 
-    def __init__(self, deltatar, cwd, index_list=[], backup_path=False,
+    def __init__(self, deltatar, cwd, index_list=None, backup_path=False,
                  tarobj=None):
         '''
         Constructor opens the tars and init the data structures.
 
-        Index list must be provided in reverse order (newer first)
+        Assumptions:
+
+            - Index list must be provided in reverse order (newer first).
+            - “newer first” apparently means that if there are n backups
+              provided, the last full backup is at index n-1 and the most recent
+              diff backup is at index 0.
+            - Only the first, the second, and the last elements of
+              ``index_list`` are relevant, others will not be accessed.
+            - If no ``index_list`` is provided, both ``tarobj`` and
+              ``backup_path`` must be passed.
+            - If ``index_list`` is provided, the values of ``tarobj`` and
+              ``backup_path`` are ignored.
         '''
         self._data = []
         self._directories = []
         self._deltatar = deltatar
         self._cwd = cwd
-        self._index_list = index_list
 
         try:
             import grp, pwd
@@ -1469,9 +1479,9 @@ class RestoreHelper(object):
         else:
             self.canchown = False
 
-        if index_list:
+        if index_list is not None:
             for index in index_list:
-                is_full = (index == index_list[-1])
+                is_full = index == index_list[-1]
 
                 # make paths absolute to avoid cwd problems
                 if not os.path.isabs(index):
@@ -1551,6 +1561,10 @@ class RestoreHelper(object):
         Restore the path from the appropriate backup. Receives the current path
         from the newest (=first) index iterator. itpath must be not null.
         callback is a custom function that gets called for every file.
+
+        NB: This function takes the attribute ``_data`` as input but will only
+        ever use its first and, if available, second element. Anything else in
+        ``._data[]`` will be ignored.
         '''
         path = itpath['path']