Commit 5b18bf90 authored by ben's avatar ben

Various changes to work with new destructive_stepping initialization

code.


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@69 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent d79e4da8
...@@ -6,7 +6,7 @@ execfile("rorpiter.py") ...@@ -6,7 +6,7 @@ execfile("rorpiter.py")
# destructive-stepping - Deal with side effects from traversing trees # destructive-stepping - Deal with side effects from traversing trees
# #
class DSRPathError(Exception): class DSRPPermError(Exception):
"""Exception used when a DSRPath can't get sufficient permissions""" """Exception used when a DSRPath can't get sufficient permissions"""
pass pass
...@@ -85,7 +85,7 @@ class DSRPath(RPath): ...@@ -85,7 +85,7 @@ class DSRPath(RPath):
def warn(self, err): def warn(self, err):
Log("Received error '%s' when dealing with file %s, skipping..." Log("Received error '%s' when dealing with file %s, skipping..."
% (err, self.path), 1) % (err, self.path), 1)
raise DSRPathError(self.path) raise DSRPermError(self.path)
def __getstate__(self): def __getstate__(self):
"""Return picklable state. See RPath __getstate__.""" """Return picklable state. See RPath __getstate__."""
......
...@@ -134,7 +134,7 @@ class HLDestinationStruct: ...@@ -134,7 +134,7 @@ class HLDestinationStruct:
cls._session_info = session_info cls._session_info = session_info
def iterate_from(cls): def iterate_from(cls):
"""Supply more arguments to DestructiveStepping.Iterate_from""" """Return selection iterator to iterate all the mirror files"""
if cls._session_info is None: Globals.select_mirror.set_iter() if cls._session_info is None: Globals.select_mirror.set_iter()
else: Globals.select_mirror.set_iter(cls._session_info.last_index) else: Globals.select_mirror.set_iter(cls._session_info.last_index)
return Globals.select_mirror return Globals.select_mirror
...@@ -203,9 +203,8 @@ class HLDestinationStruct: ...@@ -203,9 +203,8 @@ class HLDestinationStruct:
def get_dsrp(cls, dest_rpath, index): def get_dsrp(cls, dest_rpath, index):
"""Return initialized dsrp based on dest_rpath with given index""" """Return initialized dsrp based on dest_rpath with given index"""
dsrp = DSRPath(dest_rpath.conn, dest_rpath.base, index) return DSRPath(source = None, dest_rpath.conn,
DestructiveStepping.initialize(dsrp, None) dest_rpath.base, index)
return dsrp
def get_finalizer(cls): def get_finalizer(cls):
"""Return finalizer, starting from session info if necessary""" """Return finalizer, starting from session info if necessary"""
...@@ -230,9 +229,7 @@ class HLDestinationStruct: ...@@ -230,9 +229,7 @@ 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
if not dsrp: if not dsrp: dsrp = cls.get_dsrp(dest_rpath, diff_rorp.index)
dsrp = cls.get_dsrp(dest_rpath, diff_rorp.index)
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.index, dsrp) finalizer(dsrp.index, dsrp)
...@@ -261,9 +258,7 @@ class HLDestinationStruct: ...@@ -261,9 +258,7 @@ class HLDestinationStruct:
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 index = indexed_tuple.index
if not dsrp: if not dsrp: dsrp = cls.get_dsrp(dest_rpath, index)
dsrp = cls.get_dsrp(dest_rpath, index)
DestructiveStepping.initialize(dsrp, None)
if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None
ITR(index, diff_rorp, dsrp) ITR(index, diff_rorp, dsrp)
finalizer(index, dsrp) finalizer(index, dsrp)
...@@ -283,7 +278,7 @@ class HLDestinationStruct: ...@@ -283,7 +278,7 @@ class HLDestinationStruct:
def check_skip_error(cls, thunk, dsrp): def check_skip_error(cls, thunk, dsrp):
"""Run thunk, catch certain errors skip files""" """Run thunk, catch certain errors skip files"""
try: return thunk() try: return thunk()
except (IOError, OSError, SkipFileException), exp: except (IOError, OSError, SkipFileException, DSRPPermError), exp:
Log.exception() Log.exception()
if (not isinstance(exp, IOError) or if (not isinstance(exp, IOError) or
(isinstance(exp, IOError) and (isinstance(exp, IOError) and
......
...@@ -87,8 +87,7 @@ class Restore: ...@@ -87,8 +87,7 @@ class Restore:
select_result = Globals.select_mirror.Select(target) select_result = Globals.select_mirror.Select(target)
if select_result == 0: return if select_result == 0: return
if mirrorrp and (not Globals.select_source.Select(mirrorrp) or if mirrorrp and not Globals.select_source.Select(mirrorrp):
DestructiveStepping.initialize(mirrorrp, None)):
mirrorrp = None mirrorrp = None
rcd = RestoreCombinedData(rid, mirrorrp, target) rcd = RestoreCombinedData(rid, mirrorrp, target)
......
...@@ -106,9 +106,8 @@ class Select: ...@@ -106,9 +106,8 @@ class Select:
""" """
s = sel_func(dsrpath) s = sel_func(dsrpath)
if not s or DestructiveStepping.initialize(dsrpath, self.source): if s === 0: return
return elif s == 1: # File is included
if s == 1: # File is included
yield dsrpath yield dsrpath
if dsrpath.isdir(): if dsrpath.isdir():
for dsrp in self.iterate_in_dir(dsrpath, rec_func, sel_func): for dsrp in self.iterate_in_dir(dsrpath, rec_func, sel_func):
...@@ -131,7 +130,6 @@ class Select: ...@@ -131,7 +130,6 @@ class Select:
def iterate_starting_from(self, dsrpath, rec_func, sel_func): def iterate_starting_from(self, dsrpath, rec_func, sel_func):
"""Like Iterate, but only yield indicies > self.starting_index""" """Like Iterate, but only yield indicies > self.starting_index"""
if DestructiveStepping.initialize(dsrpath, self.source): return
if dsrpath.index > self.starting_index: # past starting_index if dsrpath.index > self.starting_index: # past starting_index
for dsrp in self.Iterate(dsrpath, self.Iterate, sel_func): for dsrp in self.Iterate(dsrpath, self.Iterate, sel_func):
yield dsrp yield dsrp
......
...@@ -6,7 +6,7 @@ execfile("rorpiter.py") ...@@ -6,7 +6,7 @@ execfile("rorpiter.py")
# destructive-stepping - Deal with side effects from traversing trees # destructive-stepping - Deal with side effects from traversing trees
# #
class DSRPathError(Exception): class DSRPPermError(Exception):
"""Exception used when a DSRPath can't get sufficient permissions""" """Exception used when a DSRPath can't get sufficient permissions"""
pass pass
...@@ -85,7 +85,7 @@ class DSRPath(RPath): ...@@ -85,7 +85,7 @@ class DSRPath(RPath):
def warn(self, err): def warn(self, err):
Log("Received error '%s' when dealing with file %s, skipping..." Log("Received error '%s' when dealing with file %s, skipping..."
% (err, self.path), 1) % (err, self.path), 1)
raise DSRPathError(self.path) raise DSRPermError(self.path)
def __getstate__(self): def __getstate__(self):
"""Return picklable state. See RPath __getstate__.""" """Return picklable state. See RPath __getstate__."""
......
...@@ -134,7 +134,7 @@ class HLDestinationStruct: ...@@ -134,7 +134,7 @@ class HLDestinationStruct:
cls._session_info = session_info cls._session_info = session_info
def iterate_from(cls): def iterate_from(cls):
"""Supply more arguments to DestructiveStepping.Iterate_from""" """Return selection iterator to iterate all the mirror files"""
if cls._session_info is None: Globals.select_mirror.set_iter() if cls._session_info is None: Globals.select_mirror.set_iter()
else: Globals.select_mirror.set_iter(cls._session_info.last_index) else: Globals.select_mirror.set_iter(cls._session_info.last_index)
return Globals.select_mirror return Globals.select_mirror
...@@ -203,9 +203,8 @@ class HLDestinationStruct: ...@@ -203,9 +203,8 @@ class HLDestinationStruct:
def get_dsrp(cls, dest_rpath, index): def get_dsrp(cls, dest_rpath, index):
"""Return initialized dsrp based on dest_rpath with given index""" """Return initialized dsrp based on dest_rpath with given index"""
dsrp = DSRPath(dest_rpath.conn, dest_rpath.base, index) return DSRPath(source = None, dest_rpath.conn,
DestructiveStepping.initialize(dsrp, None) dest_rpath.base, index)
return dsrp
def get_finalizer(cls): def get_finalizer(cls):
"""Return finalizer, starting from session info if necessary""" """Return finalizer, starting from session info if necessary"""
...@@ -230,9 +229,7 @@ class HLDestinationStruct: ...@@ -230,9 +229,7 @@ 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
if not dsrp: if not dsrp: dsrp = cls.get_dsrp(dest_rpath, diff_rorp.index)
dsrp = cls.get_dsrp(dest_rpath, diff_rorp.index)
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.index, dsrp) finalizer(dsrp.index, dsrp)
...@@ -261,9 +258,7 @@ class HLDestinationStruct: ...@@ -261,9 +258,7 @@ class HLDestinationStruct:
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 index = indexed_tuple.index
if not dsrp: if not dsrp: dsrp = cls.get_dsrp(dest_rpath, index)
dsrp = cls.get_dsrp(dest_rpath, index)
DestructiveStepping.initialize(dsrp, None)
if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None if diff_rorp and diff_rorp.isplaceholder(): diff_rorp = None
ITR(index, diff_rorp, dsrp) ITR(index, diff_rorp, dsrp)
finalizer(index, dsrp) finalizer(index, dsrp)
...@@ -283,7 +278,7 @@ class HLDestinationStruct: ...@@ -283,7 +278,7 @@ class HLDestinationStruct:
def check_skip_error(cls, thunk, dsrp): def check_skip_error(cls, thunk, dsrp):
"""Run thunk, catch certain errors skip files""" """Run thunk, catch certain errors skip files"""
try: return thunk() try: return thunk()
except (IOError, OSError, SkipFileException), exp: except (IOError, OSError, SkipFileException, DSRPPermError), exp:
Log.exception() Log.exception()
if (not isinstance(exp, IOError) or if (not isinstance(exp, IOError) or
(isinstance(exp, IOError) and (isinstance(exp, IOError) and
......
...@@ -87,8 +87,7 @@ class Restore: ...@@ -87,8 +87,7 @@ class Restore:
select_result = Globals.select_mirror.Select(target) select_result = Globals.select_mirror.Select(target)
if select_result == 0: return if select_result == 0: return
if mirrorrp and (not Globals.select_source.Select(mirrorrp) or if mirrorrp and not Globals.select_source.Select(mirrorrp):
DestructiveStepping.initialize(mirrorrp, None)):
mirrorrp = None mirrorrp = None
rcd = RestoreCombinedData(rid, mirrorrp, target) rcd = RestoreCombinedData(rid, mirrorrp, target)
......
...@@ -106,9 +106,8 @@ class Select: ...@@ -106,9 +106,8 @@ class Select:
""" """
s = sel_func(dsrpath) s = sel_func(dsrpath)
if not s or DestructiveStepping.initialize(dsrpath, self.source): if s === 0: return
return elif s == 1: # File is included
if s == 1: # File is included
yield dsrpath yield dsrpath
if dsrpath.isdir(): if dsrpath.isdir():
for dsrp in self.iterate_in_dir(dsrpath, rec_func, sel_func): for dsrp in self.iterate_in_dir(dsrpath, rec_func, sel_func):
...@@ -131,7 +130,6 @@ class Select: ...@@ -131,7 +130,6 @@ class Select:
def iterate_starting_from(self, dsrpath, rec_func, sel_func): def iterate_starting_from(self, dsrpath, rec_func, sel_func):
"""Like Iterate, but only yield indicies > self.starting_index""" """Like Iterate, but only yield indicies > self.starting_index"""
if DestructiveStepping.initialize(dsrpath, self.source): return
if dsrpath.index > self.starting_index: # past starting_index if dsrpath.index > self.starting_index: # past starting_index
for dsrp in self.Iterate(dsrpath, self.Iterate, sel_func): for dsrp in self.Iterate(dsrpath, self.Iterate, sel_func):
yield dsrp yield dsrp
......
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