mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Windows: If creating a bytestring temp dir fails, create a unicode one and hope the rest of calibre can handle it
This commit is contained in:
parent
87efd04aa1
commit
224968f239
@ -39,8 +39,20 @@ def base_dir():
|
|||||||
if td and os.path.exists(td):
|
if td and os.path.exists(td):
|
||||||
_base_dir = td
|
_base_dir = td
|
||||||
else:
|
else:
|
||||||
_base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__,
|
base = os.environ.get('CALIBRE_TEMP_DIR', None)
|
||||||
__version__), dir=os.environ.get('CALIBRE_TEMP_DIR', None))
|
prefix = u'%s_%s_tmp_'%(__appname__, __version__)
|
||||||
|
try:
|
||||||
|
# First try an ascii path as that is what was done historically
|
||||||
|
# and we dont want to break working code
|
||||||
|
# _base_dir will be a bytestring
|
||||||
|
_base_dir = tempfile.mkdtemp(prefix=prefix.encode('ascii'), dir=base)
|
||||||
|
except:
|
||||||
|
# Failed to create tempdir (probably localized windows)
|
||||||
|
# Try unicode. This means that all temp paths created by this
|
||||||
|
# module will be unicode, this may cause problems elsewhere, if
|
||||||
|
# so, hopefully people will open tickets and they can be fixed.
|
||||||
|
_base_dir = tempfile.mkdtemp(prefix=prefix, dir=base)
|
||||||
|
|
||||||
atexit.register(remove_dir, _base_dir)
|
atexit.register(remove_dir, _base_dir)
|
||||||
return _base_dir
|
return _base_dir
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user