def get_one_sig(cls, dest_base_rpath, index, src_rorp, dest_rorp): """Return a signature given source and destination rorps""" if (Globals.preserve_hardlinks and src_rorp and Hardlink.islinked(src_rorp)): dest_sig = rpath.RORPath(index) dest_sig.flaglinked(Hardlink.get_link_index(src_rorp)) elif dest_rorp: dest_sig = dest_rorp.getRORPath() if dest_rorp.isreg(): dest_rp = longname.get_mirror_rp(dest_base_rpath, dest_rorp) sig_fp = cls.get_one_sig_fp(dest_rp) if sig_fp is None: return None dest_sig.setfile(sig_fp) else: dest_sig = rpath.RORPath(index) return dest_sig
def get_diffiter(self, new_iter, old_iter): """Iterate meta diffs of new_iter -> old_iter""" for new_rorp, old_rorp in rorpiter.Collate2Iters(new_iter, old_iter): if not old_rorp: yield rpath.RORPath(new_rorp.index) elif not new_rorp or new_rorp.data != old_rorp.data: # exact compare here, can't use == on rorps yield old_rorp
def get_diffs(cls, dest_sigiter): """Return diffs of any files with signature in dest_sigiter""" source_rps = cls._source_select error_handler = robust.get_error_handler("ListError") def attach_snapshot(diff_rorp, src_rp): """Attach file of snapshot to diff_rorp, w/ error checking""" fileobj = robust.check_common_error(error_handler, rpath.RPath.open, (src_rp, "rb")) if fileobj: diff_rorp.setfile(hash.FileWrapper(fileobj)) else: diff_rorp.zero() diff_rorp.set_attached_filetype('snapshot') def attach_diff(diff_rorp, src_rp, dest_sig): """Attach file of diff to diff_rorp, w/ error checking""" fileobj = robust.check_common_error(error_handler, Rdiff.get_delta_sigrp_hash, (dest_sig, src_rp)) if fileobj: diff_rorp.setfile(fileobj) diff_rorp.set_attached_filetype('diff') else: diff_rorp.zero() diff_rorp.set_attached_filetype('snapshot') for dest_sig in dest_sigiter: if dest_sig is iterfile.MiscIterFlushRepeat: yield iterfile.MiscIterFlush # Flush buffer when get_sigs does continue src_rp = (source_rps.get(dest_sig.index) or rpath.RORPath(dest_sig.index)) diff_rorp = src_rp.getRORPath() if dest_sig.isflaglinked(): diff_rorp.flaglinked(dest_sig.get_link_flag()) elif src_rp.isreg(): reset_perms = False if (Globals.process_uid != 0 and not src_rp.readable() and src_rp.isowner()): reset_perms = True src_rp.chmod(0400 | src_rp.getperms()) if dest_sig.isreg(): attach_diff(diff_rorp, src_rp, dest_sig) else: attach_snapshot(diff_rorp, src_rp) if reset_perms: src_rp.chmod(src_rp.getperms() & ~0400) else: dest_sig.close_if_necessary() diff_rorp.set_attached_filetype('snapshot') yield diff_rorp
def Record2RORP(record_string): """Given record_string, return RORPath For speed reasons, write the RORPath data dictionary directly instead of calling rorpath functions. Profiling has shown this to be a time critical function. """ data_dict = {} for field, data in line_parsing_regexp.findall(record_string): if field == "File": index = quoted_filename_to_index(data) elif field == "Type": if data == "None": data_dict['type'] = None else: data_dict['type'] = data elif field == "Size": data_dict['size'] = long(data) elif field == "ResourceFork": if data == "None": data_dict['resourcefork'] = "" else: data_dict['resourcefork'] = binascii.unhexlify(data) elif field == "CarbonFile": if data == "None": data_dict['carbonfile'] = None else: data_dict['carbonfile'] = string2carbonfile(data) elif field == "SHA1Digest": data_dict['sha1'] = data elif field == "NumHardLinks": data_dict['nlink'] = int(data) elif field == "Inode": data_dict['inode'] = long(data) elif field == "DeviceLoc": data_dict['devloc'] = long(data) elif field == "SymData": data_dict['linkname'] = unquote_path(data) elif field == "DeviceNum": devchar, major_str, minor_str = data.split(" ") data_dict['devnums'] = (devchar, int(major_str), int(minor_str)) elif field == "ModTime": data_dict['mtime'] = long(data) elif field == "Uid": data_dict['uid'] = int(data) elif field == "Gid": data_dict['gid'] = int(data) elif field == "Uname": if data == ":" or data == 'None': data_dict['uname'] = None else: data_dict['uname'] = data elif field == "Gname": if data == ':' or data == 'None': data_dict['gname'] = None else: data_dict['gname'] = data elif field == "Permissions": data_dict['perms'] = int(data) elif field == "AlternateMirrorName": data_dict['mirrorname'] = data elif field == "AlternateIncrementName": data_dict['incname'] = data else: log.Log("Unknown field in line '%s %s'" % (field, data), 2) return rpath.RORPath(index, data_dict)
def attach_files(cls, src_iter, mirror_rp, inc_rp, compare_time): """Attach data to all the files that need checking Return an iterator of repo rorps that includes all the files that may have changed, and has the fileobj set on all rorps that need it. """ repo_iter = cls.init_and_get_iter(mirror_rp, inc_rp, compare_time) base_index = cls.mirror_base.index for src_rorp, mir_rorp in rorpiter.Collate2Iters(src_iter, repo_iter): index = src_rorp and src_rorp.index or mir_rorp.index if src_rorp and mir_rorp: if not src_rorp.isreg() and src_rorp == mir_rorp: log_success(src_rorp, mir_rorp) continue # They must be equal, nothing else to check if (src_rorp.isreg() and mir_rorp.isreg() and src_rorp.getsize() == mir_rorp.getsize()): fp = cls.rf_cache.get_fp(base_index + index, mir_rorp) mir_rorp.setfile(fp) mir_rorp.set_attached_filetype('snapshot') if mir_rorp: yield mir_rorp else: yield rpath.RORPath(index) # indicate deleted mir_rorp
def set_metadata_rorp(self, metadata_rorp): """Set self.metadata_rorp, creating empty if given None""" if metadata_rorp: self.metadata_rorp = metadata_rorp else: self.metadata_rorp = rpath.RORPath(self.index)