##// END OF EJS Templates
Safely encode paths in compress_user...
Sebastiaan Mathot -
Show More
@@ -81,7 +81,8 b" def unquote_filename(name, win32=(sys.platform=='win32')):"
81 81
82 82 def compress_user(path):
83 83 """Reverse of :func:`os.path.expanduser`
84 """
84 """
85 path = py3compat.unicode_to_str(path, sys.getfilesystemencoding())
85 86 home = os.path.expanduser('~')
86 87 if path.startswith(home):
87 88 path = "~" + path[len(home):]
@@ -174,13 +175,13 b' def get_home_dir(require_writable=False):'
174 175 """Return the 'home' directory, as a unicode string.
175 176
176 177 Uses os.path.expanduser('~'), and checks for writability.
177
178
178 179 See stdlib docs for how this is determined.
179 180 $HOME is first priority on *ALL* platforms.
180
181
181 182 Parameters
182 183 ----------
183
184
184 185 require_writable : bool [default: False]
185 186 if True:
186 187 guarantees the return value is a writable directory, otherwise
@@ -193,7 +194,7 b' def get_home_dir(require_writable=False):'
193 194 # Next line will make things work even when /home/ is a symlink to
194 195 # /usr/home as it is on FreeBSD, for example
195 196 homedir = os.path.realpath(homedir)
196
197
197 198 if not _writable_dir(homedir) and os.name == 'nt':
198 199 # expanduser failed, use the registry to get the 'My Documents' folder.
199 200 try:
@@ -209,7 +210,7 b' def get_home_dir(require_writable=False):'
209 210 key.Close()
210 211 except:
211 212 pass
212
213
213 214 if (not require_writable) or _writable_dir(homedir):
214 215 return py3compat.cast_unicode(homedir, fs_encoding)
215 216 else:
@@ -430,10 +431,10 b' def link_or_copy(src, dst):'
430 431
431 432 def ensure_dir_exists(path, mode=0o755):
432 433 """ensure that a directory exists
433
434
434 435 If it doesn't exist, try to create it and protect against a race condition
435 436 if another process is doing the same.
436
437
437 438 The default permissions are 755, which differ from os.makedirs default of 777.
438 439 """
439 440 if not os.path.exists(path):
General Comments 0
You need to be logged in to leave comments. Login now