Adds error handling for the paths
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user