unsupported
  C   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þ\mçVnP¸VDHÓ@þÂ„o¾Á_ŠI|¥�+Wé3ž¯ÁÀ ?÷     # Copyright 2009-2010 Gregory P. Ward
# Copyright 2009-2010 Intelerad Medical Systems Incorporated
# Copyright 2010-2011 Fog Creek Software
# Copyright 2010-2011 Unity Technologies
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

'''largefiles utility code: must not import other modules in this package.'''

import contextlib
import copy
import os
import stat

from mercurial.i18n import _
from mercurial.node import hex
from mercurial.pycompat import open

from mercurial import (
    dirstate,
    encoding,
    error,
    httpconnection,
    match as matchmod,
    pycompat,
    requirements,
    scmutil,
    sparse,
    util,
    vfs as vfsmod,
)
from mercurial.utils import hashutil
from mercurial.dirstateutils import timestamp

shortname = b'.hglf'
shortnameslash = shortname + b'/'
longname = b'largefiles'

# -- Private worker functions ------------------------------------------


@contextlib.contextmanager
def lfstatus(repo, value=True):
    oldvalue = getattr(repo, 'lfstatus', False)
    repo.lfstatus = value
    try:
        yield
    finally:
        repo.lfstatus = oldvalue


def getminsize(ui, assumelfiles, opt, default=10):
    lfsize = opt
    if not lfsize and assumelfiles:
        lfsize = ui.config(longname, b'minsize', default=default)
    if lfsize:
        try:
            lfsize = float(lfsize)
        except ValueError:
            raise error.Abort(
                _(b'largefiles: size must be number (not %s)\n') % lfsize
            )
    if lfsize is None:
        raise error.Abort(_(b'minimum size for largefiles must be specified'))
    return lfsize


def link(src, dest):
    """Try to create hardlink - if that fails, efficiently make a copy."""
    util.makedirs(os.path.dirname(dest))
    try:
        util.oslink(src, dest)
    except OSError:
        # if hardlinks fail, fallback on atomic copy
        with open(src, b'rb') as srcf, util.atomictempfile(dest) as dstf:
            for chunk in util.filechunkiter(srcf):
                dstf.write(chunk)
        os.chmod(dest, os.stat(src).st_mode)


def usercachepath(ui, hash):
    """Return the correct location in the "global" largefiles cache for a file
    with the given hash.
    This cache is used for sharing of largefiles across repositories - both
    to preserve download bandwidth and storage space."""
    return os.path.join(_usercachedir(ui), hash)


def _usercachedir(ui, name=longname):
    '''Return the location of the "global" largefiles cache.'''
    path = ui.configpath(name, b'usercache')
    if path:
        return path

    hint = None

    if pycompat.iswindows:
        appdata = encoding.environ.get(
            b'LOCALAPPDATA', encoding.environ.get(b'APPDATA')
        )
        if appdata:
            return os.path.join(appdata, name)

        hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
            b"LOCALAPPDATA",
            b"APPDATA",
            name,
        )
    elif pycompat.isdarwin:
        home = encoding.environ.get(b'HOME')
        if home:
            return os.path.join(home, b'Library', b'Caches', name)

        hint = _(b"define %s in the environment, or set %s.usercache") % (
            b"HOME",
            name,
        )
    elif pycompat.isposix:
        path = encoding.environ.get(b'XDG_CACHE_HOME')
        if path:
            return os.path.join(path, name)
        home = encoding.environ.get(b'HOME')
        if home:
            return os.path.join(home, b'.cache', name)

        hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
            b"XDG_CACHE_HOME",
            b"HOME",
            name,
        )
    else:
        raise error.Abort(
            _(b'unknown operating system: %s\n') % pycompat.osname
        )

    raise error.Abort(_(b'unknown %s usercache location') % name, hint=hint)


def inusercache(ui, hash):
    path = usercachepath(ui, hash)
    return o