summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-19 11:40:03 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:24 +0100
commit4444f712ff6643caac6f3ce37108ca2ed01329c6 (patch)
tree78eaf482caeb100e905665ecd8d26c6437048eee /ishtar_common/utils.py
parentd8dd7605d9049afdf8bf16ee44bc45c52d76aacf (diff)
downloadIshtar-4444f712ff6643caac6f3ce37108ca2ed01329c6.tar.bz2
Ishtar-4444f712ff6643caac6f3ce37108ca2ed01329c6.zip
media_find_missing_files: try first to fix bad links
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py16
1 files changed, 15 insertions, 1 deletions
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