From 87db8a049863a315c4d16c663abd335d46da0ae2 Mon Sep 17 00:00:00 2001 From: furtest Date: Sun, 27 Jul 2025 17:46:37 +0200 Subject: [PATCH] Adds links generation and update Adds update_links to the synchroniser which updates the links. It should also be able to generate links on the first run. --- src/unisync/synchroniser.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/unisync/synchroniser.py b/src/unisync/synchroniser.py index a5e0880..b4b0686 100644 --- a/src/unisync/synchroniser.py +++ b/src/unisync/synchroniser.py @@ -131,8 +131,40 @@ class Synchroniser: command.append(remote_root) command.append("-batch") - print(command) proc = subprocess.Popen(command) ret_code = proc.wait() return ret_code + def update_links(self, background:bool=True): + """ + Update the links on the remote. + First calls cleanlinks to remove deadlinks and empty directories. + Then calls lndir to create the new links. + Args: + - + """ + + link_update_script = (f"cd {self.remote_dir}/links && " + "cleanlinks && " + "lndir -withrevinfo -ignorelinks -silent ../.data .;") + + if background: + link_background_wrapper = f"nohup bash -c \"{link_update_script}\" > /dev/null 2>&1 < /dev/null &" + else: + link_background_wrapper = link_update_script + + command = [ + "/usr/bin/ssh", + "-S", self.control_path, + f"{self.remote_user}@{self.remote_ip}", + "-p", str(self.remote_port), + link_background_wrapper + ] + + link_update_process = subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + if not background: + print("Starting links update.") + link_update_process.wait() + print("Done") +