tdir_in_cache() should return an empty dir

This commit is contained in:
Kovid Goyal 2018-01-28 09:06:56 +05:30
parent 25d88c62c0
commit 20b6ac0534
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -103,7 +103,7 @@ def tdir_in_cache(base):
''' Create a temp dir inside cache_dir/base. The created dir is robust ''' Create a temp dir inside cache_dir/base. The created dir is robust
against application crashes. i.e. it will be cleaned up the next time the against application crashes. i.e. it will be cleaned up the next time the
application starts, even if it was left behind by a previous crash. ''' application starts, even if it was left behind by a previous crash. '''
b = os.path.join(cache_dir(), base) b = os.path.join(os.path.realpath(cache_dir()), base)
try: try:
os.makedirs(b) os.makedirs(b)
except EnvironmentError as e: except EnvironmentError as e:
@ -121,6 +121,8 @@ def tdir_in_cache(base):
tdir = tempfile.mkdtemp(dir=b) tdir = tempfile.mkdtemp(dir=b)
lock_data = lock_tdir(tdir) lock_data = lock_tdir(tdir)
atexit.register(remove_tdir, tdir, lock_data) atexit.register(remove_tdir, tdir, lock_data)
tdir = os.path.join(tdir, 'a')
os.mkdir(tdir)
return tdir return tdir
finally: finally:
unlock_file(global_lock) unlock_file(global_lock)