summaryrefslogtreecommitdiff
path: root/obnam
diff options
context:
space:
mode:
authorLars Wirzenius <liw@gytha>2008-04-20 21:47:17 +0300
committerLars Wirzenius <liw@gytha>2008-04-20 21:47:17 +0300
commit141b3496205a12ec7cba6d291aae9f7fa15a7002 (patch)
tree36868cce2587cb51c5ffa935b2ae26243a25b025 /obnam
parent2b416d957c9a86d4db0ec12fc1236c788a4b2c4b (diff)
downloadobnam-141b3496205a12ec7cba6d291aae9f7fa15a7002.tar.gz
Re-use contents of files that have not changed from the previous backup.
Diffstat (limited to 'obnam')
-rw-r--r--obnam/app.py33
-rw-r--r--obnam/cmp.py3
2 files changed, 30 insertions, 6 deletions
diff --git a/obnam/app.py b/obnam/app.py
index a84ea939..38261f96 100644
--- a/obnam/app.py
+++ b/obnam/app.py
@@ -249,16 +249,39 @@ class Application:
else:
return None
+ def _reuse_existing(self, old_file):
+ return (old_file.first_string_by_kind(obnam.cmp.CONTREF),
+ old_file.first_string_by_kind(obnam.cmp.SIGREF),
+ old_file.first_string_by_kind(obnam.cmp.DELTAREF))
+
+ def _compute_delta(self, filename):
+ # FIXME: This should compute a delta.
+ return self._backup_new(filename)
+
+ def _backup_new(self, filename):
+ contref = obnam.io.create_file_contents_object(self._context,
+ filename)
+ sig = self.compute_signature(filename)
+ sigref = sig.get_id()
+ deltaref = None
+ return contref, sigref, deltaref
+
def add_to_filegroup(self, fg, filename):
"""Add a file to a filegroup."""
self._context.progress.update_current_action(filename)
st = os.stat(filename)
if stat.S_ISREG(st.st_mode):
- contref = obnam.io.create_file_contents_object(self._context,
- filename)
- sig = self.compute_signature(filename)
- sigref = sig.get_id()
- deltaref = None
+ unsolved = obnam.io.unsolve(self.get_context(), filename)
+ old_file = self.get_file_in_previous_generation(unsolved)
+ if old_file:
+ old_st = old_file.first_by_kind(obnam.cmp.STAT)
+ old_st = obnam.cmp.parse_stat_component(old_st)
+ if self.file_is_unchanged(old_st, st):
+ contref, sigref, deltaref = self._reuse_existing(old_file)
+ else:
+ contref, sigref, deltaref = self._compute_delta(filename)
+ else:
+ contref, sigref, deltaref = self._backup_new(filename)
else:
contref = None
sigref = None
diff --git a/obnam/cmp.py b/obnam/cmp.py
index ac02355d..d83092eb 100644
--- a/obnam/cmp.py
+++ b/obnam/cmp.py
@@ -111,7 +111,8 @@ class Component:
def __init__(self, kind, value):
self.kind = kind
- assert type(value) in [type(""), type([])]
+ assert type(value) in [type(""), type([])], \
+ "Value type is %s instead of string or list" % type(value)
if type(value) == type(""):
self.str = value
self.subcomponents = []