diff options
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 |
commit | feae86528cba80ae9f0bcb189451ee3fb02d88be (patch) | |
tree | 78eaf482caeb100e905665ecd8d26c6437048eee /ishtar_common/utils.py | |
parent | 48da8fa6033474e48bcfa5d5d7db395b7f93fbd7 (diff) | |
download | Ishtar-feae86528cba80ae9f0bcb189451ee3fb02d88be.tar.bz2 Ishtar-feae86528cba80ae9f0bcb189451ee3fb02d88be.zip |
media_find_missing_files: try first to fix bad links
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 16 |
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 |