Skip to content

Commit ea64520

Browse files
authored
syscall: skip unsupported symlink chmod (#1148)
1 parent a6b31ad commit ea64520

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎syscall.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,8 @@ int do_chmod(const char *path, mode_t mode)
18061806
code = 1;
18071807
# elif defined AT_FDCWD && defined AT_SYMLINK_NOFOLLOW
18081808
code = fchmodat(AT_FDCWD, path, mode & CHMOD_BITS, AT_SYMLINK_NOFOLLOW);
1809+
if (code < 0 && (errno == ENOTSUP || errno == EOPNOTSUPP || errno == ENOSYS))
1810+
code = 1;
18091811
# else
18101812
code = 1;
18111813
# endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import stat
5+
import struct
6+
7+
from rsyncfns import SCRATCHDIR, makepath, run_rsync, test_fail
8+
9+
source = SCRATCHDIR / 'source'
10+
destination = SCRATCHDIR / 'destination'
11+
makepath(source)
12+
makepath(destination)
13+
target = destination / 'target'
14+
target.write_text('target contents\n')
15+
target.chmod(0o640)
16+
links = [('link', 'target'), ('dangling', 'missing')]
17+
for name, link in links:
18+
os.symlink(link, source / name)
19+
20+
batch = SCRATCHDIR / 'symlinks.batch'
21+
run_rsync('-rlp', '--checksum-seed=1', f'--only-write-batch={batch}',
22+
f'{source}/', f'{destination}/')
23+
24+
# Supply BSD-style link modes without relying on the source filesystem
25+
mode = stat.S_IMODE((source / 'link').lstat().st_mode)
26+
wanted = 0o400 if mode != 0o400 else 0o755
27+
encoded_mode = struct.pack('<I', 0o120000 | mode)
28+
data = batch.read_bytes()
29+
if data.count(encoded_mode) != 1:
30+
test_fail('expected one shared symlink mode in the batch')
31+
batch.write_bytes(data.replace(encoded_mode, struct.pack('<I', 0o120000 | wanted)))
32+
33+
for _ in range(2):
34+
run_rsync('-rlp', f'--read-batch={batch}', f'{destination}/')
35+
for name, link in links:
36+
if not (destination / name).is_symlink() or os.readlink(destination / name) != link:
37+
test_fail(f'{name}: symlink was not preserved')
38+
if stat.S_IMODE(target.stat().st_mode) != 0o640 or target.read_text() != 'target contents\n':
39+
test_fail('symlink chmod changed the target')
40+
if (destination / 'missing').exists():
41+
test_fail('dangling symlink target was created')

0 commit comments

Comments
 (0)