Example #1
0
def statbfile(repo, proto, sha):
    """statbfile sends '2\n' if the bfile is missing, '1\n' if it has a
    mismatched checksum, or '0\n' if it is in good condition"""
    filename = bfutil.findfile(repo, sha)
    if not filename:
        return '2\n'
    fd = None
    try:
        fd = open(filename, 'rb')
        return bfutil.hexsha1(fd) == sha and '0\n' or '1\n'
    finally:
        if fd:
            fd.close()
Example #2
0
def putbfile(repo, proto, sha):
    """putbfile puts a bfile into a repository's local cache and into the
    system cache."""
    f = None
    proto.redirect()
    try:
        try:
            f = tempfile.NamedTemporaryFile(mode='wb+', prefix='hg-putbfile-')
            proto.getfile(f)
            f.seek(0)
            if sha != bfutil.hexsha1(f):
                return wireproto.pushres(1)
            bfutil.copytocacheabsolute(repo, f.name, sha)
        except IOError:
            repo.ui.warn(
                _('error: could not put received data into bfile store'))
            return wireproto.pushres(1)
    finally:
        if f:
            f.close()

    return wireproto.pushres(0)