#291: - Compile --exclude/--include/--exclude-from/--include-from into the SAME ordered rule list as --filter/-f (first match wins), so the common `--include='*.txt' --exclude='*'` idiom and include-alone semantics match rsync. The legacy per-kind scanner arrays are no longer applied. - -x/--one-file-system emits the cross-device mount-point directory entry (empty) instead of dropping it, in both the sequential and parallel scanners. - Stop passing the legacy arrays to the scanner; document -f is --filter. #292: - New src/shared/format.c/.h: rsync "big_num" (comma-grouped integers) and decimal -h human sizes, %M/%t timestamp, and the STATUS_DEST_INFO codec. - Receiver answers each STATUS_CHECK with a pre-transfer destination snapshot (new report_dest_info wire field + STATUS_DEST_INFO, PROTOCOL_VERSION 2.23.0) so the sender can render true itemize columns. - Itemize now emits rsync-correct update/type chars and c/s/t/p/o/g columns for files, dirs, symlinks and hard links, comparing size/time/perms/owner/ group against the reported destination. - --out-format gains %i %n %f %l %b %M %t %o %p %B %U %G %L; %f is the relative display path, %M the YYYY/MM/DD-HH:MM:SS form, %b the literal bytes sent. - --list-only prints transfer-relative names, directory entries and ls-style grouped sizes. - --stats prints rsync's multi-line block on stdout; -h uses decimal units. Tests: unit tests for the filter ordering, format primitives, itemize columns; integration + differential tests against real rsync 3.4.1 for itemize/out-format/list-only/selection and -x. Golden wire len/hash and protocol version strings updated for 2.23.0.
This commit is contained in:
@@ -36,7 +36,7 @@ from common import ( # noqa: E402
|
||||
verify_transfer,
|
||||
)
|
||||
|
||||
PROTOCOL_VERSION = b"2.22.0"
|
||||
PROTOCOL_VERSION = b"2.23.0"
|
||||
STATUS_MANIFEST = 5
|
||||
STATUS_OK = 0
|
||||
|
||||
|
||||
@@ -325,7 +325,7 @@ class TestDryRun:
|
||||
result, dur = run_client(SOURCE_DIR, DEST_DIR, flags=["-h", "--dry-run"])
|
||||
assert result.returncode == 0, f"Exit {result.returncode}: {result.stderr[:100]}"
|
||||
assert "Total:" in result.stdout
|
||||
assert "KB" in result.stdout
|
||||
assert any(unit in result.stdout for unit in ("K", "M", "G"))
|
||||
|
||||
def test_dry_run(self):
|
||||
clean_dir(DEST_DIR)
|
||||
@@ -1070,10 +1070,12 @@ class TestExclude:
|
||||
|
||||
class TestInclude:
|
||||
def test_include_single(self, shared_server):
|
||||
# rsync first-match-wins: an --include alone is NOT a whitelist, so the
|
||||
# selector must pair it with --exclude '*' (the common idiom).
|
||||
clean_dir(DEST_DIR)
|
||||
result, dur = run_client(
|
||||
SOURCE_DIR, DEST_DIR,
|
||||
flags=["--include", "binary.bin"],
|
||||
flags=["--include", "binary.bin", "--exclude", "*"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
@@ -1086,13 +1088,14 @@ class TestInclude:
|
||||
clean_dir(DEST_DIR)
|
||||
result, dur = run_client(
|
||||
SOURCE_DIR, DEST_DIR,
|
||||
flags=["--include", "*.bin"],
|
||||
flags=["--include", "*.bin", "--exclude", "*"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
pytest.fail(f"Exit {result.returncode}: {(result.stderr or result.stdout)[:200]}")
|
||||
received = get_dest_received_dir(DEST_DIR, SOURCE_DIR)
|
||||
assert os.path.exists(os.path.join(received, "binary.bin")), "binary.bin should be included"
|
||||
assert not os.path.exists(os.path.join(received, "small.txt")), "small.txt should not be included"
|
||||
|
||||
|
||||
class TestSizeFilters:
|
||||
@@ -1646,8 +1649,8 @@ class TestDelete:
|
||||
port=shared_server.port,
|
||||
)
|
||||
assert result.returncode == 0, f"Exit {result.returncode}: {result.stderr[:100]}"
|
||||
assert "Stats:" in result.stderr
|
||||
assert "KB" in result.stderr
|
||||
assert "Number of files:" in result.stdout
|
||||
assert "Total file size:" in result.stdout
|
||||
|
||||
def test_human_readable_stats_multithreaded(self, shared_server):
|
||||
# The multithreaded sender shares the single-threaded --stats format,
|
||||
@@ -1659,9 +1662,8 @@ class TestDelete:
|
||||
port=shared_server.port,
|
||||
)
|
||||
assert result.returncode == 0, f"Exit {result.returncode}: {result.stderr[:100]}"
|
||||
assert "Stats:" in result.stderr
|
||||
assert "KB" in result.stderr
|
||||
assert "/s" in result.stderr
|
||||
assert "Number of files:" in result.stdout
|
||||
assert "bytes/sec" in result.stdout
|
||||
|
||||
def test_human_readable_progress_multithreaded(self, shared_server):
|
||||
clean_dir(DEST_DIR)
|
||||
@@ -1673,7 +1675,6 @@ class TestDelete:
|
||||
assert result.returncode == 0, f"Exit {result.returncode}: {result.stderr[:100]}"
|
||||
output = result.stdout + result.stderr
|
||||
assert "Sent " in output
|
||||
assert "KB" in output
|
||||
assert "Done." in output
|
||||
|
||||
|
||||
@@ -2164,7 +2165,8 @@ class TestListOnly:
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR, flags=["--list-only"])
|
||||
assert result.returncode == 0, f"list-only failed: {result.stderr[:200]}"
|
||||
for full_path in _source_files():
|
||||
assert full_path in result.stdout, f"list-only omitted {full_path}"
|
||||
rel = os.path.relpath(full_path, SOURCE_DIR)
|
||||
assert rel in result.stdout, f"list-only omitted {rel}"
|
||||
received = get_dest_received_dir(DEST_DIR, SOURCE_DIR)
|
||||
assert not os.path.exists(received), "list-only wrote to the destination"
|
||||
|
||||
@@ -2180,7 +2182,8 @@ class TestListOnly:
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR, flags=["--list-only", "--threads"])
|
||||
assert result.returncode == 0, f"list-only -m failed: {result.stderr[:200]}"
|
||||
for full_path in _source_files():
|
||||
assert full_path in result.stdout, f"list-only -m omitted {full_path}"
|
||||
rel = os.path.relpath(full_path, SOURCE_DIR)
|
||||
assert rel in result.stdout, f"list-only -m omitted {rel}"
|
||||
received = get_dest_received_dir(DEST_DIR, SOURCE_DIR)
|
||||
assert not os.path.exists(received), "list-only -m wrote to the destination"
|
||||
|
||||
@@ -2193,7 +2196,7 @@ class TestItemizeChanges:
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR,
|
||||
flags=["--preserve", "-i"], port=shared_server.port)
|
||||
assert result.returncode == 0, f"itemize sync failed: {result.stderr[:200]}"
|
||||
sent_lines = {">f+++++++++ " + p for p in _source_files()}
|
||||
sent_lines = {">f+++++++++ " + os.path.relpath(p, SOURCE_DIR) for p in _source_files()}
|
||||
assert sent_lines <= set(result.stdout.splitlines()), (
|
||||
f"missing itemize lines; got {result.stdout[:500]}"
|
||||
)
|
||||
@@ -2214,7 +2217,7 @@ class TestItemizeChanges:
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR,
|
||||
flags=["--preserve", "-i", "--threads"], port=shared_server.port)
|
||||
assert result.returncode == 0, f"itemize -m sync failed: {result.stderr[:200]}"
|
||||
sent_lines = {">f+++++++++ " + p for p in _source_files()}
|
||||
sent_lines = {">f+++++++++ " + os.path.relpath(p, SOURCE_DIR) for p in _source_files()}
|
||||
assert sent_lines <= set(result.stdout.splitlines()), (
|
||||
f"missing itemize lines in -m mode; got {result.stdout[:500]}"
|
||||
)
|
||||
@@ -2249,7 +2252,9 @@ class TestItemizeChanges:
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, f"incremental itemize failed: {result.stderr[:200]}"
|
||||
itemized = [line for line in result.stdout.splitlines() if line.startswith(">f")]
|
||||
assert itemized == [">f+++++++++ " + changed], (
|
||||
# The content and mtime both changed, so the itemize compares the
|
||||
# destination snapshot: size and time columns are set.
|
||||
assert itemized == [">f.st...... changed.txt"], (
|
||||
f"expected exactly one itemize line for {changed}, got {itemized}"
|
||||
)
|
||||
received = get_dest_received_dir(dest, source)
|
||||
@@ -2265,7 +2270,11 @@ class TestOutFormat:
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR,
|
||||
flags=["--out-format=%f %l"], port=shared_server.port)
|
||||
assert result.returncode == 0, f"out-format sync failed: {result.stderr[:200]}"
|
||||
expected = {f"{p} {os.path.getsize(p)}" for p in _source_files()}
|
||||
# %f is rsync's long display path: the source argument normalized
|
||||
# (leading '/' stripped) joined to the transfer-relative name.
|
||||
prefix = SOURCE_DIR.lstrip(os.sep)
|
||||
expected = {f"{os.path.join(prefix, os.path.relpath(p, SOURCE_DIR))} {os.path.getsize(p)}"
|
||||
for p in _source_files()}
|
||||
got = set(result.stdout.splitlines())
|
||||
assert expected <= got, f"out-format lines missing: expected {len(expected)} got {len(got)}"
|
||||
|
||||
@@ -2274,7 +2283,9 @@ class TestOutFormat:
|
||||
result, _ = run_client(SOURCE_DIR, DEST_DIR,
|
||||
flags=["--out-format=%f %l", "--threads"], port=shared_server.port)
|
||||
assert result.returncode == 0, f"out-format -m sync failed: {result.stderr[:200]}"
|
||||
expected = {f"{p} {os.path.getsize(p)}" for p in _source_files()}
|
||||
prefix = SOURCE_DIR.lstrip(os.sep)
|
||||
expected = {f"{os.path.join(prefix, os.path.relpath(p, SOURCE_DIR))} {os.path.getsize(p)}"
|
||||
for p in _source_files()}
|
||||
got = set(result.stdout.splitlines())
|
||||
assert expected <= got, f"out-format -m lines missing: {result.stdout[:500]}"
|
||||
|
||||
@@ -2296,7 +2307,9 @@ class TestLogFileFormat:
|
||||
assert os.path.exists(log_path), "--log-file created no log"
|
||||
with open(log_path, encoding="utf-8", errors="replace") as fh:
|
||||
content = fh.read()
|
||||
expected = {f"{p} {os.path.getsize(p)}" for p in _source_files()}
|
||||
prefix = SOURCE_DIR.lstrip(os.sep)
|
||||
expected = {f"{os.path.join(prefix, os.path.relpath(p, SOURCE_DIR))} {os.path.getsize(p)}"
|
||||
for p in _source_files()}
|
||||
for line in expected:
|
||||
assert line in content, f"log file missing {line!r}"
|
||||
|
||||
@@ -2322,7 +2335,8 @@ class TestLogFileFormat:
|
||||
assert os.path.exists(log_path), "--log-file created no log"
|
||||
with open(log_path, encoding="utf-8", errors="replace") as fh:
|
||||
content = fh.read()
|
||||
expected = {f"{os.path.join(source, rel)} {len(data)}" for rel, data in files.items()}
|
||||
prefix = os.path.abspath(source).lstrip(os.sep)
|
||||
expected = {f"{os.path.join(prefix, rel)} {len(data)}" for rel, data in files.items()}
|
||||
for line in expected:
|
||||
assert line in content, f"log file (--threads) missing {line!r}"
|
||||
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
"""Output-parity tests (#291 selection/output, #292 output formatting).
|
||||
|
||||
These tests exercise rsync-style selection ordering and output formatting. The
|
||||
differential tests run the SAME transfer with real ``rsync 3.4.1`` and with
|
||||
fastsync and compare stdout, so they are skipped when rsync is unavailable.
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from common import TEST_DATA_DIR, run_client, clean_dir, get_dest_received_dir
|
||||
|
||||
RSYNC = shutil.which("rsync")
|
||||
requires_rsync = pytest.mark.skipif(RSYNC is None, reason="rsync 3.4.1 not installed")
|
||||
|
||||
|
||||
def _rsync(args):
|
||||
env = dict(os.environ, LC_ALL="C")
|
||||
return subprocess.run(
|
||||
[RSYNC] + args, capture_output=True, text=True, env=env, timeout=120
|
||||
)
|
||||
|
||||
|
||||
def _make_selection_tree(root):
|
||||
clean_dir(root)
|
||||
os.makedirs(os.path.join(root, "sub"))
|
||||
with open(os.path.join(root, "a.txt"), "wb") as fh:
|
||||
fh.write(b"top text\n")
|
||||
with open(os.path.join(root, "b.log"), "wb") as fh:
|
||||
fh.write(b"log data\n")
|
||||
with open(os.path.join(root, "sub", "c.txt"), "wb") as fh:
|
||||
fh.write(b"nested text\n")
|
||||
with open(os.path.join(root, "sub", "d.log"), "wb") as fh:
|
||||
fh.write(b"nested log\n")
|
||||
|
||||
|
||||
class TestSelectionOrdering:
|
||||
"""#291: --include/--exclude compile into one ordered rule list."""
|
||||
|
||||
@pytest.mark.ci
|
||||
def test_include_then_exclude_keeps_only_matching(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_inc_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_inc_dst")
|
||||
_make_selection_tree(source)
|
||||
clean_dir(dest)
|
||||
result, _ = run_client(
|
||||
source, dest,
|
||||
flags=["--preserve", "--include=*.txt", "--exclude=*"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
assert result.returncode == 0, f"include/exclude failed: {result.stderr[:300]}"
|
||||
received = get_dest_received_dir(dest, source)
|
||||
assert os.path.exists(os.path.join(received, "a.txt"))
|
||||
# `*` also excludes the directory, so nothing below sub/ is sent.
|
||||
assert not os.path.exists(os.path.join(received, "b.log"))
|
||||
assert not os.path.exists(os.path.join(received, "sub", "c.txt"))
|
||||
|
||||
@pytest.mark.ci
|
||||
def test_include_dirs_then_files_idiom(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_inc2_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_inc2_dst")
|
||||
_make_selection_tree(source)
|
||||
clean_dir(dest)
|
||||
result, _ = run_client(
|
||||
source, dest,
|
||||
flags=["--preserve", "--include=*/", "--include=*.txt", "--exclude=*"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
assert result.returncode == 0, f"include/exclude failed: {result.stderr[:300]}"
|
||||
received = get_dest_received_dir(dest, source)
|
||||
assert os.path.exists(os.path.join(received, "a.txt"))
|
||||
assert os.path.exists(os.path.join(received, "sub", "c.txt"))
|
||||
assert not os.path.exists(os.path.join(received, "b.log"))
|
||||
assert not os.path.exists(os.path.join(received, "sub", "d.log"))
|
||||
|
||||
@requires_rsync
|
||||
def test_include_idiom_matches_rsync_selection(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_inc3_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_inc3_dst")
|
||||
rdst = os.path.join(TEST_DATA_DIR, "out_inc3_rdst")
|
||||
_make_selection_tree(source)
|
||||
clean_dir(dest)
|
||||
clean_dir(rdst)
|
||||
flags = ["--include=*/", "--include=*.txt", "--exclude=*"]
|
||||
rsync_result = _rsync(["-a"] + flags + [source + "/", rdst + "/"])
|
||||
assert rsync_result.returncode == 0, rsync_result.stderr
|
||||
result, _ = run_client(source, dest, flags=["--preserve"] + flags,
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0
|
||||
received = get_dest_received_dir(dest, source)
|
||||
assert os.path.exists(os.path.join(received, "a.txt"))
|
||||
assert os.path.exists(os.path.join(received, "sub", "c.txt"))
|
||||
assert not os.path.exists(os.path.join(received, "b.log"))
|
||||
# rsync -a src/ dst/ writes directly into dst/
|
||||
assert os.path.exists(os.path.join(rdst, "a.txt"))
|
||||
assert os.path.exists(os.path.join(rdst, "sub", "c.txt"))
|
||||
assert not os.path.exists(os.path.join(rdst, "b.log"))
|
||||
|
||||
|
||||
class TestOneFileSystem:
|
||||
"""#291: -x emits the mount-point directory but not its contents."""
|
||||
|
||||
def test_one_file_system_emits_mount_point_dir(self, shared_server):
|
||||
local = os.stat(".")
|
||||
shm = "/dev/shm"
|
||||
try:
|
||||
shm_stat = os.stat(shm)
|
||||
except OSError:
|
||||
pytest.skip("/dev/shm not available")
|
||||
if shm_stat.st_dev == local.st_dev:
|
||||
pytest.skip("no cross-device filesystem available")
|
||||
|
||||
source = os.path.join(TEST_DATA_DIR, "out_ofs_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_ofs_dst")
|
||||
clean_dir(source)
|
||||
clean_dir(dest)
|
||||
os.makedirs(os.path.join(source, "nested"))
|
||||
os.makedirs(os.path.join(shm, "fastsync_ofs_probe"), exist_ok=True)
|
||||
with open(os.path.join(source, "keep.txt"), "wb") as fh:
|
||||
fh.write(b"keep\n")
|
||||
with open(os.path.join(shm, "fastsync_ofs_probe", "inside.txt"), "wb") as fh:
|
||||
fh.write(b"cross\n")
|
||||
link = os.path.join(source, "nested", "link")
|
||||
try:
|
||||
os.symlink(os.path.join(shm, "fastsync_ofs_probe"), link)
|
||||
except OSError:
|
||||
pytest.skip("cannot create symlink")
|
||||
|
||||
try:
|
||||
result, _ = run_client(
|
||||
source, dest,
|
||||
flags=["--preserve", "--copy-links", "-x"],
|
||||
port=shared_server.port,
|
||||
)
|
||||
assert result.returncode == 0, f"-x failed: {result.stderr[:300]}"
|
||||
received = get_dest_received_dir(dest, source)
|
||||
assert os.path.exists(os.path.join(received, "keep.txt"))
|
||||
# The mount-point directory entry is created but its contents are not.
|
||||
assert os.path.isdir(os.path.join(received, "nested", "link"))
|
||||
assert not os.path.exists(os.path.join(received, "nested", "link", "inside.txt"))
|
||||
finally:
|
||||
shutil.rmtree(os.path.join(shm, "fastsync_ofs_probe"), ignore_errors=True)
|
||||
|
||||
|
||||
def _make_output_tree(root):
|
||||
clean_dir(root)
|
||||
os.makedirs(os.path.join(root, "sub"))
|
||||
with open(os.path.join(root, "a.txt"), "wb") as fh:
|
||||
fh.write(b"hello\n")
|
||||
with open(os.path.join(root, "sub", "b.txt"), "wb") as fh:
|
||||
fh.write("wörld\n".encode("utf-8"))
|
||||
os.symlink("a.txt", os.path.join(root, "link"))
|
||||
|
||||
|
||||
class TestItemizeParity:
|
||||
"""#292: -i output matches rsync 3.4.1 for the cases fastsync can observe."""
|
||||
|
||||
@requires_rsync
|
||||
@pytest.mark.ci
|
||||
def test_itemize_first_transfer_matches_rsync(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_item_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_item_dst")
|
||||
rdst = os.path.join(TEST_DATA_DIR, "out_item_rdst")
|
||||
_make_output_tree(source)
|
||||
clean_dir(dest)
|
||||
clean_dir(rdst)
|
||||
rsync_result = _rsync(["-a", "-i", source + "/", rdst + "/"])
|
||||
assert rsync_result.returncode == 0, rsync_result.stderr
|
||||
rsync_lines = sorted(
|
||||
line for line in rsync_result.stdout.splitlines()
|
||||
if line.startswith(">f") or line.startswith("cL")
|
||||
)
|
||||
result, _ = run_client(source, dest, flags=["-a", "-i"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, result.stderr[:300]
|
||||
fast_lines = sorted(
|
||||
line for line in result.stdout.splitlines()
|
||||
if line.startswith(">f") or line.startswith("cL")
|
||||
)
|
||||
assert fast_lines == rsync_lines, f"rsync={rsync_lines} fastsync={fast_lines}"
|
||||
|
||||
@requires_rsync
|
||||
@pytest.mark.ci
|
||||
def test_itemize_modified_file_matches_rsync(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_item2_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_item2_dst")
|
||||
rdst = os.path.join(TEST_DATA_DIR, "out_item2_rdst")
|
||||
_make_output_tree(source)
|
||||
clean_dir(dest)
|
||||
clean_dir(rdst)
|
||||
seed = run_client(source, dest, flags=["-a"], port=shared_server.port)
|
||||
assert seed[0].returncode == 0, seed[0].stderr[:300]
|
||||
assert _rsync(["-a", source + "/", rdst + "/"]).returncode == 0
|
||||
|
||||
with open(os.path.join(source, "a.txt"), "wb") as fh:
|
||||
fh.write(b"hello changed and longer\n")
|
||||
# Pin the source mtime so rsync's `t` column is deterministic (a write
|
||||
# that lands in the same whole second as the seed would not show `t`).
|
||||
os.utime(os.path.join(source, "a.txt"), (1000000000, 1000000000))
|
||||
|
||||
rsync_result = _rsync(["-a", "-i", source + "/", rdst + "/"])
|
||||
assert rsync_result.returncode == 0, rsync_result.stderr
|
||||
rsync_lines = sorted(
|
||||
line for line in rsync_result.stdout.splitlines() if line.startswith(">f")
|
||||
)
|
||||
result, _ = run_client(source, dest,
|
||||
flags=["-a", "-i", "--incremental"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, result.stderr[:300]
|
||||
fast_lines = sorted(
|
||||
line for line in result.stdout.splitlines() if line.startswith(">f")
|
||||
)
|
||||
assert fast_lines == rsync_lines, f"rsync={rsync_lines} fastsync={fast_lines}"
|
||||
|
||||
|
||||
class TestOutFormatParity:
|
||||
@requires_rsync
|
||||
@pytest.mark.ci
|
||||
def test_out_format_n_l_matches_rsync(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_fmt_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_fmt_dst")
|
||||
rdst = os.path.join(TEST_DATA_DIR, "out_fmt_rdst")
|
||||
_make_output_tree(source)
|
||||
clean_dir(dest)
|
||||
clean_dir(rdst)
|
||||
fmt = "%n %l"
|
||||
rsync_result = _rsync(["-a", "--out-format=" + fmt, source + "/", rdst + "/"])
|
||||
assert rsync_result.returncode == 0, rsync_result.stderr
|
||||
rsync_lines = sorted(
|
||||
line for line in rsync_result.stdout.splitlines()
|
||||
if line and not line.split(" ", 1)[0].endswith("/")
|
||||
)
|
||||
result, _ = run_client(source, dest,
|
||||
flags=["-a", "--out-format=" + fmt],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, result.stderr[:300]
|
||||
fast_lines = sorted(
|
||||
line for line in result.stdout.splitlines()
|
||||
if line and not line.split(" ", 1)[0].endswith("/")
|
||||
)
|
||||
assert fast_lines == rsync_lines, f"rsync={rsync_lines} fastsync={fast_lines}"
|
||||
|
||||
@requires_rsync
|
||||
@pytest.mark.ci
|
||||
def test_out_format_M_datetime_shape(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_M_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_M_dst")
|
||||
_make_output_tree(source)
|
||||
clean_dir(dest)
|
||||
result, _ = run_client(source, dest,
|
||||
flags=["-a", "--out-format=%M %f"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, result.stderr[:300]
|
||||
import re
|
||||
pattern = re.compile(r"^\d{4}/\d{2}/\d{2}-\d{2}:\d{2}:\d{2} ")
|
||||
for line in result.stdout.splitlines():
|
||||
if line:
|
||||
assert pattern.match(line), f"bad %M format: {line!r}"
|
||||
|
||||
|
||||
class TestListOnlyParity:
|
||||
@requires_rsync
|
||||
@pytest.mark.ci
|
||||
def test_list_only_matches_rsync(self, shared_server):
|
||||
source = os.path.join(TEST_DATA_DIR, "out_list_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "out_list_dst")
|
||||
_make_output_tree(source)
|
||||
clean_dir(dest)
|
||||
rsync_result = _rsync(["-r", "--list-only", source + "/"])
|
||||
assert rsync_result.returncode == 0, rsync_result.stderr
|
||||
rsync_lines = sorted(rsync_result.stdout.splitlines())
|
||||
result, _ = run_client(source, dest, flags=["--list-only", "-l"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, result.stderr[:300]
|
||||
fast_lines = sorted(result.stdout.splitlines())
|
||||
assert fast_lines == rsync_lines, (
|
||||
f"rsync={rsync_lines}\nfastsync={fast_lines}"
|
||||
)
|
||||
@@ -94,14 +94,14 @@ def _seed_protocol_source(source):
|
||||
class TestProtocol:
|
||||
@pytest.mark.ci
|
||||
def test_protocol_current_version_accepted(self, shared_server):
|
||||
"""--protocol=2.22.0 (the current PROTOCOL_VERSION) is accepted and the
|
||||
"""--protocol=2.23.0 (the current PROTOCOL_VERSION) is accepted and the
|
||||
transfer completes normally."""
|
||||
source = os.path.join(TEST_DATA_DIR, "proto_ok_src")
|
||||
dest = os.path.join(TEST_DATA_DIR, "proto_ok_dst")
|
||||
shutil.rmtree(dest, ignore_errors=True)
|
||||
os.makedirs(dest)
|
||||
_seed_protocol_source(source)
|
||||
result, _ = run_client(source, dest, flags=["--protocol=2.22.0"],
|
||||
result, _ = run_client(source, dest, flags=["--protocol=2.23.0"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode == 0, \
|
||||
f"--protocol current run failed: {(result.stderr or result.stdout)[:400]}"
|
||||
@@ -118,8 +118,8 @@ class TestProtocol:
|
||||
shutil.rmtree(dest, ignore_errors=True)
|
||||
os.makedirs(dest)
|
||||
_seed_protocol_source(source)
|
||||
for bad in ("2.21.0", "2.20.0", "2.19.0", "2.18.0", "2.17.0", "2.15.0", "2.16.0", "216",
|
||||
"31"):
|
||||
for bad in ("2.22.0", "2.21.0", "2.20.0", "2.19.0", "2.18.0", "2.17.0", "2.15.0", "2.16.0",
|
||||
"216", "31"):
|
||||
result, _ = run_client(source, dest, flags=[f"--protocol={bad}"],
|
||||
port=shared_server.port)
|
||||
assert result.returncode != 0, f"--protocol={bad} should be rejected"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "test_file.h"
|
||||
#include "test_file_list.h"
|
||||
#include "test_file_sendfile.h"
|
||||
#include "test_format.h"
|
||||
#include "test_fuzz_smoke.h"
|
||||
#include "test_glob.h"
|
||||
#include "test_hardlink.h"
|
||||
@@ -58,6 +59,7 @@ int main() {
|
||||
RUN_TEST(test_chunk);
|
||||
RUN_TEST(test_batch);
|
||||
RUN_TEST(test_change_list);
|
||||
RUN_TEST(test_format);
|
||||
RUN_TEST(test_config);
|
||||
RUN_TEST(test_credentials);
|
||||
RUN_TEST(test_compression);
|
||||
|
||||
+106
-16
@@ -1,5 +1,6 @@
|
||||
#include "test_change_list.h"
|
||||
#include "change_list.h"
|
||||
#include "config.h"
|
||||
#include "test_utils.h"
|
||||
#include "utils.h"
|
||||
#include <stdlib.h>
|
||||
@@ -9,64 +10,150 @@
|
||||
static ChangeEvent sample_event(void) {
|
||||
ChangeEvent event;
|
||||
memset(&event, 0, sizeof(event));
|
||||
event.path = "/srv/root/sub/file.txt";
|
||||
event.path = "src/sub/file.txt";
|
||||
event.name = "sub/file.txt";
|
||||
event.decision = CHANGE_SENT;
|
||||
event.is_directory = false;
|
||||
event.size = 12345;
|
||||
event.bytes_sent = 999;
|
||||
event.mtime_sec = 1700000000;
|
||||
event.mtime_nsec = 0;
|
||||
event.mode = 0100644;
|
||||
event.uid = 1000;
|
||||
event.gid = 1000;
|
||||
return event;
|
||||
}
|
||||
|
||||
/* Expected %M expansion computed independently with localtime_r. */
|
||||
static void expected_mtime(time_t when, char out[32]) {
|
||||
struct tm broken_down;
|
||||
localtime_r(&when, &broken_down);
|
||||
strftime(out, 32, "%Y/%m/%d-%H:%M:%S", &broken_down);
|
||||
}
|
||||
|
||||
static void test_format_tokens() {
|
||||
ChangeEvent event = sample_event();
|
||||
char* line = change_render_format("%f %n %l %b %M %%", &event);
|
||||
Config* config = config_create();
|
||||
char when[32];
|
||||
expected_mtime(event.mtime_sec, when);
|
||||
char* line = change_render_format("%f %n %l %b %M %%", config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, "/srv/root/sub/file.txt file.txt 12345 999 1700000000 %");
|
||||
char expected[256];
|
||||
snprintf(expected, sizeof(expected), "src/sub/file.txt sub/file.txt 12345 999 %s %%", when);
|
||||
EXPECT_EQ_STR(line, expected);
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_format_unknown_tokens_preserved() {
|
||||
ChangeEvent event = sample_event();
|
||||
char* line = change_render_format("x%q=%f%z", &event);
|
||||
Config* config = config_create();
|
||||
char* line = change_render_format("x%q=%f%z", config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, "x%q=/srv/root/sub/file.txt%z");
|
||||
EXPECT_EQ_STR(line, "x%q=src/sub/file.txt%z");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_format_leaf_name() {
|
||||
static void test_format_directory_name_has_trailing_slash() {
|
||||
ChangeEvent event = sample_event();
|
||||
event.path = "bare.txt";
|
||||
char* line = change_render_format("%n|%f", &event);
|
||||
event.is_directory = true;
|
||||
event.path = "src/sub";
|
||||
event.name = "sub";
|
||||
Config* config = config_create();
|
||||
char* line = change_render_format("%n|%f", config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, "bare.txt|bare.txt");
|
||||
EXPECT_EQ_STR(line, "sub/|src/sub");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_render_itemize_sent_file() {
|
||||
ChangeEvent event = sample_event();
|
||||
char* line = change_render_itemize(&event);
|
||||
Config* config = config_create();
|
||||
char* line = change_render_itemize(config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, ">f+++++++++ /srv/root/sub/file.txt");
|
||||
EXPECT_EQ_STR(line, ">f+++++++++ sub/file.txt");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_render_itemize_directory() {
|
||||
ChangeEvent event = sample_event();
|
||||
event.is_directory = true;
|
||||
event.path = "src/sub";
|
||||
event.name = "sub";
|
||||
Config* config = config_create();
|
||||
char* line = change_render_itemize(config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, "cd+++++++++ sub/");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_render_itemize_symlink() {
|
||||
ChangeEvent event = sample_event();
|
||||
event.is_symlink = true;
|
||||
event.path = "src/link";
|
||||
event.name = "link";
|
||||
event.symlink_target = "a.txt";
|
||||
Config* config = config_create();
|
||||
char* line = change_render_itemize(config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, "cL+++++++++ link -> a.txt");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_render_itemize_compares_destination() {
|
||||
ChangeEvent event = sample_event();
|
||||
Config* config = config_create();
|
||||
config->preserve_perms = true;
|
||||
config->preserve_owner = true;
|
||||
config->preserve_group = true;
|
||||
event.dest.known = true;
|
||||
event.dest.existed = true;
|
||||
event.dest.size = 1;
|
||||
event.dest.mtime_sec = 1700000000;
|
||||
event.dest.mtime_nsec = 0;
|
||||
event.dest.mode = 0100600;
|
||||
event.dest.uid = 1;
|
||||
event.dest.gid = 2;
|
||||
char* line = change_render_itemize(config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
/* size, perms, owner and group differ; time matches. */
|
||||
EXPECT_EQ_STR(line, ">f.s.pog... sub/file.txt");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_render_itemize_up_to_date_is_empty() {
|
||||
ChangeEvent event = sample_event();
|
||||
Config* config = config_create();
|
||||
event.decision = CHANGE_UP_TO_DATE;
|
||||
char* line = change_render_itemize(&event);
|
||||
char* line = change_render_itemize(config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_EQ_STR(line, "");
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_render_list_line() {
|
||||
char* line = change_render_list_line(0100644, 4096, 1700000000, "/srv/x.txt");
|
||||
ChangeEvent event;
|
||||
memset(&event, 0, sizeof(event));
|
||||
Config* config = config_create();
|
||||
event.name = "sub/x.txt";
|
||||
event.path = "sub/x.txt";
|
||||
event.mode = 0100644;
|
||||
event.size = 4096;
|
||||
event.mtime_sec = 1700000000;
|
||||
char* line = change_render_list_line(config, &event);
|
||||
EXPECT_NOT_NULL(line);
|
||||
EXPECT_TRUE(strncmp(line, "-rw-r--r--", 10) == 0);
|
||||
EXPECT_TRUE(strstr(line, "4096") != NULL);
|
||||
EXPECT_TRUE(strstr(line, "/srv/x.txt") != NULL);
|
||||
EXPECT_TRUE(strstr(line, "4,096") != NULL);
|
||||
EXPECT_TRUE(strstr(line, "sub/x.txt") != NULL);
|
||||
free(line);
|
||||
config_delete(config);
|
||||
}
|
||||
|
||||
static void test_change_list_enabled() {
|
||||
@@ -93,8 +180,11 @@ static void test_change_list_enabled() {
|
||||
void test_change_list() {
|
||||
test_format_tokens();
|
||||
test_format_unknown_tokens_preserved();
|
||||
test_format_leaf_name();
|
||||
test_format_directory_name_has_trailing_slash();
|
||||
test_render_itemize_sent_file();
|
||||
test_render_itemize_directory();
|
||||
test_render_itemize_symlink();
|
||||
test_render_itemize_compares_destination();
|
||||
test_render_itemize_up_to_date_is_empty();
|
||||
test_render_list_line();
|
||||
test_change_list_enabled();
|
||||
|
||||
+46
-4
@@ -317,7 +317,7 @@ static void test_parse_args_protocol_accept_current() {
|
||||
Config* cfg = valid_client_config();
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
char* argv_equals[] = {"fastsync", "--source-dir", "/src",
|
||||
"--dest-dir", "/dst", "--protocol=2.22.0"};
|
||||
"--dest-dir", "/dst", "--protocol=2.23.0"};
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
EXPECT_EQ_INT(parse_args(cfg, 6, argv_equals, positional_args, &positional_count), 0);
|
||||
@@ -327,7 +327,7 @@ static void test_parse_args_protocol_accept_current() {
|
||||
cfg = valid_client_config();
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
char* argv_space[] = {"fastsync", "--source-dir", "/src", "--dest-dir",
|
||||
"/dst", "--protocol", "2.22.0"};
|
||||
"/dst", "--protocol", "2.23.0"};
|
||||
positional_count = 0;
|
||||
EXPECT_EQ_INT(parse_args(cfg, 7, argv_space, positional_args, &positional_count), 0);
|
||||
EXPECT_EQ_STR(cfg->version, PROTOCOL_VERSION);
|
||||
@@ -338,8 +338,8 @@ static void test_parse_args_protocol_accept_current() {
|
||||
* failure (parse_args simply stores it; validate_config rejects it up front). */
|
||||
static void test_parse_args_protocol_rejects_other_versions() {
|
||||
static const char* const bad_versions[] = {"2.17", "2.16", "2.15.0", "2.16.0", "2.17.0",
|
||||
"2.18.0", "2.19.0", "2.20.0", "2.21.0", "216",
|
||||
"31", "abc", ""};
|
||||
"2.18.0", "2.19.0", "2.20.0", "2.21.0", "2.22.0",
|
||||
"216", "31", "abc", ""};
|
||||
for (size_t i = 0; i < sizeof(bad_versions) / sizeof(bad_versions[0]); i++) {
|
||||
Config* cfg = valid_client_config();
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
@@ -3729,6 +3729,12 @@ static void test_parse_args_inline_equals_forms() {
|
||||
EXPECT_EQ_STR(cfg->exclude_patterns[0], "*.log");
|
||||
EXPECT_EQ_INT(cfg->include_count, 1);
|
||||
EXPECT_EQ_STR(cfg->include_patterns[0], "*.txt");
|
||||
/* The same patterns are compiled, in command-line order, into the shared
|
||||
* ordered --filter rule list (rsync first-match-wins). */
|
||||
EXPECT_NOT_NULL(cfg->filters);
|
||||
EXPECT_EQ_INT(cfg->filters->size, 2);
|
||||
EXPECT_EQ_STR((char*)cfg->filters->items[0], "- *.log");
|
||||
EXPECT_EQ_STR((char*)cfg->filters->items[1], "+ *.txt");
|
||||
config_delete(cfg);
|
||||
|
||||
const char* list_path = "cli_inline_patterns.txt";
|
||||
@@ -3776,6 +3782,41 @@ static void test_parse_args_inline_equals_forms() {
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
/* --exclude/--include compile into the SAME ordered filter list as --filter, so
|
||||
* rsync's first-match-wins semantics hold: the common `--include='*.txt'
|
||||
* --exclude='*'` idiom keeps the .txt files and drops the rest, and an
|
||||
* --include rule with no matching exclude is not a mandatory whitelist. */
|
||||
static void test_parse_args_include_exclude_order() {
|
||||
Config* cfg = config_create();
|
||||
int positional_args[2];
|
||||
int positional_count = 0;
|
||||
char* argv[] = {"fastsync", "--include=*.txt", "--exclude=*", "/src", "/dst"};
|
||||
EXPECT_EQ_INT(parse_args(cfg, 5, argv, positional_args, &positional_count), 0);
|
||||
EXPECT_NOT_NULL(cfg->filters);
|
||||
EXPECT_EQ_INT(cfg->filters->size, 2);
|
||||
EXPECT_EQ_STR((char*)cfg->filters->items[0], "+ *.txt");
|
||||
EXPECT_EQ_STR((char*)cfg->filters->items[1], "- *");
|
||||
/* The order is reversible on the command line and the list follows it. */
|
||||
Config* cfg2 = config_create();
|
||||
positional_count = 0;
|
||||
char* argv2[] = {"fastsync", "--exclude=*", "--include=*.txt", "/src", "/dst"};
|
||||
EXPECT_EQ_INT(parse_args(cfg2, 5, argv2, positional_args, &positional_count), 0);
|
||||
EXPECT_EQ_INT(cfg2->filters->size, 2);
|
||||
EXPECT_EQ_STR((char*)cfg2->filters->items[0], "- *");
|
||||
EXPECT_EQ_STR((char*)cfg2->filters->items[1], "+ *.txt");
|
||||
/* --filter and --exclude/--include interleave in command-line order. */
|
||||
Config* cfg3 = config_create();
|
||||
positional_count = 0;
|
||||
char* argv3[] = {"fastsync", "--filter=- *.tmp", "--include=*.txt", "/src", "/dst"};
|
||||
EXPECT_EQ_INT(parse_args(cfg3, 5, argv3, positional_args, &positional_count), 0);
|
||||
EXPECT_EQ_INT(cfg3->filters->size, 2);
|
||||
EXPECT_EQ_STR((char*)cfg3->filters->items[0], "- *.tmp");
|
||||
EXPECT_EQ_STR((char*)cfg3->filters->items[1], "+ *.txt");
|
||||
config_delete(cfg);
|
||||
config_delete(cfg2);
|
||||
config_delete(cfg3);
|
||||
}
|
||||
|
||||
/* OPT_NOOP compatibility flags (-s/--secluded-args, -r/--recursive) must never
|
||||
* swallow the next argv: `fastsync -s SRC DST` keeps both positionals. */
|
||||
static void test_parse_args_noop_does_not_consume_argv() {
|
||||
@@ -4003,6 +4044,7 @@ void test_client_cli() {
|
||||
test_parse_args_short_clustering();
|
||||
test_parse_args_attached_short_values();
|
||||
test_parse_args_inline_equals_forms();
|
||||
test_parse_args_include_exclude_order();
|
||||
test_parse_args_noop_does_not_consume_argv();
|
||||
test_parse_args_backup_copy_links_shorts();
|
||||
test_parse_args_rejects_unsupported_short();
|
||||
|
||||
+7
-8
@@ -2665,14 +2665,13 @@ static void golden_config_populate(Config* c) {
|
||||
c->copy_as_gid = 222;
|
||||
}
|
||||
|
||||
/* The pinned golden frame (protocol 2.22.0). The values below are the only
|
||||
/* The pinned golden frame (protocol 2.23.0). The values below are the only
|
||||
* thing that ties the generated table to the historical wire format; update
|
||||
* them ONLY with a PROTOCOL_VERSION bump and a documented reason. The 2.22.0
|
||||
* preserve-attribute split appends four serialized bools
|
||||
* (preserve_perms/times/owner/group) to CONFIG_WIRE_METADATA_TIMES_FIELDS after
|
||||
* omit_link_times. */
|
||||
#define GOLDEN_WIRE_LEN 653
|
||||
#define GOLDEN_WIRE_HASH 95530566005420798ULL
|
||||
* them ONLY with a PROTOCOL_VERSION bump and a documented reason. The 2.23.0
|
||||
* output-parity wave appends one serialized bool (report_dest_info) to the end
|
||||
* of the frame, after the --copy-as block. */
|
||||
#define GOLDEN_WIRE_LEN 657
|
||||
#define GOLDEN_WIRE_HASH 4633069702262438591ULL
|
||||
|
||||
static unsigned long long fnv1a_64(const unsigned char* buf, size_t len) {
|
||||
unsigned long long h = 1469598103934665603ULL;
|
||||
@@ -2754,7 +2753,7 @@ static unsigned long long capture_wire_hash(const Config* cfg, size_t* out_len)
|
||||
return h;
|
||||
}
|
||||
|
||||
/* Byte-for-byte wire compatibility guard (protocol 2.22.0). The expected hash
|
||||
/* Byte-for-byte wire compatibility guard (protocol 2.23.0). The expected hash
|
||||
* pins the pre-X-macro byte stream; the refactor MUST NOT change it. */
|
||||
static void test_config_wire_golden() {
|
||||
if (is_running_under_valgrind())
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "test_format.h"
|
||||
#include "format.h"
|
||||
#include "test_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void expect_big_num(unsigned long long value, bool human, const char* expected) {
|
||||
char buffer[64];
|
||||
EXPECT_TRUE(format_big_num(value, human, buffer, sizeof(buffer)));
|
||||
EXPECT_EQ_STR(buffer, expected);
|
||||
}
|
||||
|
||||
static void test_human_size_decimal() {
|
||||
/* Values below 1000 print verbatim; larger values use the largest unit that
|
||||
* keeps the value below 1000 and exactly two decimals (rsync human_num). */
|
||||
expect_big_num(0, true, "0");
|
||||
expect_big_num(999, true, "999");
|
||||
expect_big_num(1000, true, "1.00K");
|
||||
expect_big_num(1500, true, "1.50K");
|
||||
expect_big_num(9999, true, "10.00K");
|
||||
expect_big_num(999999, true, "1000.00K");
|
||||
expect_big_num(1000000, true, "1.00M");
|
||||
expect_big_num(1500000, true, "1.50M");
|
||||
}
|
||||
|
||||
static void test_big_num_grouping() {
|
||||
/* Non-human numbers are comma-grouped every three digits (rsync big_num). */
|
||||
expect_big_num(0, false, "0");
|
||||
expect_big_num(1, false, "1");
|
||||
expect_big_num(999, false, "999");
|
||||
expect_big_num(1000, false, "1,000");
|
||||
expect_big_num(4096, false, "4,096");
|
||||
expect_big_num(1234567, false, "1,234,567");
|
||||
expect_big_num(1000000000ULL, false, "1,000,000,000");
|
||||
}
|
||||
|
||||
static void test_datetime_format() {
|
||||
char buffer[32];
|
||||
time_t when = 1700000000;
|
||||
EXPECT_TRUE(format_rsync_datetime(when, true, buffer, sizeof(buffer)));
|
||||
/* %M shape: YYYY/MM/DD-HH:MM:SS */
|
||||
EXPECT_EQ_INT(strlen(buffer), 19);
|
||||
EXPECT_EQ_INT(buffer[4], '/');
|
||||
EXPECT_EQ_INT(buffer[7], '/');
|
||||
EXPECT_EQ_INT(buffer[10], '-');
|
||||
EXPECT_EQ_INT(buffer[13], ':');
|
||||
EXPECT_EQ_INT(buffer[16], ':');
|
||||
|
||||
char space_form[32];
|
||||
EXPECT_TRUE(format_rsync_datetime(when, false, space_form, sizeof(space_form)));
|
||||
EXPECT_EQ_INT(space_form[10], ' ');
|
||||
}
|
||||
|
||||
static void test_dest_state_roundtrip() {
|
||||
/* The wire codec is exercised over a socketpair so the real send/receive
|
||||
* primitives run. */
|
||||
int fds[2];
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0)
|
||||
return;
|
||||
OutputDestState out;
|
||||
memset(&out, 0, sizeof(out));
|
||||
out.known = true;
|
||||
out.existed = true;
|
||||
out.size = 123456789ULL;
|
||||
out.mtime_sec = 1700000000;
|
||||
out.mtime_nsec = 123456789;
|
||||
out.mode = 0100644;
|
||||
out.uid = 1000;
|
||||
out.gid = 1000;
|
||||
OutputDestState in;
|
||||
memset(&in, 0, sizeof(in));
|
||||
EXPECT_TRUE(format_dest_state_send(fds[0], &out));
|
||||
EXPECT_TRUE(format_dest_state_receive(fds[1], &in));
|
||||
EXPECT_TRUE(in.known);
|
||||
EXPECT_TRUE(in.existed);
|
||||
EXPECT_TRUE(in.size == out.size);
|
||||
EXPECT_TRUE(in.mtime_sec == out.mtime_sec);
|
||||
EXPECT_TRUE(in.mtime_nsec == out.mtime_nsec);
|
||||
EXPECT_TRUE(in.mode == out.mode);
|
||||
EXPECT_TRUE(in.uid == out.uid);
|
||||
EXPECT_TRUE(in.gid == out.gid);
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
}
|
||||
|
||||
void test_format(void) {
|
||||
test_human_size_decimal();
|
||||
test_big_num_grouping();
|
||||
test_datetime_format();
|
||||
test_dest_state_roundtrip();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef TEST_FORMAT_H
|
||||
#define TEST_FORMAT_H
|
||||
|
||||
void test_format(void);
|
||||
|
||||
#endif
|
||||
+14
-11
@@ -18,6 +18,9 @@
|
||||
|
||||
/* P8 config-frame tail: super_mode (4) + copy-as presence (4) + uid (4) + gid (4). */
|
||||
#define P8_TAIL_BYTES 16
|
||||
/* Protocol 2.23.0 appends one trailing bool (report_dest_info) AFTER the P8
|
||||
* tail, so the P8 fields sit this many bytes before the end of the frame. */
|
||||
#define OUTPUT_TAIL_BYTES 4
|
||||
|
||||
/* Smoke test for chunk_deserialize fuzz target */
|
||||
static void test_fuzz_chunk_deserialize() {
|
||||
@@ -334,31 +337,31 @@ static void test_fuzz_config_receive_p8_tail() {
|
||||
|
||||
/* super_mode outside the 0..2 tri-state is refused. */
|
||||
memcpy(mut, frame, len);
|
||||
put_i32(mut, len - P8_TAIL_BYTES, 99);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES, 99);
|
||||
EXPECT_FALSE(receive_config_frame(mut, len));
|
||||
put_i32(mut, len - P8_TAIL_BYTES, -1);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES, -1);
|
||||
EXPECT_FALSE(receive_config_frame(mut, len));
|
||||
|
||||
/* A negative (sentinel) and an extreme copy-as uid/gid are refused. */
|
||||
memcpy(mut, frame, len);
|
||||
put_i32(mut, len - P8_TAIL_BYTES, SUPER_MODE_AUTO);
|
||||
put_i32(mut, len - P8_TAIL_BYTES + 4, 1);
|
||||
put_i32(mut, len - P8_TAIL_BYTES + 8, -1);
|
||||
put_i32(mut, len - P8_TAIL_BYTES + 12, 0);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES, SUPER_MODE_AUTO);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES + 4, 1);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES + 8, -1);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES + 12, 0);
|
||||
EXPECT_FALSE(receive_config_frame(mut, len));
|
||||
put_i32(mut, len - P8_TAIL_BYTES + 8, 0);
|
||||
put_i32(mut, len - P8_TAIL_BYTES + 12, INT32_MIN);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES + 8, 0);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES + 12, INT32_MIN);
|
||||
EXPECT_FALSE(receive_config_frame(mut, len));
|
||||
|
||||
/* A presence int that is not a wire bool is refused. */
|
||||
memcpy(mut, frame, len);
|
||||
put_i32(mut, len - P8_TAIL_BYTES, SUPER_MODE_AUTO);
|
||||
put_i32(mut, len - P8_TAIL_BYTES + 4, 2);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES, SUPER_MODE_AUTO);
|
||||
put_i32(mut, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES + 4, 2);
|
||||
EXPECT_FALSE(receive_config_frame(mut, len));
|
||||
|
||||
/* Truncating anywhere inside the P8 tail is refused. */
|
||||
EXPECT_FALSE(receive_config_frame(frame, len - 2));
|
||||
EXPECT_FALSE(receive_config_frame(frame, len - P8_TAIL_BYTES));
|
||||
EXPECT_FALSE(receive_config_frame(frame, len - OUTPUT_TAIL_BYTES - P8_TAIL_BYTES));
|
||||
|
||||
free(mut);
|
||||
free(frame);
|
||||
|
||||
+34
-3
@@ -644,17 +644,19 @@ static void test_scanner_one_file_system_cross_device() {
|
||||
EXPECT_EQ_INT(seq_off_rc, 0);
|
||||
EXPECT_TRUE(seq_off_found);
|
||||
EXPECT_EQ_INT(seq_off_total, 2);
|
||||
/* Sequential: with -x the cross-device subtree is dropped, keep.txt remains. */
|
||||
/* Sequential: with -x the cross-device subtree is not descended into, but
|
||||
* rsync-compatible behavior still emits the mount-point directory entry as an
|
||||
* empty directory File, so keep.txt plus that entry are present. */
|
||||
EXPECT_EQ_INT(seq_on_rc, 0);
|
||||
EXPECT_FALSE(seq_on_found);
|
||||
EXPECT_EQ_INT(seq_on_total, 1);
|
||||
EXPECT_EQ_INT(seq_on_total, 2);
|
||||
/* Parallel: same behavior, worker path (depth > 1). */
|
||||
EXPECT_EQ_INT(par_off_rc, 0);
|
||||
EXPECT_TRUE(par_off_found);
|
||||
EXPECT_EQ_INT(par_off_total, 2);
|
||||
EXPECT_EQ_INT(par_on_rc, 0);
|
||||
EXPECT_FALSE(par_on_found);
|
||||
EXPECT_EQ_INT(par_on_total, 1);
|
||||
EXPECT_EQ_INT(par_on_total, 2);
|
||||
}
|
||||
|
||||
/* Collect emitted file paths (relative to `root`) from a sequential scan.
|
||||
@@ -884,6 +886,35 @@ static void test_filter_rules(bool parallel) {
|
||||
free_paths(paths, count);
|
||||
filter_rule_list_free(base);
|
||||
|
||||
/* The common include idiom (the exact rule order the CLI compiles from
|
||||
* --include='*.txt' --exclude='*'): only .txt files survive. */
|
||||
const char* idiom[] = {"+ *.txt", "- *"};
|
||||
base = filter_base_build(idiom, 2, false, err, sizeof(err));
|
||||
EXPECT_NOT_NULL(base);
|
||||
options.base_filters = base;
|
||||
rc = parallel ? collect_files_parallel(root, &options, &paths, &count)
|
||||
: collect_files(root, &options, &paths, &count);
|
||||
EXPECT_EQ_INT(rc, 0);
|
||||
EXPECT_EQ_INT(count, 2);
|
||||
EXPECT_TRUE(has_path(paths, count, "a.txt"));
|
||||
EXPECT_TRUE(has_path(paths, count, "c.txt"));
|
||||
EXPECT_FALSE(has_path(paths, count, "b.tmp"));
|
||||
free_paths(paths, count);
|
||||
filter_rule_list_free(base);
|
||||
|
||||
/* An include rule alone is NOT a mandatory whitelist (rsync semantics): only
|
||||
* the matching file is affected, everything else is still transferred. */
|
||||
const char* include_alone[] = {"+ *.txt"};
|
||||
base = filter_base_build(include_alone, 1, false, err, sizeof(err));
|
||||
EXPECT_NOT_NULL(base);
|
||||
options.base_filters = base;
|
||||
rc = parallel ? collect_files_parallel(root, &options, &paths, &count)
|
||||
: collect_files(root, &options, &paths, &count);
|
||||
EXPECT_EQ_INT(rc, 0);
|
||||
EXPECT_EQ_INT(count, 3);
|
||||
free_paths(paths, count);
|
||||
filter_rule_list_free(base);
|
||||
|
||||
unlink("test_scan_filter/a.txt");
|
||||
unlink("test_scan_filter/b.tmp");
|
||||
unlink("test_scan_filter/c.txt");
|
||||
|
||||
Reference in New Issue
Block a user