mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-10-31 01:58:31 -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.
105 lines
2.8 KiB
Python
105 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
# Python rewrite of testsuite/00-hello.test.
|
|
#
|
|
# Foundational smoke test: --version / --info=help / --debug=help all
|
|
# work, plus a round-trip transfer of a directory whose name contains
|
|
# shell-special characters via the lsh.sh remote-shell stand-in.
|
|
|
|
import os
|
|
|
|
from rsyncfns import (
|
|
FROMDIR, RSYNC, RSYNC_PEER, SRCDIR, TODIR,
|
|
checkit, run_rsync, test_fail, rsync_path_arg, rsh_cmd,
|
|
)
|
|
|
|
|
|
# Set RSYNC_RSH so rsync picks up lsh.sh for the "lh:" hosts below.
|
|
os.environ['RSYNC_RSH'] = rsh_cmd()
|
|
|
|
# Basic help dumps must not crash.
|
|
if run_rsync('--version', check=False).returncode != 0:
|
|
test_fail('--version output failed')
|
|
if run_rsync('--info=help', check=False).returncode != 0:
|
|
test_fail('--info=help output failed')
|
|
if run_rsync('--debug=help', check=False).returncode != 0:
|
|
test_fail('--debug=help output failed')
|
|
|
|
weird_name = "A weird)name"
|
|
|
|
FROMDIR.mkdir(parents=True, exist_ok=True)
|
|
weird_dir = FROMDIR / weird_name
|
|
weird_dir.mkdir()
|
|
|
|
|
|
def append_line(line: str) -> None:
|
|
print(line)
|
|
with open(weird_dir / 'file', 'a') as f:
|
|
f.write(line + '\n')
|
|
|
|
|
|
def copy_weird(args: list, src_host: str, dst_host: str) -> None:
|
|
checkit(
|
|
[*args, f'--rsync-path={rsync_path_arg()}',
|
|
f'{src_host}{weird_dir}/',
|
|
f'{dst_host}{TODIR / weird_name}'],
|
|
FROMDIR, TODIR,
|
|
)
|
|
|
|
|
|
append_line('test1')
|
|
checkit(['-ai', f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)
|
|
|
|
append_line('test2')
|
|
copy_weird(['-ai'], 'lh:', '')
|
|
|
|
append_line('test3')
|
|
copy_weird(['-ai'], '', 'lh:')
|
|
|
|
append_line('test4')
|
|
copy_weird(['-ais'], 'lh:', '')
|
|
|
|
append_line('test5')
|
|
copy_weird(['-ais'], '', 'lh:')
|
|
|
|
# test6: --old-args lets two whitespace-separated names go through as a
|
|
# single "one two" remote argument to be re-split by the remote shell.
|
|
print('test6')
|
|
(FROMDIR / 'one').touch()
|
|
(FROMDIR / 'two').touch()
|
|
|
|
saved = os.getcwd()
|
|
os.chdir(FROMDIR)
|
|
try:
|
|
run_rsync('-ai', '--old-args', f'--rsync-path={rsync_path_arg()}',
|
|
'lh:one two', f'{TODIR}/')
|
|
finally:
|
|
os.chdir(saved)
|
|
|
|
if not (TODIR / 'one').is_file() or not (TODIR / 'two').is_file():
|
|
test_fail("old-args copy of 'one two' failed")
|
|
|
|
# test7: the RSYNC_OLD_ARGS=1 env var should be equivalent to --old-args.
|
|
print('test7')
|
|
(TODIR / 'one').unlink()
|
|
(TODIR / 'two').unlink()
|
|
|
|
env = os.environ.copy()
|
|
env['RSYNC_OLD_ARGS'] = '1'
|
|
import subprocess
|
|
from rsyncfns import rsync_argv
|
|
|
|
os.chdir(FROMDIR)
|
|
try:
|
|
subprocess.run(
|
|
rsync_argv('-ai', f'--rsync-path={rsync_path_arg()}',
|
|
'lh:one two', f'{TODIR}/'),
|
|
env=env, check=True,
|
|
)
|
|
finally:
|
|
os.chdir(saved)
|
|
|
|
# check=True only proves a zero exit; confirm the env-var path actually copied
|
|
# both files (as the explicit --old-args case above does).
|
|
if not (TODIR / 'one').is_file() or not (TODIR / 'two').is_file():
|
|
test_fail("RSYNC_OLD_ARGS=1 copy of 'one two' failed")
|