comparison hgext/largefiles/lfutil.py @ 44379:ca82929e433d

lfutil: provide a hint if the largefiles/lfs cache path cannot be determined A coworker hit this error using an LFS repo in a stripped down environment, and didn't know how to resolve it. The final conditional is a bit fast and loose, but there is currently no 'posix' test in hghave, and it doesn't seem like it's worth adding for this since I think Windows is the only non-POSIX platform we run tests on. Differential Revision: https://phab.mercurial-scm.org/D8145
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 24 Feb 2020 14:52:46 -0500
parents 2d49482d0dd4
children 89a2afe31e82
comparison
equal deleted inserted replaced
44376:56f089e40c5a 44379:ca82929e433d
90 def _usercachedir(ui, name=longname): 90 def _usercachedir(ui, name=longname):
91 '''Return the location of the "global" largefiles cache.''' 91 '''Return the location of the "global" largefiles cache.'''
92 path = ui.configpath(name, b'usercache') 92 path = ui.configpath(name, b'usercache')
93 if path: 93 if path:
94 return path 94 return path
95
96 hint = None
97
95 if pycompat.iswindows: 98 if pycompat.iswindows:
96 appdata = encoding.environ.get( 99 appdata = encoding.environ.get(
97 b'LOCALAPPDATA', encoding.environ.get(b'APPDATA') 100 b'LOCALAPPDATA', encoding.environ.get(b'APPDATA')
98 ) 101 )
99 if appdata: 102 if appdata:
100 return os.path.join(appdata, name) 103 return os.path.join(appdata, name)
104
105 hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
106 b"LOCALAPPDATA",
107 b"APPDATA",
108 name,
109 )
101 elif pycompat.isdarwin: 110 elif pycompat.isdarwin:
102 home = encoding.environ.get(b'HOME') 111 home = encoding.environ.get(b'HOME')
103 if home: 112 if home:
104 return os.path.join(home, b'Library', b'Caches', name) 113 return os.path.join(home, b'Library', b'Caches', name)
114
115 hint = _(b"define %s in the environment, or set %s.usercache") % (
116 b"HOME",
117 name,
118 )
105 elif pycompat.isposix: 119 elif pycompat.isposix:
106 path = encoding.environ.get(b'XDG_CACHE_HOME') 120 path = encoding.environ.get(b'XDG_CACHE_HOME')
107 if path: 121 if path:
108 return os.path.join(path, name) 122 return os.path.join(path, name)
109 home = encoding.environ.get(b'HOME') 123 home = encoding.environ.get(b'HOME')
110 if home: 124 if home:
111 return os.path.join(home, b'.cache', name) 125 return os.path.join(home, b'.cache', name)
126
127 hint = _(b"define %s or %s in the environment, or set %s.usercache") % (
128 b"XDG_CACHE_HOME",
129 b"HOME",
130 name,
131 )
112 else: 132 else:
113 raise error.Abort( 133 raise error.Abort(
114 _(b'unknown operating system: %s\n') % pycompat.osname 134 _(b'unknown operating system: %s\n') % pycompat.osname
115 ) 135 )
116 raise error.Abort(_(b'unknown %s usercache location') % name) 136
137 raise error.Abort(_(b'unknown %s usercache location') % name, hint=hint)
117 138
118 139
119 def inusercache(ui, hash): 140 def inusercache(ui, hash):
120 path = usercachepath(ui, hash) 141 path = usercachepath(ui, hash)
121 return os.path.exists(path) 142 return os.path.exists(path)