From 5613f8287ca963f6a8cef56c142f2e946ac0bcfe Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:34:07 -0500 Subject: [PATCH] Fix handling of relative paths in image source field --- kodak/resources/image.py | 2 +- kodak/tools/index.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kodak/resources/image.py b/kodak/resources/image.py index fd0fdec..2c8f3e2 100644 --- a/kodak/resources/image.py +++ b/kodak/resources/image.py @@ -23,7 +23,7 @@ class Image(KodakResource): # "original". This is because flask will serve the symlink file itself, not the linked file, # to the browser. resp = flask.send_file( - image.source, + flask.current_app.appconfig.source_dir / image.source, cache_timeout=int(datetime.timedelta(days=365).total_seconds()), add_etags=False, ) diff --git a/kodak/tools/index.py b/kodak/tools/index.py index 67ed4e8..7010b31 100644 --- a/kodak/tools/index.py +++ b/kodak/tools/index.py @@ -21,7 +21,7 @@ def identify(config: configuration.KodakConfig) -> List[database.ImageRecord]: for item in path.iterdir(): if item.is_file() and item.suffix in constants.IMAGE_FILE_EXTENSIONS: logger.debug(f"Including file {item}") - identified.append(item) + identified.append(item.resolve()) elif item.is_dir(): logger.debug(f"Entering subdirectory {item}") identified += _identify(item) @@ -49,7 +49,7 @@ def identify(config: configuration.KodakConfig) -> List[database.ImageRecord]: results = [] for image in images: - if image in existing: + if image.relative_to(config.source_dir) in existing: logger.debug(f"Skipping existing {image}") else: logger.debug(f"Including newly identified image {image}") @@ -58,7 +58,7 @@ def identify(config: configuration.KodakConfig) -> List[database.ImageRecord]: return results -def clean() -> List[database.ImageRecord]: +def clean(config: configuration.KodakConfig) -> List[database.ImageRecord]: """Identify removed or changed source images and mark them as deleted :param config: Populated application configuration object @@ -78,7 +78,7 @@ def clean() -> List[database.ImageRecord]: deleted = [] for item in existing: - if item.source.exists(): + if (config.source_dir / item.source).exists(): logger.debug( f"Image file exists, record will not be modified: {item.source}" ) @@ -108,7 +108,7 @@ def build(config: Optional[configuration.KodakConfig] = None) -> None: batch_size=database.calc_batch_size(config.database.backend, new_images), ) - removed_images = clean() + removed_images = clean(config) with database.interface.atomic(): database.ImageRecord.bulk_update( removed_images,