Even more robust handling of temp library during restore

This commit is contained in:
Kovid Goyal 2013-10-20 09:43:48 +05:30
parent 0bc80abeab
commit 2fae9e67c7
2 changed files with 12 additions and 2 deletions

View File

@ -99,7 +99,16 @@ class Restore(Thread):
def run(self): def run(self):
try: try:
with TemporaryDirectory('relib') as tdir: basedir = os.path.dirname(self.src_library_path)
try:
tdir = TemporaryDirectory('_rlib', dir=basedir)
tdir.__enter__()
except EnvironmentError:
# Incase we dont have permissions to create directories in the
# parent folder of the src library
tdir = TemporaryDirectory('_rlib')
with tdir as tdir:
self.library_path = tdir self.library_path = tdir
self.scan_library() self.scan_library()
if not self.load_preferences(): if not self.load_preferences():

View File

@ -170,7 +170,8 @@ class TemporaryDirectory(object):
self.keep = keep self.keep = keep
def __enter__(self): def __enter__(self):
self.tdir = _make_dir(self.suffix, self.prefix, self.dir) if not hasattr(self, 'tdir'):
self.tdir = _make_dir(self.suffix, self.prefix, self.dir)
return self.tdir return self.tdir
def __exit__(self, *args): def __exit__(self, *args):