From 86a6c8acceaadc65b1f5bf2aec67a861d2559f9c Mon Sep 17 00:00:00 2001 From: furtest Date: Tue, 30 Dec 2025 17:56:03 +0100 Subject: [PATCH] Adds error handling for the paths --- src/unisync/synchroniser.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/unisync/synchroniser.py b/src/unisync/synchroniser.py index f1831d1..fc07e76 100644 --- a/src/unisync/synchroniser.py +++ b/src/unisync/synchroniser.py @@ -9,6 +9,8 @@ import logging from pathlib import Path +from errors import RemoteMountedError, InvalidMountError + logger = logging.getLogger(__name__) class Synchroniser: @@ -175,16 +177,24 @@ class Synchroniser: Mount the remote directory to make the local links work. This is achieved using sshfs. Raise: + - RemoteMountedError: The .data directory is already a mount point + - InvalidMountError: .data is either not a directory or not empty - subprocess.CalledProcessError: An error occured with sshfs """ + # Get the absolute path to the correct .data directory resolving symlinks + path_to_mount:PosixPath = Path(f"{self.local}/../.data").resolve() + if path_to_mount.is_mount(): + raise RemoteMountedError + # Check if it is an empty directory + if not path_to_mount.is_dir() or any(path_to_mount.iterdir()): + raise InvalidMountError 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()) + str(path_to_mount) ] completed_process = subprocess.run(command) completed_process.check_returncode()