mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove code to reset temp folder permissions on windows
Being unable to chdir ot the temp folder is going to break a lot of things, so that workaround would not really help anyway. Also port ptempfile to use unicode_literals
This commit is contained in:
parent
ed42a7c1b6
commit
3e68346e4e
@ -437,27 +437,19 @@ def fit_image(width, height, pwidth, pheight):
|
||||
|
||||
class CurrentDir(object):
|
||||
|
||||
def __init__(self, path, workaround_temp_folder_permissions=False):
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
self.cwd = None
|
||||
self.workaround_temp_folder_permissions = workaround_temp_folder_permissions
|
||||
|
||||
def __enter__(self, *args):
|
||||
self.cwd = os.getcwdu()
|
||||
try:
|
||||
os.chdir(self.path)
|
||||
except OSError:
|
||||
if not self.workaround_temp_folder_permissions:
|
||||
raise
|
||||
from calibre.ptempfile import reset_temp_folder_permissions
|
||||
reset_temp_folder_permissions()
|
||||
os.chdir(self.path)
|
||||
return self.cwd
|
||||
|
||||
def __exit__(self, *args):
|
||||
try:
|
||||
os.chdir(self.cwd)
|
||||
except:
|
||||
except EnvironmentError:
|
||||
# The previous CWD no longer exists
|
||||
pass
|
||||
|
||||
|
@ -237,7 +237,7 @@ class InputFormatPlugin(Plugin):
|
||||
# In case stdout is broken
|
||||
pass
|
||||
|
||||
with CurrentDir(output_dir, workaround_temp_folder_permissions=True):
|
||||
with CurrentDir(output_dir):
|
||||
for x in os.listdir('.'):
|
||||
shutil.rmtree(x) if os.path.isdir(x) else os.remove(x)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from __future__ import with_statement
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
"""
|
||||
@ -9,7 +9,7 @@ import tempfile, os, atexit
|
||||
from polyglot.builtins import map
|
||||
|
||||
from calibre.constants import (__version__, __appname__, filesystem_encoding,
|
||||
get_unicode_windows_env_var, iswindows, get_windows_temp_path, isosx)
|
||||
get_unicode_windows_env_var, iswindows, get_windows_temp_path, isosx, ispy3)
|
||||
|
||||
|
||||
def cleanup(path):
|
||||
@ -59,20 +59,6 @@ def app_prefix(prefix):
|
||||
return '%s_%s_%s'%(__appname__, __version__, prefix)
|
||||
|
||||
|
||||
def reset_temp_folder_permissions():
|
||||
# There are some broken windows installs where the permissions for the temp
|
||||
# folder are set to not be executable, which means chdir() into temp
|
||||
# folders fails. Try to fix that by resetting the permissions on the temp
|
||||
# folder.
|
||||
global _base_dir
|
||||
if iswindows and _base_dir:
|
||||
import subprocess
|
||||
from calibre import prints
|
||||
parent = os.path.dirname(_base_dir)
|
||||
retcode = subprocess.Popen(['icacls.exe', parent, '/reset', '/Q', '/T']).wait()
|
||||
prints('Trying to reset permissions of temp folder', parent, 'return code:', retcode)
|
||||
|
||||
|
||||
_osx_cache_dir = None
|
||||
|
||||
|
||||
@ -279,6 +265,10 @@ class SpooledTemporaryFile(tempfile.SpooledTemporaryFile):
|
||||
suffix = ''
|
||||
if dir is None:
|
||||
dir = base_dir()
|
||||
if ispy3:
|
||||
tempfile.SpooledTemporaryFile.__init__(self, max_size=max_size,
|
||||
suffix=suffix, prefix=prefix, dir=dir, mode=mode)
|
||||
else:
|
||||
tempfile.SpooledTemporaryFile.__init__(self, max_size=max_size,
|
||||
suffix=suffix, prefix=prefix, dir=dir, mode=mode,
|
||||
bufsize=bufsize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user