Exemplo n.º 1
0
def _hardlink_rorp_eq(src_rorp, dest_rorp):
    """Compare two files for hardlink equality, encompassing being hard-linked,
    having the same hashsum, and the same number of link counts."""
    Hardlink.add_rorp(dest_rorp)
    Hardlink.add_rorp(src_rorp, dest_rorp)
    rorp_eq = Hardlink.rorp_eq(src_rorp, dest_rorp)
    if not src_rorp.isreg() or not dest_rorp.isreg() or src_rorp.getnumlinks() == dest_rorp.getnumlinks() == 1:
        if not rorp_eq:
            Log("Hardlink compare error with when no links exist", 3)
            Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
            Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
            return False
    elif src_rorp.getnumlinks() > 1 and not Hardlink.is_linked(src_rorp):
        if rorp_eq:
            Log("Hardlink compare error with first linked src_rorp and no dest_rorp sha1", 3)
            Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
            Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
            return False
        hash.compute_sha1(dest_rorp)
        rorp_eq = Hardlink.rorp_eq(src_rorp, dest_rorp)
        if src_rorp.getnumlinks() != dest_rorp.getnumlinks():
            if rorp_eq:
                Log("Hardlink compare error with first linked src_rorp, with dest_rorp sha1, and with differing link counts", 3)
                Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
                Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
                return False
        elif not rorp_eq:
            Log("Hardlink compare error with first linked src_rorp, with dest_rorp sha1, and with equal link counts", 3)
            Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
            Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
            return False
    elif src_rorp.getnumlinks() != dest_rorp.getnumlinks():
        if rorp_eq:
            Log("Hardlink compare error with non-first linked src_rorp and with differing link counts", 3)
            Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
            Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
            return False
    elif not rorp_eq:
        Log("Hardlink compare error with non-first linked src_rorp and with equal link counts", 3)
        Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
        Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
        return False
    Hardlink.del_rorp(src_rorp)
    Hardlink.del_rorp(dest_rorp)
    return True
Exemplo n.º 2
0
 def hardlink_rorp_eq(src_rorp, dest_rorp):
     Hardlink.add_rorp(dest_rorp)
     Hardlink.add_rorp(src_rorp, dest_rorp)
     rorp_eq = Hardlink.rorp_eq(src_rorp, dest_rorp)
     if not src_rorp.isreg() or not dest_rorp.isreg() or src_rorp.getnumlinks() == dest_rorp.getnumlinks() == 1:
         if not rorp_eq:
             Log("Hardlink compare error with when no links exist exist", 3)
             Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
             Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
             return 0
     elif src_rorp.getnumlinks() > 1 and not Hardlink.is_linked(src_rorp):
         if rorp_eq:
             Log("Hardlink compare error with first linked src_rorp and no dest_rorp sha1", 3)
             Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
             Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
             return 0
         hash.compute_sha1(dest_rorp)
         rorp_eq = Hardlink.rorp_eq(src_rorp, dest_rorp)
         if src_rorp.getnumlinks() != dest_rorp.getnumlinks():
             if rorp_eq:
                 Log("Hardlink compare error with first linked src_rorp, with dest_rorp sha1, and with differing link counts", 3)
                 Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
                 Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
                 return 0
         elif not rorp_eq:
             Log("Hardlink compare error with first linked src_rorp, with dest_rorp sha1, and with equal link counts", 3)
             Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
             Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
             return 0
     elif src_rorp.getnumlinks() != dest_rorp.getnumlinks():
         if rorp_eq:
             Log("Hardlink compare error with non-first linked src_rorp and with differing link counts", 3)
             Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
             Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
             return 0
     elif not rorp_eq:
         Log("Hardlink compare error with non-first linked src_rorp and with equal link counts", 3)
         Log("%s: %s" % (src_rorp.index, Hardlink._get_inode_key(src_rorp)), 3)
         Log("%s: %s" % (dest_rorp.index, Hardlink._get_inode_key(dest_rorp)), 3)
         return 0
     Hardlink.del_rorp(src_rorp)
     Hardlink.del_rorp(dest_rorp)
     return 1
Exemplo n.º 3
0
 def hashes_changed(src_rp, mir_rorp):
     """Return 0 if their data hashes same, 1 otherwise"""
     verify_sha1 = map_hardlinks.get_hash(mir_rorp)
     if not verify_sha1:
         log.Log("Metadata file has no digest for mirror file {mf}, "
                 "unable to compare.".format(mf=mir_rorp), log.WARNING)
         return 0
     elif (src_rp.getsize() == mir_rorp.getsize()
           and hash.compute_sha1(src_rp) == verify_sha1):
         return 0
     return 1