Debian Codegraph @

testsuite/chgrp_test.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Python rewrite of testsuite/chgrp.test.
3 #
4 # Test that -g preserves group ownership when the user is a member of the
5 # target group. Creates one file per supplementary group, chgrps each,
6 # then verifies the destination listing matches.
7
8 import os
9 import shutil
10 import time
11
12 from rsyncfns import FROMDIR, TODIR, checkit, rsync_getgroups, test_fail
13
14
15 groups = rsync_getgroups()
16 if not groups:
17 test_fail("Can't get groups")
18
19 FROMDIR.mkdir(parents=True, exist_ok=True)
20 for g in groups:
21 fname = FROMDIR / f'foo-{g}'
22 fname.write_text(time.ctime() + '\n')
23 chgrp = shutil.which('chgrp')
24 if chgrp is None:
25 test_fail("chgrp not found in PATH")
26 # The shell test treats chgrp failure as fatal.
27 try:
28 os.chown(fname, -1, int(g))
29 except (ValueError, PermissionError):
30 # If g isn't numeric or we lack permission, fall back to chgrp(1).
31 import subprocess
32 proc = subprocess.run([chgrp, g, str(fname)])
33 if proc.returncode != 0:
34 test_fail("Can't chgrp")
35
36 time.sleep(2)
37
38 checkit(['-rtgpvvv', f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)