Commit db3211cb authored by bescoto's avatar bescoto

Fix to backup_warn_if_infinite_regress code


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@524 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 1b47cf8e
...@@ -272,6 +272,7 @@ def Backup(rpin, rpout): ...@@ -272,6 +272,7 @@ def Backup(rpin, rpout):
init_user_group_mapping(rpout.conn) init_user_group_mapping(rpout.conn)
backup_final_init(rpout) backup_final_init(rpout)
backup_set_select(rpin) backup_set_select(rpin)
backup_warn_if_infinite_regress(rpin, rpout)
if prevtime: if prevtime:
rpout.conn.Main.backup_touch_curmirror_local(rpin, rpout) rpout.conn.Main.backup_touch_curmirror_local(rpin, rpout)
Time.setprevtime(prevtime) Time.setprevtime(prevtime)
...@@ -311,7 +312,6 @@ def backup_check_dirs(rpin, rpout): ...@@ -311,7 +312,6 @@ def backup_check_dirs(rpin, rpout):
Log.FatalError("Source directory %s does not exist" % rpin.path) Log.FatalError("Source directory %s does not exist" % rpin.path)
elif not rpin.isdir(): elif not rpin.isdir():
Log.FatalError("Source %s is not a directory" % rpin.path) Log.FatalError("Source %s is not a directory" % rpin.path)
backup_warn_if_infinite_regress(rpin, rpout)
Globals.rbdir = rpout.append_path("rdiff-backup-data") Globals.rbdir = rpout.append_path("rdiff-backup-data")
def backup_set_rbdir(rpin, rpout): def backup_set_rbdir(rpin, rpout):
...@@ -337,14 +337,16 @@ option.""" % rpout.path) ...@@ -337,14 +337,16 @@ option.""" % rpout.path)
def backup_warn_if_infinite_regress(rpin, rpout): def backup_warn_if_infinite_regress(rpin, rpout):
"""Warn user if destination area contained in source area""" """Warn user if destination area contained in source area"""
if rpout.conn is rpin.conn: # it's meaningful to compare paths # Just a few heuristics, we don't have to get every case
if ((len(rpout.path) > len(rpin.path)+1 and if rpout.conn is not rpin.conn: return
rpout.path[:len(rpin.path)] == rpin.path and if len(rpout.path) <= len(rpin.path)+1: return
rpout.path[len(rpin.path)] == '/') or if rpout.path[:len(rpin.path)+1] != rpin.path + '/': return
(rpin.path == "." and rpout.path[0] != '/' and
rpout.path[:2] != '..')): relative_rpout_comps = tuple(rpout.path[len(rpin.path)+1:].split('/'))
# Just a few heuristics, we don't have to get every case relative_rpout = rpin.new_index(relative_rpout_comps)
if Globals.backup_reader.Globals.select_source.Select(rpout): Log( if not Globals.select_mirror.Select(relative_rpout): return
Log(
"""Warning: The destination directory '%s' may be contained in the """Warning: The destination directory '%s' may be contained in the
source directory '%s'. This could cause an infinite regress. You source directory '%s'. This could cause an infinite regress. You
may need to use the --exclude option.""" % (rpout.path, rpin.path), 2) may need to use the --exclude option.""" % (rpout.path, rpin.path), 2)
......
...@@ -71,6 +71,7 @@ class SourceStruct: ...@@ -71,6 +71,7 @@ class SourceStruct:
sel.set_iter() sel.set_iter()
cache_size = Globals.pipeline_max_length * 3 # to and from+leeway cache_size = Globals.pipeline_max_length * 3 # to and from+leeway
cls._source_select = rorpiter.CacheIndexable(sel, cache_size) cls._source_select = rorpiter.CacheIndexable(sel, cache_size)
Globals.set('select_mirror', sel)
def get_source_select(cls): def get_source_select(cls):
"""Return source select iterator, set by set_source_select""" """Return source select iterator, set by set_source_select"""
......
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