From 27295b8373b39c34126bcbf35152e04b194721cc Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 31 Jul 2024 11:49:16 -0600 Subject: [PATCH] Handling if tagged file does not exist during sync_tags_directory. --- wrolpi/tags.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/wrolpi/tags.py b/wrolpi/tags.py index 3e96c8eb..fe9c1545 100644 --- a/wrolpi/tags.py +++ b/wrolpi/tags.py @@ -281,8 +281,13 @@ def _sync_tags_directory_tag_files(tags_directory: pathlib.Path, session: Sessio for file, link in file_group.get_tag_directory_paths_map().items(): link = tags_directory / link if not link.is_file(): - link.parent.mkdir(parents=True, exist_ok=True) - link.hardlink_to(file) + try: + link.parent.mkdir(parents=True, exist_ok=True) + link.hardlink_to(file) + except FileNotFoundError: + logger.error(f'Failed to create link to file because it does not exist: {file}') + if PYTEST: + raise links.append(link) return links @@ -328,10 +333,12 @@ def create_tags_directory(directory: pathlib.Path): directory.mkdir(parents=True, exist_ok=True) readme = directory / 'README.txt' - readme.write_text('''This directory exists to allow a secondary way to access your tagged files. Files are -organized in a directory named after all the Tags they have been tagged with. + readme.write_text('''This directory exists to allow a secondary way to access your tagged files. +Files are organized in a directory named after all the Tags they have been +tagged with. -WARNING: This directory is controlled by WROLPi, any files you put in here will be automatically deleted! +WARNING: This directory is controlled by WROLPi, any files you put in here will +be AUTOMATICALLY DELETED! ''')