summaryrefslogtreecommitdiff
path: root/rdiff-backup/src/increment.py
diff options
context:
space:
mode:
Diffstat (limited to 'rdiff-backup/src/increment.py')
-rw-r--r--rdiff-backup/src/increment.py118
1 files changed, 22 insertions, 96 deletions
diff --git a/rdiff-backup/src/increment.py b/rdiff-backup/src/increment.py
index 446806b..b28b315 100644
--- a/rdiff-backup/src/increment.py
+++ b/rdiff-backup/src/increment.py
@@ -1,4 +1,4 @@
-execfile("selection.py")
+execfile("filename_mapping.py")
#######################################################################
#
@@ -85,10 +85,12 @@ class Inc:
"""Get new increment rp with given time suffix"""
addtostr = lambda s: "%s.%s.%s" % (s, timestr, typestr)
if rp.index:
- return rp.__class__(rp.conn, rp.base, rp.index[:-1] +
- (addtostr(rp.index[-1]),))
- else: return rp.__class__(rp.conn, addtostr(rp.base), rp.index)
-
+ incrp = rp.__class__(rp.conn, rp.base, rp.index[:-1] +
+ (addtostr(rp.index[-1]),))
+ else: incrp = rp.__class__(rp.conn, addtostr(rp.base), rp.index)
+ if Globals.quoting_enabled: incrp.quote_path()
+ return incrp
+
inctime = 0
while 1:
inctime = Resume.FindTime(rp.index, inctime)
@@ -123,7 +125,7 @@ class IncrementITR(IterTreeReducer):
def __init__(self, inc_rpath):
"""Set inc_rpath, an rpath of the base of the tree"""
self.inc_rpath = inc_rpath
- IterTreeReducer.__init__(inc_rpath)
+ IterTreeReducer.__init__(self, inc_rpath)
def start_process(self, index, diff_rorp, dsrp):
"""Initial processing of file
@@ -133,11 +135,21 @@ class IncrementITR(IterTreeReducer):
"""
incpref = self.inc_rpath.new_index(index)
+ if Globals.quoting_enabled: incpref.quote_path()
if dsrp.isdir():
self.init_dir(dsrp, diff_rorp, incpref)
self.setvals(diff_rorp, dsrp, incpref)
else: self.init_non_dir(dsrp, diff_rorp, incpref)
+ def override_changed(self):
+ """Set changed flag to true
+
+ This is used only at the top level of a backup, to make sure
+ that a marker is created recording every backup session.
+
+ """
+ self.changed = 1
+
def setvals(self, diff_rorp, dsrp, incpref):
"""Record given values in state dict since in directory
@@ -162,7 +174,7 @@ class IncrementITR(IterTreeReducer):
"""
if not (incpref.lstat() and incpref.isdir()): incpref.mkdir()
if diff_rorp and diff_rorp.isreg() and diff_rorp.file:
- tf = TempFileManager(dsrp)
+ tf = TempFileManager.new(dsrp)
RPathStatic.copy_with_attribs(diff_rorp, tf)
tf.set_attached_filetype(diff_rorp.get_attached_filetype())
self.directory_replacement = tf
@@ -170,7 +182,7 @@ class IncrementITR(IterTreeReducer):
def init_non_dir(self, dsrp, diff_rorp, incpref):
"""Process a non directory file (initial pass)"""
if not diff_rorp: return # no diff, so no change necessary
- if diff_rorp.isreg and (dsrp.isreg() or diff_rorp.isflaglinked()):
+ if diff_rorp.isreg() and (dsrp.isreg() or diff_rorp.isflaglinked()):
tf = TempFileManager.new(dsrp)
def init_thunk():
if diff_rorp.isflaglinked():
@@ -180,8 +192,8 @@ class IncrementITR(IterTreeReducer):
Inc.Increment_action(tf, dsrp, incpref).execute()
Robust.make_tf_robustaction(init_thunk, (tf,), (dsrp,)).execute()
else:
- Robust.chain([Inc.Increment_action(diff_rorp, dsrp, incref),
- RORPIter.patchonce_action(none, dsrp, diff_rorp)]
+ Robust.chain([Inc.Increment_action(diff_rorp, dsrp, incpref),
+ RORPIter.patchonce_action(None, dsrp, diff_rorp)]
).execute()
self.changed = 1
@@ -207,89 +219,3 @@ class IncrementITR(IterTreeReducer):
-
-
- def make_patch_increment_ITR(inc_rpath, initial_state = None):
- """Return IterTreeReducer that patches and increments"""
- def base_init(indexed_tuple):
- """Patch if appropriate, return (a,b) tuple
-
- a is true if found directory and thus didn't take action
-
- if a is false, b is true if some changes were made
-
- if a is true, b is the rp of a temporary file used to hold
- the diff_rorp's data (for dir -> normal file change), and
- false if none was necessary.
-
- """
- diff_rorp, dsrp = indexed_tuple
- incpref = inc_rpath.new_index(indexed_tuple.index)
- if dsrp.isdir(): return init_dir(dsrp, diff_rorp, incpref)
- else: return init_non_dir(dsrp, diff_rorp, incpref)
-
- def init_dir(dsrp, diff_rorp, incpref):
- """Initial processing of a directory
-
- Make the corresponding directory right away, but wait
- until the end to write the replacement. However, if the
- diff_rorp contains data, we must write it locally before
- continuing, or else that data will be lost in the stream.
-
- """
- if not (incpref.lstat() and incpref.isdir()): incpref.mkdir()
- if diff_rorp and diff_rorp.isreg() and diff_rorp.file:
- tf = TempFileManager.new(dsrp)
- RPathStatic.copy_with_attribs(diff_rorp, tf)
- tf.set_attached_filetype(diff_rorp.get_attached_filetype())
- return (1, tf)
- else: return (1, None)
-
- def init_non_dir(dsrp, diff_rorp, incpref):
- """Initial processing of non-directory
-
- If a reverse diff is called for it is generated by apply
- the forwards diff first on a temporary file.
-
- """
- if diff_rorp:
- if diff_rorp.isreg() and (dsrp.isreg() or
- diff_rorp.isflaglinked()):
- tf = TempFileManager.new(dsrp)
- def init_thunk():
- if diff_rorp.isflaglinked():
- Hardlink.link_rp(diff_rorp, tf, dsrp)
- else: Rdiff.patch_with_attribs_action(dsrp, diff_rorp,
- tf).execute()
- Inc.Increment_action(tf, dsrp, incpref).execute()
- Robust.make_tf_robustaction(init_thunk, (tf,),
- (dsrp,)).execute()
- else:
- Robust.chain([Inc.Increment_action(diff_rorp, dsrp,
- incpref),
- RORPIter.patchonce_action(
- None, dsrp, diff_rorp)]).execute()
- return (None, 1)
- return (None, None)
-
- def base_final(base_tuple, base_init_tuple, changed):
- """Patch directory if not done, return true iff made change"""
- if base_init_tuple[0]: # was directory
- diff_rorp, dsrp = base_tuple
- if changed or diff_rorp:
- if base_init_tuple[1]: diff_rorp = base_init_tuple[1]
- Inc.Increment(diff_rorp, dsrp,
- inc_rpath.new_index(base_tuple.index))
- if diff_rorp:
- RORPIter.patchonce_action(None, dsrp,
- diff_rorp).execute()
- if isinstance(diff_rorp, TempFile): diff_rorp.delete()
- return 1
- return None
- else: # changed iff base_init_tuple says it was
- return base_init_tuple[1]
-
- return IterTreeReducer(base_init, lambda x,y: x or y, None,
- base_final, initial_state)
-
-