mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-09-13 05:38:57 -04:00
Second layer of the space-in-build-path work. Quoting the Makefile got the
runner started; these are the places that then hand the binary's path to
something that splits on whitespace.
- RSYNC_CONNECT_PROG is run by a shell. This was the big one: an unquoted
daemon command turned every daemon-mode test into
"sh: 1: /path/to/ws: Permission denied".
- RSYNC_RSH / --rsh is tokenised by rsync itself (do_cmd() in main.c, which
honours ' and "), so support/lsh.sh needs quoting when srcdir has a space.
- --rsync-path is a command line run by the REMOTE shell, so rsync passes it
through unsplit and lsh.sh's eval re-parses it.
- The generated rsync-shim scripts interpolate RSYNC into "#!/bin/sh\nexec
...", where it is shell syntax rather than an argv entry.
rsync_path_arg() and rsh_cmd() build those strings by splitting the command and
re-joining with shlex, so a plain path with a space comes back quoted while a
wrapper command ("valgrind ... /build/rsync") stays several words.
split_rsync_cmd() also has to cope with RSYNC once a test has appended options
to it -- chown-fake and friends do -- where the string is no longer a filename.
It now takes the longest leading run that names an existing file as the program
and splits only what follows.
In a directory with a space: 231 pass, 22 fail, from 0 able to run before the
first commit. Unchanged in a normal path: 257 passed, 0 failed.
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
# Python rewrite of testsuite/ssh-basic.test.
|
|
#
|
|
# Basic two-step "remote shell" transfer via lsh.sh (or real ssh if
|
|
# rsync_enable_ssh_tests=yes is set in shconfig). Confirms that an -e
|
|
# RSH transfer reproduces the source tree on the destination, and that
|
|
# a follow-up --delete pass cleans up after a destination-side rename.
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from rsyncfns import (
|
|
FROMDIR, SRCDIR, TODIR,
|
|
checkit, hands_setup, runtest, test_skipped, rsync_path_arg, rsh_cmd,
|
|
)
|
|
|
|
|
|
SSH = rsh_cmd()
|
|
|
|
# Allow opting into real ssh via the shconfig variable, like the shell test.
|
|
if os.environ.get('rsync_enable_ssh_tests') == 'yes':
|
|
real_ssh = shutil.which('ssh')
|
|
if real_ssh:
|
|
SSH = real_ssh
|
|
|
|
probe = subprocess.run(
|
|
[SSH, '-oBatchMode yes', 'localhost', 'echo', 'yes'],
|
|
capture_output=True, text=True,
|
|
)
|
|
if probe.stdout.strip() != 'yes':
|
|
test_skipped(
|
|
"Skipping SSH tests because ssh connection to localhost not authorised"
|
|
)
|
|
|
|
print(f"Using remote shell: {SSH}")
|
|
|
|
hands_setup()
|
|
|
|
# RSYNC may be a multi-word command line; pass it through --rsync-path.
|
|
from rsyncfns import RSYNC, RSYNC_PEER
|
|
|
|
|
|
def _basic():
|
|
checkit(['-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}',
|
|
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
|
|
|
|
|
|
def _delete_after_rename():
|
|
shutil.move(str(TODIR / 'text'), str(TODIR / 'ThisShouldGo'))
|
|
checkit(['--delete', '-avH', '-e', SSH, f'--rsync-path={rsync_path_arg()}',
|
|
f'{FROMDIR}/', f'localhost:{TODIR}'], FROMDIR, TODIR)
|
|
|
|
|
|
runtest("ssh: basic test", _basic)
|
|
runtest("ssh: renamed file", _delete_after_rename)
|