From 26a6d142dd736feafc347651c22360b5d5574734 Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 2 Jun 2002 20:14:08 +0000 Subject: Added --null-separator, tweaked increment error handling git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@117 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/rdiff_backup/increment.py | 13 ++++++++-- rdiff-backup/rdiff_backup/lazy.py | 2 +- rdiff-backup/rdiff_backup/selection.py | 26 ++++++++++++------- rdiff-backup/rdiff_backup/statistics.py | 46 ++++++++++++++++++++------------- 4 files changed, 56 insertions(+), 31 deletions(-) (limited to 'rdiff-backup/rdiff_backup') diff --git a/rdiff-backup/rdiff_backup/increment.py b/rdiff-backup/rdiff_backup/increment.py index 7aa7009..5836f63 100644 --- a/rdiff-backup/rdiff_backup/increment.py +++ b/rdiff-backup/rdiff_backup/increment.py @@ -219,6 +219,7 @@ class IncrementITR(ErrorITR, StatsITR): # Write updated mirror to temp file so we can compute # reverse diff locally mirror_tf = TempFileManager.new(dsrp) + old_dsrp_tf = TempFileManager.new(dsrp) def init_thunk(): if diff_rorp.isflaglinked(): Hardlink.link_rp(diff_rorp, mirror_tf, dsrp) @@ -226,8 +227,16 @@ class IncrementITR(ErrorITR, StatsITR): mirror_tf).execute() self.incrp = Inc.Increment_action(mirror_tf, dsrp, incpref).execute() - def final(init_val): mirror_tf.rename(dsrp) - def error(exc, ran_init, init_val): mirror_tf.delete() + if dsrp.lstat(): RPathStatic.rename(dsrp, old_dsrp_tf) + mirror_tf.rename(dsrp) + + def final(init_val): old_dsrp_tf.delete() + def error(exc, ran_init, init_val): + if ran_init: old_dsrp_tf.delete() # everything is fine + else: # restore to previous state + if old_dsrp_tf.lstat(): old_dsrp_tf.rename(dsrp) + if self.incrp: self.incrp.delete() + RobustAction(init_thunk, final, error).execute() else: self.incrp = Robust.chain( Inc.Increment_action(diff_rorp, dsrp, incpref), diff --git a/rdiff-backup/rdiff_backup/lazy.py b/rdiff-backup/rdiff_backup/lazy.py index 98a4027..c7d1a52 100644 --- a/rdiff-backup/rdiff_backup/lazy.py +++ b/rdiff-backup/rdiff_backup/lazy.py @@ -54,7 +54,7 @@ class Iter: return None try: i2 = iter2.next() except StopIteration: return 1 - if verbose: print "End when i2 = %s" % i2 + if verbose: print "End when i2 = %s" % (i2,) return None def Or(iter): diff --git a/rdiff-backup/rdiff_backup/selection.py b/rdiff-backup/rdiff_backup/selection.py index 8b87af8..4c003c8 100644 --- a/rdiff-backup/rdiff_backup/selection.py +++ b/rdiff-backup/rdiff_backup/selection.py @@ -281,19 +281,25 @@ probably isn't what you meant.""" % def filelist_read(self, filelist_fp, include, filelist_name): """Read filelist from fp, return (tuplelist, something_excluded)""" + prefix_warnings = [0] + def incr_warnings(exc): + """Warn if prefix is incorrect""" + prefix_warnings[0] += 1 + if prefix_warnings[0] < 6: + Log("Warning: file specification '%s' in filelist %s\n" + "doesn't start with correct prefix %s. Ignoring." % + (exc, filelist_name, self.prefix), 2) + if prefix_warnings[0] == 5: + Log("Future prefix errors will not be logged.", 2) + something_excluded, tuple_list = None, [] - prefix_warnings = 0 - for line in filelist_fp: - if not line.strip(): continue # skip blanks + separator = Globals.null_separator and "\0" or "\n" + for line in filelist_fp.read().split(separator): + if not line: continue # skip blanks try: tuple = self.filelist_parse_line(line, include) except FilePrefixError, exc: - prefix_warnings += 1 - if prefix_warnings < 6: - Log("Warning: file specification %s in filelist %s\n" - "doesn't start with correct prefix %s, ignoring." % - (exc, filelist_name, self.prefix), 2) - if prefix_warnings == 5: - Log("Future prefix errors will not be logged.", 2) + incr_warnings(exc) + continue tuple_list.append(tuple) if not tuple[1]: something_excluded = 1 if filelist_fp.close(): diff --git a/rdiff-backup/rdiff_backup/statistics.py b/rdiff-backup/rdiff_backup/statistics.py index 7f99c31..4043f16 100644 --- a/rdiff-backup/rdiff_backup/statistics.py +++ b/rdiff-backup/rdiff_backup/statistics.py @@ -56,15 +56,17 @@ class StatsObj: """Add 1 to value of attribute""" self.__dict__[attr] = self.get_stat(attr) + 1 - def get_stats_line(self, index): + def get_stats_line(self, index, use_repr = 1): """Return one line abbreviated version of full stats string""" file_attrs = map(lambda attr: str(self.get_stat(attr)), self.stat_file_attrs) if not index: filename = "." else: - # use repr to quote newlines in relative filename, then - # take of leading and trailing quote. - filename = repr(apply(os.path.join, index))[1:-1] + filename = apply(os.path.join, index) + if use_repr: + # use repr to quote newlines in relative filename, then + # take of leading and trailing quote. + filename = repr(filename)[1:-1] return " ".join([filename,] + file_attrs) def set_stats_from_line(self, line): @@ -227,39 +229,45 @@ class StatsITR(IterTreeReducer, StatsObj): """ if mirror_dsrp.lstat(): self.mirror_base_exists = 1 - self.mirror_base_size = mirror_dsrp.getsize() + self.mirror_base_size = self.stats_getsize(mirror_dsrp) else: self.mirror_base_exists = None + def stats_getsize(self, rp): + """Return size of rp, with error checking""" + try: return rp.getsize() + except KeyError: return 0 + def end_stats(self, diff_rorp, mirror_dsrp, inc_rp = None): """Set various statistics after mirror processed""" if mirror_dsrp.lstat(): + source_size = self.stats_getsize(mirror_dsrp) self.SourceFiles += 1 - self.SourceFileSize += mirror_dsrp.getsize() + self.SourceFileSize += source_size if self.mirror_base_exists: self.MirrorFiles += 1 self.MirrorFileSize += self.mirror_base_size if diff_rorp: # otherwise no change self.ChangedFiles += 1 - self.ChangedSourceSize += mirror_dsrp.getsize() + self.ChangedSourceSize += source_size self.ChangedMirrorSize += self.mirror_base_size - if inc_rp: - self.IncrementFiles += 1 - self.IncrementFileSize += inc_rp.getsize() + self.stats_incr_incfiles(inc_rp) else: # new file was created self.NewFiles += 1 - self.NewFileSize += mirror_dsrp.getsize() - if inc_rp: - self.IncrementFiles += 1 - self.IncrementFileSize += inc_rp.getsize() + self.NewFileSize += source_size + self.stats_incr_incfiles(inc_rp) else: if self.mirror_base_exists: # file was deleted from mirror self.MirrorFiles += 1 self.MirrorFileSize += self.mirror_base_size self.DeletedFiles += 1 self.DeletedFileSize += self.mirror_base_size - if inc_rp: - self.IncrementFiles += 1 - self.IncrementFileSize += inc_rp.getsize() + self.stats_incr_incfiles(inc_rp) + + def stats_incr_incfiles(self, inc_rp): + """Increment IncrementFile statistics""" + if inc_rp: + self.IncrementFiles += 1 + self.IncrementFileSize += self.stats_getsize(inc_rp) def add_file_stats(self, subinstance): """Add all file statistics from subinstance to current totals""" @@ -304,7 +312,9 @@ class Stats: def write_dir_stats_line(cls, statobj, index): """Write info from statobj about rpath to statistics file""" - cls._dir_stats_fp.write(statobj.get_stats_line(index) +"\n") + if Globals.null_separator: + cls._dir_stats_fp.write(statobj.get_stats_line(index, None) + "\0") + else: cls._dir_stats_fp.write(statobj.get_stats_line(index) + "\n") def close_dir_stats_file(cls): """Close directory statistics file if its open""" -- cgit v1.2.1