From 837cc1bcf47d01b24500a2097e0d9de046046e4c Mon Sep 17 00:00:00 2001 From: furtest Date: Mon, 28 Jul 2025 15:31:40 +0200 Subject: [PATCH] Adds mount_remote_dir Adds the mount_remote_dir method to the synchroniser, this allows to mount the remote directory in order to access it with the generated links. Also adds the background parameter to the documentation of update_links --- src/unisync/synchroniser.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/unisync/synchroniser.py b/src/unisync/synchroniser.py index b4b0686..f1831d1 100644 --- a/src/unisync/synchroniser.py +++ b/src/unisync/synchroniser.py @@ -7,6 +7,8 @@ import sys import time import logging +from pathlib import Path + logger = logging.getLogger(__name__) class Synchroniser: @@ -141,7 +143,7 @@ class Synchroniser: First calls cleanlinks to remove deadlinks and empty directories. Then calls lndir to create the new links. Args: - - + - background: controls if the update is done in the background or waited for """ link_update_script = (f"cd {self.remote_dir}/links && " @@ -168,3 +170,21 @@ class Synchroniser: link_update_process.wait() print("Done") + def mount_remote_dir(self): + """ + Mount the remote directory to make the local links work. + This is achieved using sshfs. + Raise: + - subprocess.CalledProcessError: An error occured with sshfs + """ + command = [ + "/usr/bin/sshfs", + "-o", "ControlPath={self.control_path}", + "-o", "ServerAliveInterval=15", + "-p", str(self.remote_port), + f"{self.remote_user}@{self.remote_ip}:{self.remote_dir}/.data", + # Get the absolute path to the correct .data directory resolving symlinks + str(Path(f"{self.local}/../.data").resolve()) + ] + completed_process = subprocess.run(command) + completed_process.check_returncode()