Commit d79e4da8 authored by ben's avatar ben

Various changed to deal with new IterTreeReducer format


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@68 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent d4f87b46
...@@ -109,19 +109,19 @@ class HLSourceStruct: ...@@ -109,19 +109,19 @@ class HLSourceStruct:
""" """
collated = RORPIter.CollateIterators(cls.initial_dsiter2, sigiter) collated = RORPIter.CollateIterators(cls.initial_dsiter2, sigiter)
finalizer = DestructiveStepping.Finalizer() finalizer = DestructiveSteppingFinalizer()
def diffs(): def diffs():
for dsrp, dest_sig in collated: for dsrp, dest_sig in collated:
try: try:
if dest_sig: if dest_sig:
if dest_sig.isplaceholder(): yield dest_sig if dest_sig.isplaceholder(): yield dest_sig
else: yield RORPIter.diffonce(dest_sig, dsrp) else: yield RORPIter.diffonce(dest_sig, dsrp)
if dsrp: finalizer(dsrp) if dsrp: finalizer(dsrp.index, dsrp)
except (IOError, OSError, RdiffException): except (IOError, OSError, RdiffException):
Log.exception() Log.exception()
Log("Error processing %s, skipping" % Log("Error processing %s, skipping" %
str(dest_sig.index), 2) str(dest_sig.index), 2)
finalizer.getresult() finalizer.Finish()
return diffs() return diffs()
MakeClass(HLSourceStruct) MakeClass(HLSourceStruct)
...@@ -209,13 +209,15 @@ class HLDestinationStruct: ...@@ -209,13 +209,15 @@ class HLDestinationStruct:
def get_finalizer(cls): def get_finalizer(cls):
"""Return finalizer, starting from session info if necessary""" """Return finalizer, starting from session info if necessary"""
init_state = cls._session_info and cls._session_info.finalizer_state old_finalizer = cls._session_info and cls._session_info.finalizer
return DestructiveStepping.Finalizer(init_state) if old_finalizer: return old_finalizer
else: return DestructiveSteppingFinalizer()
def get_ITR(cls, inc_rpath): def get_ITR(cls, inc_rpath):
"""Return ITR, starting from state if necessary""" """Return ITR, starting from state if necessary"""
init_state = cls._session_info and cls._session_info.ITR_state if cls._session_info and cls._session_info.ITR:
return Inc.make_patch_increment_ITR(inc_rpath, init_state) return cls._session_info.ITR
else: return IncrementITR(inc_rpath)
def patch_and_finalize(cls, dest_rpath, diffs, checkpoint = 1): def patch_and_finalize(cls, dest_rpath, diffs, checkpoint = 1):
"""Apply diffs and finalize""" """Apply diffs and finalize"""
...@@ -233,7 +235,7 @@ class HLDestinationStruct: ...@@ -233,7 +235,7 @@ class HLDestinationStruct:
DestructiveStepping.initialize(dsrp, None) DestructiveStepping.initialize(dsrp, None)
if diff_rorp and not diff_rorp.isplaceholder(): if diff_rorp and not diff_rorp.isplaceholder():
RORPIter.patchonce_action(None, dsrp, diff_rorp).execute() RORPIter.patchonce_action(None, dsrp, diff_rorp).execute()
finalizer(dsrp) finalizer(dsrp.index, dsrp)
return dsrp return dsrp
try: try:
...@@ -242,7 +244,7 @@ class HLDestinationStruct: ...@@ -242,7 +244,7 @@ class HLDestinationStruct:
except StopIteration: break except StopIteration: break
if checkpoint: SaveState.checkpoint_mirror(finalizer, dsrp) if checkpoint: SaveState.checkpoint_mirror(finalizer, dsrp)
except: cls.handle_last_error(dsrp, finalizer) except: cls.handle_last_error(dsrp, finalizer)
finalizer.getresult() finalizer.Finish()
if Globals.preserve_hardlinks and Globals.rbdir: if Globals.preserve_hardlinks and Globals.rbdir:
Hardlink.final_writedata() Hardlink.final_writedata()
if checkpoint: SaveState.checkpoint_remove() if checkpoint: SaveState.checkpoint_remove()
...@@ -258,16 +260,13 @@ class HLDestinationStruct: ...@@ -258,16 +260,13 @@ class HLDestinationStruct:
indexed_tuple = collated.next() indexed_tuple = collated.next()
Log("Processing %s" % str(indexed_tuple), 7) Log("Processing %s" % str(indexed_tuple), 7)
diff_rorp, dsrp = indexed_tuple diff_rorp, dsrp = indexed_tuple
index = indexed_tuple.index
if not dsrp: if not dsrp:
dsrp = cls.get_dsrp(dest_rpath, indexed_tuple.index) dsrp = cls.get_dsrp(dest_rpath, index)
DestructiveStepping.initialize(dsrp, None) DestructiveStepping.initialize(dsrp, None)
indexed_tuple = IndexedTuple(indexed_tuple.index, if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None
(diff_rorp, dsrp)) ITR(index, diff_rorp, dsrp)
if diff_rorp and diff_rorp.isplaceholder(): finalizer(index, dsrp)
indexed_tuple = IndexedTuple(indexed_tuple.index,
(None, dsrp))
ITR(indexed_tuple)
finalizer(dsrp)
return dsrp return dsrp
try: try:
...@@ -275,8 +274,8 @@ class HLDestinationStruct: ...@@ -275,8 +274,8 @@ class HLDestinationStruct:
try: dsrp = cls.check_skip_error(error_checked, dsrp) try: dsrp = cls.check_skip_error(error_checked, dsrp)
except StopIteration: break except StopIteration: break
SaveState.checkpoint_inc_backup(ITR, finalizer, dsrp) SaveState.checkpoint_inc_backup(ITR, finalizer, dsrp)
cls.check_skip_error(ITR.getresult, dsrp) cls.check_skip_error(ITR.Finish, dsrp)
cls.check_skip_error(finalizer.getresult, dsrp) cls.check_skip_error(finalizer.Finish, dsrp)
except: cls.handle_last_error(dsrp, finalizer, ITR) except: cls.handle_last_error(dsrp, finalizer, ITR)
if Globals.preserve_hardlinks: Hardlink.final_writedata() if Globals.preserve_hardlinks: Hardlink.final_writedata()
SaveState.checkpoint_remove() SaveState.checkpoint_remove()
......
...@@ -593,13 +593,9 @@ class RPath(RORPath): ...@@ -593,13 +593,9 @@ class RPath(RORPath):
self.setdata() self.setdata()
if not self.lstat(): return # must have been deleted in meantime if not self.lstat(): return # must have been deleted in meantime
elif self.isdir(): elif self.isdir():
def helper(dsrp, base_init_output, branch_reduction): itm = RpathDeleter()
if dsrp.isdir(): dsrp.rmdir() for dsrp in Select(self, None).set_iter(): itm(dsrp.index, dsrp)
else: dsrp.delete() itm.Finish()
itm = IterTreeReducer(lambda x: None, lambda x,y: None, None,
helper)
for dsrp in Select(self, None).set_iter(): itm(dsrp)
itm.getresult()
else: self.conn.os.unlink(self.path) else: self.conn.os.unlink(self.path)
self.setdata() self.setdata()
...@@ -752,3 +748,15 @@ class RPathFileHook: ...@@ -752,3 +748,15 @@ class RPathFileHook:
result = self.file.close() result = self.file.close()
self.closing_thunk() self.closing_thunk()
return result return result
class RpathDeleter(IterTreeReducer):
"""Delete a directory. Called by RPath.delete()"""
def start_process(self, index, dsrp):
self.dsrp = dsrp
def end_process(self):
if self.dsrp.isdir(): self.dsrp.rmdir()
else: self.dsrp.delete()
...@@ -109,19 +109,19 @@ class HLSourceStruct: ...@@ -109,19 +109,19 @@ class HLSourceStruct:
""" """
collated = RORPIter.CollateIterators(cls.initial_dsiter2, sigiter) collated = RORPIter.CollateIterators(cls.initial_dsiter2, sigiter)
finalizer = DestructiveStepping.Finalizer() finalizer = DestructiveSteppingFinalizer()
def diffs(): def diffs():
for dsrp, dest_sig in collated: for dsrp, dest_sig in collated:
try: try:
if dest_sig: if dest_sig:
if dest_sig.isplaceholder(): yield dest_sig if dest_sig.isplaceholder(): yield dest_sig
else: yield RORPIter.diffonce(dest_sig, dsrp) else: yield RORPIter.diffonce(dest_sig, dsrp)
if dsrp: finalizer(dsrp) if dsrp: finalizer(dsrp.index, dsrp)
except (IOError, OSError, RdiffException): except (IOError, OSError, RdiffException):
Log.exception() Log.exception()
Log("Error processing %s, skipping" % Log("Error processing %s, skipping" %
str(dest_sig.index), 2) str(dest_sig.index), 2)
finalizer.getresult() finalizer.Finish()
return diffs() return diffs()
MakeClass(HLSourceStruct) MakeClass(HLSourceStruct)
...@@ -209,13 +209,15 @@ class HLDestinationStruct: ...@@ -209,13 +209,15 @@ class HLDestinationStruct:
def get_finalizer(cls): def get_finalizer(cls):
"""Return finalizer, starting from session info if necessary""" """Return finalizer, starting from session info if necessary"""
init_state = cls._session_info and cls._session_info.finalizer_state old_finalizer = cls._session_info and cls._session_info.finalizer
return DestructiveStepping.Finalizer(init_state) if old_finalizer: return old_finalizer
else: return DestructiveSteppingFinalizer()
def get_ITR(cls, inc_rpath): def get_ITR(cls, inc_rpath):
"""Return ITR, starting from state if necessary""" """Return ITR, starting from state if necessary"""
init_state = cls._session_info and cls._session_info.ITR_state if cls._session_info and cls._session_info.ITR:
return Inc.make_patch_increment_ITR(inc_rpath, init_state) return cls._session_info.ITR
else: return IncrementITR(inc_rpath)
def patch_and_finalize(cls, dest_rpath, diffs, checkpoint = 1): def patch_and_finalize(cls, dest_rpath, diffs, checkpoint = 1):
"""Apply diffs and finalize""" """Apply diffs and finalize"""
...@@ -233,7 +235,7 @@ class HLDestinationStruct: ...@@ -233,7 +235,7 @@ class HLDestinationStruct:
DestructiveStepping.initialize(dsrp, None) DestructiveStepping.initialize(dsrp, None)
if diff_rorp and not diff_rorp.isplaceholder(): if diff_rorp and not diff_rorp.isplaceholder():
RORPIter.patchonce_action(None, dsrp, diff_rorp).execute() RORPIter.patchonce_action(None, dsrp, diff_rorp).execute()
finalizer(dsrp) finalizer(dsrp.index, dsrp)
return dsrp return dsrp
try: try:
...@@ -242,7 +244,7 @@ class HLDestinationStruct: ...@@ -242,7 +244,7 @@ class HLDestinationStruct:
except StopIteration: break except StopIteration: break
if checkpoint: SaveState.checkpoint_mirror(finalizer, dsrp) if checkpoint: SaveState.checkpoint_mirror(finalizer, dsrp)
except: cls.handle_last_error(dsrp, finalizer) except: cls.handle_last_error(dsrp, finalizer)
finalizer.getresult() finalizer.Finish()
if Globals.preserve_hardlinks and Globals.rbdir: if Globals.preserve_hardlinks and Globals.rbdir:
Hardlink.final_writedata() Hardlink.final_writedata()
if checkpoint: SaveState.checkpoint_remove() if checkpoint: SaveState.checkpoint_remove()
...@@ -258,16 +260,13 @@ class HLDestinationStruct: ...@@ -258,16 +260,13 @@ class HLDestinationStruct:
indexed_tuple = collated.next() indexed_tuple = collated.next()
Log("Processing %s" % str(indexed_tuple), 7) Log("Processing %s" % str(indexed_tuple), 7)
diff_rorp, dsrp = indexed_tuple diff_rorp, dsrp = indexed_tuple
index = indexed_tuple.index
if not dsrp: if not dsrp:
dsrp = cls.get_dsrp(dest_rpath, indexed_tuple.index) dsrp = cls.get_dsrp(dest_rpath, index)
DestructiveStepping.initialize(dsrp, None) DestructiveStepping.initialize(dsrp, None)
indexed_tuple = IndexedTuple(indexed_tuple.index, if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None
(diff_rorp, dsrp)) ITR(index, diff_rorp, dsrp)
if diff_rorp and diff_rorp.isplaceholder(): finalizer(index, dsrp)
indexed_tuple = IndexedTuple(indexed_tuple.index,
(None, dsrp))
ITR(indexed_tuple)
finalizer(dsrp)
return dsrp return dsrp
try: try:
...@@ -275,8 +274,8 @@ class HLDestinationStruct: ...@@ -275,8 +274,8 @@ class HLDestinationStruct:
try: dsrp = cls.check_skip_error(error_checked, dsrp) try: dsrp = cls.check_skip_error(error_checked, dsrp)
except StopIteration: break except StopIteration: break
SaveState.checkpoint_inc_backup(ITR, finalizer, dsrp) SaveState.checkpoint_inc_backup(ITR, finalizer, dsrp)
cls.check_skip_error(ITR.getresult, dsrp) cls.check_skip_error(ITR.Finish, dsrp)
cls.check_skip_error(finalizer.getresult, dsrp) cls.check_skip_error(finalizer.Finish, dsrp)
except: cls.handle_last_error(dsrp, finalizer, ITR) except: cls.handle_last_error(dsrp, finalizer, ITR)
if Globals.preserve_hardlinks: Hardlink.final_writedata() if Globals.preserve_hardlinks: Hardlink.final_writedata()
SaveState.checkpoint_remove() SaveState.checkpoint_remove()
......
...@@ -593,13 +593,9 @@ class RPath(RORPath): ...@@ -593,13 +593,9 @@ class RPath(RORPath):
self.setdata() self.setdata()
if not self.lstat(): return # must have been deleted in meantime if not self.lstat(): return # must have been deleted in meantime
elif self.isdir(): elif self.isdir():
def helper(dsrp, base_init_output, branch_reduction): itm = RpathDeleter()
if dsrp.isdir(): dsrp.rmdir() for dsrp in Select(self, None).set_iter(): itm(dsrp.index, dsrp)
else: dsrp.delete() itm.Finish()
itm = IterTreeReducer(lambda x: None, lambda x,y: None, None,
helper)
for dsrp in Select(self, None).set_iter(): itm(dsrp)
itm.getresult()
else: self.conn.os.unlink(self.path) else: self.conn.os.unlink(self.path)
self.setdata() self.setdata()
...@@ -752,3 +748,15 @@ class RPathFileHook: ...@@ -752,3 +748,15 @@ class RPathFileHook:
result = self.file.close() result = self.file.close()
self.closing_thunk() self.closing_thunk()
return result return result
class RpathDeleter(IterTreeReducer):
"""Delete a directory. Called by RPath.delete()"""
def start_process(self, index, dsrp):
self.dsrp = dsrp
def end_process(self):
if self.dsrp.isdir(): self.dsrp.rmdir()
else: self.dsrp.delete()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment