Skip to content

Commit 45ca578

Browse files
create target directory more efficiently
1 parent dd37211 commit 45ca578

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

livesync/folder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
import sys
66
from pathlib import Path
7-
from typing import Callable, List, Optional, Set, Union
7+
from typing import Callable, List, Optional, Union
88

99
import pathspec
1010
import watchfiles
@@ -84,7 +84,8 @@ async def watch(self) -> None:
8484
def sync(self) -> None:
8585
args = ' '.join(self._rsync_args)
8686
args += ''.join(f' --exclude="{e}"' for e in self._get_ignores())
87-
args += f' -e "ssh -p {self.ssh_port}"'
87+
args += f' -e "ssh -p {self.ssh_port}"' # NOTE: use SSH with custom port
88+
args += f' --rsync-path="mkdir -p {self.target_path} && rsync"' # NOTE: create target folder if not exists
8889
run_subprocess(f'rsync {args} {self.source_path}/ {self.target}/', quiet=True)
8990
if isinstance(self.on_change, str):
9091
run_subprocess(f'ssh {self.host} -p {self.ssh_port} "cd {self.target_path}; {self.on_change}"')

livesync/sync.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from .folder import Folder
66
from .mutex import Mutex
7-
from .run_subprocess import run_subprocess
87

98

109
def get_summary(folders: Iterable[Folder]) -> str:
@@ -13,10 +12,6 @@ def get_summary(folders: Iterable[Folder]) -> str:
1312

1413
async def run_folder_tasks(folders: Iterable[Folder], mutex_interval: float) -> None:
1514
try:
16-
for folder in folders:
17-
print(f'Creating target folder {folder.target_path}', flush=True)
18-
run_subprocess(f'ssh {folder.host} -p {folder.ssh_port} "mkdir -p {folder.target_path}"')
19-
2015
summary = get_summary(folders)
2116
mutexes = {folder.host: Mutex(folder.host, folder.ssh_port) for folder in folders}
2217
for mutex in mutexes.values():

0 commit comments

Comments
 (0)