From 71a89500bbce14a6742b2bd1b1e4e7bd8a06ea34 Mon Sep 17 00:00:00 2001 From: Jared Therriault Date: Tue, 16 Dec 2025 19:43:52 -0800 Subject: [PATCH] Improve sorting by date in ImageDrawer This ensures that, if available, we'll sort using the date the file was created rather than modified date. Modified will be used as a fallback. --- py/server_backend.py | 2 +- py/utils.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/py/server_backend.py b/py/server_backend.py index 1992479..4d8e87a 100644 --- a/py/server_backend.py +++ b/py/server_backend.py @@ -118,7 +118,7 @@ def create_familiar_dictionaries(names, type, image_extension_filter, info_exten # logger.info(f"file_name_no_ext, file_ext: {file_name_no_ext, file_ext}") # Get time of creation since the last epoch, in seconds - file_age = os.path.getctime(file_path) + file_age = get_creation_time(file_path) file_path = file_path.replace("\\", "/") # logger.info(f'file_path: {file_path}') diff --git a/py/utils.py b/py/utils.py index a06e23b..b0a4a92 100644 --- a/py/utils.py +++ b/py/utils.py @@ -389,3 +389,11 @@ def is_pil_image(obj): # Check if an object is a PyTorch tensor def is_torch_tensor(obj): return isinstance(obj, torch.Tensor) + +def get_creation_time(file_path): + """Get file creation time if available, otherwise fallback to modification time.""" + try: + stat = os.stat(file_path) + return stat.st_birthtime # Works on some Linux filesystems + except AttributeError: + return os.path.getmtime(file_path)