Handle mtime as number or datetime object

This commit is contained in:
Kovid Goyal 2021-06-28 07:37:57 +05:30
parent 78da380d11
commit 582e13ba6e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -79,9 +79,10 @@ def create_file_copy(ctx, rd, prefix, library_id, book_id, ext, mtime, copy_func
with suppress(OSError): with suppress(OSError):
return os.path.getmtime(fname) return os.path.getmtime(fname)
mt = mtime if isinstance(mtime, (int, float)) else timestampfromdt(mtime)
with lock: with lock:
previous_mtime = safe_mtime() previous_mtime = safe_mtime()
if previous_mtime is None or previous_mtime < mtime: if previous_mtime is None or previous_mtime < mt:
if previous_mtime is not None: if previous_mtime is not None:
# File exists and may be open, so we cannot change its # File exists and may be open, so we cannot change its
# contents, as that would lead to corrupted downloads in any # contents, as that would lead to corrupted downloads in any
@ -111,7 +112,7 @@ def create_file_copy(ctx, rd, prefix, library_id, book_id, ext, mtime, copy_func
if ctx.testing: if ctx.testing:
rd.outheaders['Used-Cache'] = used_cache rd.outheaders['Used-Cache'] = used_cache
rd.outheaders['Tempfile'] = as_hex_unicode(fname) rd.outheaders['Tempfile'] = as_hex_unicode(fname)
return rd.filesystem_file_with_custom_etag(ans, prefix, library_id, book_id, mtime, extra_etag_data) return rd.filesystem_file_with_custom_etag(ans, prefix, library_id, book_id, mt, extra_etag_data)
def write_generated_cover(db, book_id, width, height, destf): def write_generated_cover(db, book_id, width, height, destf):