Fix test failing on windows

This commit is contained in:
Kovid Goyal 2019-12-05 18:37:32 +05:30
parent d2ed3045df
commit 99bc1a8e65
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -9,6 +9,7 @@ import os
import tempfile import tempfile
import time import time
from hashlib import sha1 from hashlib import sha1
from itertools import count
from calibre import walk from calibre import walk
from calibre.constants import cache_dir, iswindows from calibre.constants import cache_dir, iswindows
@ -23,6 +24,7 @@ from polyglot.builtins import as_bytes, as_unicode, iteritems
DAY = 24 * 3600 DAY = 24 * 3600
VIEWER_VERSION = 1 VIEWER_VERSION = 1
td_counter = count()
def book_cache_dir(): def book_cache_dir():
@ -137,7 +139,7 @@ def expire_cache_and_temp(temp_path, finished_path, metadata, max_age, force_exp
def prepare_convert(temp_path, key, st, book_path): def prepare_convert(temp_path, key, st, book_path):
tdir = tempfile.mkdtemp(dir=temp_path) tdir = tempfile.mkdtemp(dir=temp_path, prefix=f'c{next(td_counter)}-')
now = time.time() now = time.time()
return { return {
'path': os.path.basename(tdir), 'path': os.path.basename(tdir),
@ -233,7 +235,7 @@ def prepare_book(path, convert_func=do_convert, max_age=30 * DAY, force=False, p
convert_func(path, temp_path, key, instance) convert_func(path, temp_path, key, instance)
src_path = os.path.join(temp_path, instance['path']) src_path = os.path.join(temp_path, instance['path'])
with cache_lock() as f: with cache_lock() as f:
ans = tempfile.mkdtemp(dir=finished_path) ans = tempfile.mkdtemp(dir=finished_path, prefix=f'c{next(td_counter)}-')
instance['path'] = os.path.basename(ans) instance['path'] = os.path.basename(ans)
try: try:
metadata = json.loads(f.read()) metadata = json.loads(f.read())