mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Try to automatically fix temp folder permissions on windows
This commit is contained in:
parent
fae8aa1405
commit
3a9fa00032
@ -790,7 +790,9 @@ folder.
|
||||
Some users have reported that running the following command in an Administrator
|
||||
Command Prompt fixed their permissions. To get an Administrator Command Prompt
|
||||
search for cmd.exe in the start menu, then right click on the command prompt
|
||||
entry and select Run as Administrator::
|
||||
entry and select Run as Administrator. At the command prompt type the following
|
||||
command and press Enter::
|
||||
|
||||
icacls "%appdata%\..\Local\Temp" /reset /T
|
||||
|
||||
Alternately, you can run calibre as Administrator, but doing so will cause
|
||||
|
@ -436,13 +436,21 @@ def fit_image(width, height, pwidth, pheight):
|
||||
|
||||
class CurrentDir(object):
|
||||
|
||||
def __init__(self, path):
|
||||
def __init__(self, path, workaround_temp_folder_permissions=False):
|
||||
self.path = path
|
||||
self.cwd = None
|
||||
self.workaround_temp_folder_permissions = workaround_temp_folder_permissions
|
||||
|
||||
def __enter__(self, *args):
|
||||
self.cwd = os.getcwdu()
|
||||
os.chdir(self.path)
|
||||
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):
|
||||
|
@ -233,7 +233,7 @@ class InputFormatPlugin(Plugin):
|
||||
# In case stdout is broken
|
||||
pass
|
||||
|
||||
with CurrentDir(output_dir):
|
||||
with CurrentDir(output_dir, workaround_temp_folder_permissions=True):
|
||||
for x in os.listdir('.'):
|
||||
shutil.rmtree(x) if os.path.isdir(x) else os.remove(x)
|
||||
|
||||
|
@ -34,6 +34,19 @@ def app_prefix(prefix):
|
||||
return '%s_'%__appname__
|
||||
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)
|
||||
|
||||
def base_dir():
|
||||
global _base_dir
|
||||
if _base_dir is not None and not os.path.exists(_base_dir):
|
||||
|
Loading…
x
Reference in New Issue
Block a user