Esempio n. 1
0
def savepinnednodes(repo, newpin, newunpin, fullargs):
    # take a narrowed lock so it does not affect repo lock
    with extutil.flock(repo.svfs.join("obsinhibit.lock"), "save pinned nodes"):
        orignodes = loadpinnednodes(repo)
        nodes = set(orignodes)
        nodes |= set(newpin)
        nodes -= set(newunpin)
        with util.atomictempfile(repo.svfs.join("obsinhibit")) as f:
            f.write("".join(nodes))

        desc = lambda s: [short(n) for n in s]
        repo.ui.log(
            "pinnednodes",
            "pinnednodes: %r newpin=%r newunpin=%r "
            "before=%r after=%r\n",
            fullargs,
            desc(newpin),
            desc(newunpin),
            desc(orignodes),
            desc(nodes),
        )
Esempio n. 2
0
def _loadfileblob(repo, path, node):
    usesimplecache = repo.ui.configbool("remotefilelog", "simplecacheserverstore")
    cachepath = repo.ui.config("remotefilelog", "servercachepath")
    if cachepath and usesimplecache:
        raise error.Abort(
            "remotefilelog.servercachepath and remotefilelog.simplecacheserverstore can't be both enabled"
        )

    key = os.path.join(path, hex(node))

    # simplecache store for remotefilelogcache
    if usesimplecache:
        try:
            simplecache = extensions.find("simplecache")
        except KeyError:
            raise error.Abort(
                "simplecache extension must be enabled with remotefilelog.simplecacheserverstore enabled"
            )

        # this function doesn't raise exception
        text = simplecache.cacheget(key, trivialserializer, repo.ui)
        if text:
            return text
        else:
            text = readvalue(repo, path, node)
            # this function doesn't raise exception
            simplecache.cacheset(key, text, trivialserializer, repo.ui)
            return text

    # on disk store for remotefilelogcache
    if not cachepath:
        cachepath = os.path.join(repo.path, "remotefilelogcache")

    filecachepath = os.path.join(cachepath, key)
    if not os.path.exists(filecachepath) or os.path.getsize(filecachepath) == 0:
        text = readvalue(repo, path, node)
        # everything should be user & group read/writable
        oldumask = os.umask(0o002)
        try:
            dirname = os.path.dirname(filecachepath)
            if not os.path.exists(dirname):
                try:
                    os.makedirs(dirname)
                except OSError as ex:
                    if ex.errno != errno.EEXIST:
                        raise
            f = None
            try:
                f = util.atomictempfile(filecachepath, "w")
                f.write(text)
            except (IOError, OSError):
                # Don't abort if the user only has permission to read,
                # and not write.
                pass
            finally:
                if f:
                    f.close()
        finally:
            os.umask(oldumask)
    else:
        with util.posixfile(filecachepath, "r") as f:
            text = f.read()
    return text