From 22c1b6b252061d61376ab0deabaf9a92054c0fd4 Mon Sep 17 00:00:00 2001 From: Zhizhen He Date: Fri, 23 Oct 2026 23:43:03 +0800 Subject: [PATCH] ssh: Fix chmod compatibility on macOS when merging directories --- docs/changelog.rst | 2 ++ kitty_tests/ssh.py | 35 ++++++++++++++++++++++++ shell-integration/ssh/bootstrap-utils.sh | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index b64f2557f..03c0ce66e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -346,6 +346,8 @@ Detailed list of changes directories, instead of using the permissions of the top level directory and the remote umask (:pull:`10727`) +- ssh kitten: Fix spurious chmod errors when merging copied directories on macOS + - ssh kitten: Fix hanging when re-using a shared connection that has silently died, for example, after a network change or suspend, and fix colors 16-255 being set to white with themes that do not define them (:iss:`10691`, diff --git a/kitty_tests/ssh.py b/kitty_tests/ssh.py index b47fdd115..01b9f7144 100644 --- a/kitty_tests/ssh.py +++ b/kitty_tests/ssh.py @@ -160,6 +160,41 @@ copy --exclude **/w.* --exclude **/r d1 ) self.ae(len(glob.glob(f'{remote_home}/{tname}/*/xterm-kitty')), 2) + def test_ssh_copy_directory_merge(self): + bootstrap_utils = os.path.join(kitty_base_dir, 'shell-integration', 'ssh', 'bootstrap-utils.sh') + for sh in self.all_possible_sh: + if 'python' in sh: + continue + with self.subTest(shell=sh), tempfile.TemporaryDirectory() as tdir: + src, dest = os.path.join(tdir, 'src'), os.path.join(tdir, 'dest') + name = '-private dir' + source, target = os.path.join(src, name), os.path.join(dest, name) + os.makedirs(os.path.join(source, 'nested')) + os.makedirs(target) + with open(os.path.join(source, 'nested', 'file with spaces'), 'w') as f: + f.write('copied contents') + with open(os.path.join(target, 'existing'), 'w') as f: + f.write('retained contents') + os.chmod(os.path.join(source, 'nested'), 0o750) + os.chmod(source, 0o500) + os.chmod(target, 0o710) + try: + cp = subprocess.run( + [sh, '-c', '. "$1"; mv_files_and_dirs "$2" "$3"', 'sh', bootstrap_utils, src, dest], + stdin=subprocess.DEVNULL, + capture_output=True, + text=True, + ) + self.ae(cp.returncode, 0, cp.stderr) + self.ae(cp.stderr, '') + self.ae(stat.S_IMODE(os.stat(target).st_mode), 0o710) + self.ae(stat.S_IMODE(os.stat(os.path.join(target, 'nested')).st_mode), 0o750) + for filename, data in (('nested/file with spaces', 'copied contents'), ('existing', 'retained contents')): + with open(os.path.join(target, filename)) as f: + self.ae(f.read(), data) + finally: + make_writable(tdir) + def test_ssh_copy_directory_permissions(self): dirs = { '': 0o750, diff --git a/shell-integration/ssh/bootstrap-utils.sh b/shell-integration/ssh/bootstrap-utils.sh index fbc5b2fd4..76e46687f 100644 --- a/shell-integration/ssh/bootstrap-utils.sh +++ b/shell-integration/ssh/bootstrap-utils.sh @@ -20,7 +20,7 @@ mv_files_and_dirs() { [ -d "$1/$2" ] && exit 0 command mkdir -p -- "$1/$2" fi - command chmod u+rwx -- "$2" + command chmod u+rwx "$2" exit 1' sh "$2" "{}" ";" -prune command find . -type l -exec sh -c 'tgt=$(command readlink -n "$2"); command ln -snf -- "$tgt" "$1/$2"; command rm -f -- "$2"' sh "$2" "{}" ";" command find . -type f -exec mv "{}" "$2/{}" ";"