From 4444f712ff6643caac6f3ce37108ca2ed01329c6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 19 Feb 2021 11:40:03 +0100 Subject: media_find_missing_files: try first to fix bad links --- ishtar_common/utils.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index a3bc23e21..b4542688b 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -1499,6 +1499,20 @@ MEDIA_RE = [ ] +def get_broken_links(path): + for root, dirs, files in os.walk(path): + for filename in files: + path = os.path.join(root, filename) + if os.path.islink(path): + target_path = os.readlink(path) + # resolve relative symlinks + if not os.path.isabs(target_path): + target_path = os.path.join(os.path.dirname(path), + target_path) + if not os.path.exists(target_path): + yield path + + def simplify_name(full_path_name, check_existing=False, min_len=15): """ Simplify a file name by removing auto save suffixes @@ -1766,7 +1780,7 @@ def try_fix_file(filename, make_copy=True, hard=False): for path, __, files in os.walk(settings.MEDIA_ROOT): for f in files: result = _try_copy(path, f, filename, simplified_ref_name, - make_copy, min_len=15) # 15 - less agressive + make_copy, min_len=10) if result: return result -- cgit v1.2.3