Debian Codegraph @

testsuite/nested-socket-specials_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Regression: `rsync -a` (implies --specials via -D) of a tree with a NESTED
3 # unix socket must not fail the whole transfer on platforms that cannot create
4 # a socket in a subdirectory race-safely (no bindat(): the BSDs, macOS,
5 # Solaris). syscall.c returns EOPNOTSUPP for such a nested socket; the
6 # generator used to turn that into a transfer error (FERROR_XFER -> exit 23)
7 # where master created it via the path-based bind(). Now the socket is skipped
8 # with a warning and the rest of the transfer succeeds. On Linux the socket is
9 # created (mknodat handles it); either way the transfer exits 0 and the regular
10 # files land.
11
12 import os
13 import socket as _socket
14
15 from rsyncfns import (
16 SCRATCHDIR, assert_same, rmtree, run_rsync, test_fail, test_skipped,
17 )
18
19 base = SCRATCHDIR / 'nested-socket'
20 src = base / 'src'
21 dest = base / 'dest'
22 rmtree(base)
23 (src / 'sub').mkdir(parents=True)
24 (src / 'sub' / 'f.txt').write_text('regular\n')
25 (src / 'top.txt').write_text('top\n')
26
27 # A unix socket nested in a subdirectory (the case that returned EOPNOTSUPP).
28 # AF_UNIX sun_path is ~108 bytes, far shorter than the scratch path, so bind a
29 # short relative name from inside the dir, then restore the cwd.
30 s = _socket.socket(_socket.AF_UNIX)
31 prev = os.getcwd()
32 try:
33 os.chdir(src / 'sub')
34 s.bind('thesock')
35 except OSError as e:
36 test_skipped(f"cannot create a unix socket fixture ({e})")
37 finally:
38 try:
39 os.chdir(prev)
40 except OSError:
41 pass
42 s.close()
43
44 # -a implies --specials. Must exit 0 even where the nested socket cannot be
45 # created -- it is skipped with a warning there (RED on the unfixed branch,
46 # which exited 23 on the BSDs/macOS/Solaris).
47 run_rsync('-a', f'{src}/', f'{dest}/')
48
49 for rel in ('sub/f.txt', 'top.txt'):
50 got = dest / rel
51 if not got.is_file():
52 test_fail(f"a regular file was lost alongside the nested socket: {got}")
53 assert_same(src / rel, got, label=rel)
54
55 print("nested-socket-specials: a nested unix socket does not fail the transfer")