diff --git a/README.md b/README.md index 5415c57..80a439b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # link-fixer -Fix broken symbolic links. Search for file of same name in target directory and link to that target if unique and if exists. \ No newline at end of file +Fix broken symbolic links. Search for file of same name as original target in provided directory and link to that target if unique and if exists. \ No newline at end of file diff --git a/link_fixer.py b/link_fixer.py index 55c4510..549b27e 100644 --- a/link_fixer.py +++ b/link_fixer.py @@ -3,6 +3,9 @@ import os from pathlib import Path import sys +from search_file import search_file +from swap_link import swap_link + def link_fixer(ln_path, tgt_dir_path): ln_is_dir = False @@ -32,6 +35,9 @@ def link_fixer(ln_path, tgt_dir_path): print("Targets dir: \t", tgt_dir) if ln_is_dir: sys.exit("But ln dir version not yet implemented. Sorry!") + + tgt = search_file(link.resolve().name, tgt_dir_path) + swap_link(ln_path, tgt) def fix_link(lnk, tgt_dir_path): return True diff --git a/swap_link.py b/swap_link.py index 7f5e442..f2afc1b 100644 --- a/swap_link.py +++ b/swap_link.py @@ -6,8 +6,8 @@ from pathlib import Path from os.path import relpath # won't be necessary with Python 3.12 thanks to walk_up arg in relative_to() def swap_link(lnk, tgt): - #lnk: symbolic link to swap - #tgt: target for new link + #lnk: symbolic link to swap, str + #tgt: target for new link, str lnpath = Path(lnk) if not lnpath.is_symlink(): raise Exception("First argument is not a symbolic link")