hgext/largefiles/lfutil.py
changeset 28574 7a4e1749cb07
parent 28560 bfbd3f02b442
child 28575 78e4e558fa74
equal deleted inserted replaced
28573:6a42564081cb 28574:7a4e1749cb07
    49             dst.write(chunk)
    49             dst.write(chunk)
    50         dst.close()
    50         dst.close()
    51         os.chmod(dest, os.stat(src).st_mode)
    51         os.chmod(dest, os.stat(src).st_mode)
    52 
    52 
    53 def usercachepath(ui, hash):
    53 def usercachepath(ui, hash):
       
    54     '''Return the correct location in the "global" largefiles cache for a file
       
    55     with the given hash.
       
    56     This cache is used for sharing of largefiles across repositories - both
       
    57     to preserve download bandwidth and storage space.'''
       
    58     path = _usercachedir(ui)
       
    59     if path:
       
    60         return os.path.join(path, hash)
       
    61     return None
       
    62 
       
    63 def _usercachedir(ui):
       
    64     '''Return the location of the "global" largefiles cache.'''
    54     path = ui.configpath(longname, 'usercache', None)
    65     path = ui.configpath(longname, 'usercache', None)
    55     if path:
    66     if path:
    56         path = os.path.join(path, hash)
    67         return path
    57     else:
    68     if os.name == 'nt':
    58         if os.name == 'nt':
    69         appdata = os.getenv('LOCALAPPDATA', os.getenv('APPDATA'))
    59             appdata = os.getenv('LOCALAPPDATA', os.getenv('APPDATA'))
    70         if appdata:
    60             if appdata:
    71             return os.path.join(appdata, longname)
    61                 path = os.path.join(appdata, longname, hash)
    72     elif platform.system() == 'Darwin':
    62         elif platform.system() == 'Darwin':
    73         home = os.getenv('HOME')
    63             home = os.getenv('HOME')
    74         if home:
    64             if home:
    75             return os.path.join(home, 'Library', 'Caches', longname)
    65                 path = os.path.join(home, 'Library', 'Caches',
    76     elif os.name == 'posix':
    66                                     longname, hash)
    77         path = os.getenv('XDG_CACHE_HOME')
    67         elif os.name == 'posix':
    78         if path:
    68             path = os.getenv('XDG_CACHE_HOME')
    79             return os.path.join(path, longname)
    69             if path:
    80         home = os.getenv('HOME')
    70                 path = os.path.join(path, longname, hash)
    81         if home:
    71             else:
    82             return os.path.join(home, '.cache', longname)
    72                 home = os.getenv('HOME')
    83     else:
    73                 if home:
    84         raise error.Abort(_('unknown operating system: %s\n') % os.name)
    74                     path = os.path.join(home, '.cache', longname, hash)
    85     return None
    75         else:
       
    76             raise error.Abort(_('unknown operating system: %s\n') % os.name)
       
    77     return path
       
    78 
    86 
    79 def inusercache(ui, hash):
    87 def inusercache(ui, hash):
    80     path = usercachepath(ui, hash)
    88     path = usercachepath(ui, hash)
    81     return path and os.path.exists(path)
    89     return path and os.path.exists(path)
    82 
    90