Allow transferring files outside of HOME
This commit is contained in:
parent
4b6bfaffba
commit
8867317b6a
@ -75,7 +75,8 @@ def get_arcname(loc: str, dest: Optional[str], home: str) -> str:
|
|||||||
if arcname.startswith(home):
|
if arcname.startswith(home):
|
||||||
arcname = os.path.relpath(arcname, home)
|
arcname = os.path.relpath(arcname, home)
|
||||||
arcname = os.path.normpath(arcname).replace(os.sep, '/')
|
arcname = os.path.normpath(arcname).replace(os.sep, '/')
|
||||||
return arcname
|
prefix = 'root' if arcname.startswith('/') else 'home/'
|
||||||
|
return prefix + arcname
|
||||||
|
|
||||||
|
|
||||||
class CopyInstruction(NamedTuple):
|
class CopyInstruction(NamedTuple):
|
||||||
|
|||||||
@ -100,11 +100,11 @@ def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str]) -> bytes:
|
|||||||
rd = ssh_opts.remote_dir.rstrip('/')
|
rd = ssh_opts.remote_dir.rstrip('/')
|
||||||
for location, ci in ssh_opts.copy.items():
|
for location, ci in ssh_opts.copy.items():
|
||||||
tf.add(location, arcname=ci.arcname, filter=filter_from_globs(*ci.exclude_patterns))
|
tf.add(location, arcname=ci.arcname, filter=filter_from_globs(*ci.exclude_patterns))
|
||||||
add_data_as_file(tf, 'kitty-ssh-kitten-data.sh', env_script)
|
add_data_as_file(tf, 'data.sh', env_script)
|
||||||
if ksi:
|
if ksi:
|
||||||
arcname = rd + '/shell-integration'
|
arcname = 'home/' + rd + '/shell-integration'
|
||||||
tf.add(shell_integration_dir, arcname=arcname, filter=filter_from_globs(f'{arcname}/ssh/bootstrap.*'))
|
tf.add(shell_integration_dir, arcname=arcname, filter=filter_from_globs(f'{arcname}/ssh/bootstrap.*'))
|
||||||
tf.add(terminfo_dir, arcname='.terminfo', filter=normalize_tarinfo)
|
tf.add(terminfo_dir, arcname='home/.terminfo', filter=normalize_tarinfo)
|
||||||
return buf.getvalue()
|
return buf.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -48,10 +48,7 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
|
|
||||||
def test_ssh_config_parsing(self):
|
def test_ssh_config_parsing(self):
|
||||||
def parse(conf):
|
def parse(conf):
|
||||||
with tempfile.NamedTemporaryFile(suffix='test.conf') as cf:
|
return load_config(overrides=conf.splitlines())
|
||||||
cf.write(conf.encode('utf-8'))
|
|
||||||
cf.flush()
|
|
||||||
return load_config(cf.name)
|
|
||||||
|
|
||||||
def for_host(hostname, conf):
|
def for_host(hostname, conf):
|
||||||
if isinstance(conf, str):
|
if isinstance(conf, str):
|
||||||
@ -72,6 +69,9 @@ print(' '.join(map(str, buf)))'''), lines=13, cols=77)
|
|||||||
def all_possible_sh(self):
|
def all_possible_sh(self):
|
||||||
return tuple(sh for sh in ('dash', 'zsh', 'bash', 'posh', 'sh') if shutil.which(sh))
|
return tuple(sh for sh in ('dash', 'zsh', 'bash', 'posh', 'sh') if shutil.which(sh))
|
||||||
|
|
||||||
|
def test_ssh_copy(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def test_ssh_env_vars(self):
|
def test_ssh_env_vars(self):
|
||||||
for sh in self.all_possible_sh:
|
for sh in self.all_possible_sh:
|
||||||
with self.subTest(sh=sh), tempfile.TemporaryDirectory() as tdir:
|
with self.subTest(sh=sh), tempfile.TemporaryDirectory() as tdir:
|
||||||
|
|||||||
@ -37,6 +37,14 @@ leading_data=""
|
|||||||
dsc_to_kitty "ssh" "hostname=$hostname:pwfile=$password_filename:pw=$data_password"
|
dsc_to_kitty "ssh" "hostname=$hostname:pwfile=$password_filename:pw=$data_password"
|
||||||
record_separator=$(printf "\036")
|
record_separator=$(printf "\036")
|
||||||
|
|
||||||
|
mv_files_and_dirs() {
|
||||||
|
cwd="$PWD";
|
||||||
|
cd "$1";
|
||||||
|
command find . -type d -exec mkdir -p "$2/{}" ";"
|
||||||
|
command find . -type f -exec mv "{}" "$2/{}" ";"
|
||||||
|
cd "$cwd";
|
||||||
|
}
|
||||||
|
|
||||||
untar_and_read_env() {
|
untar_and_read_env() {
|
||||||
# extract the tar file atomically, in the sense that any file from the
|
# extract the tar file atomically, in the sense that any file from the
|
||||||
# tarfile is only put into place after it has been fully written to disk
|
# tarfile is only put into place after it has been fully written to disk
|
||||||
@ -47,15 +55,11 @@ untar_and_read_env() {
|
|||||||
# does not limit itself to reading -c bytes only from the pipe so we can potentially lose
|
# does not limit itself to reading -c bytes only from the pipe so we can potentially lose
|
||||||
# some trailing data, for instance if the user starts typing. Cant be helped.
|
# some trailing data, for instance if the user starts typing. Cant be helped.
|
||||||
command head -c "$1" < /dev/tty | command base64 -d | command tar xjf - --no-same-owner -C "$tdir";
|
command head -c "$1" < /dev/tty | command base64 -d | command tar xjf - --no-same-owner -C "$tdir";
|
||||||
data_file="$tdir/kitty-ssh-kitten-data.sh";
|
data_file="$tdir/data.sh";
|
||||||
[ -f "$data_file" ] && . "$data_file";
|
[ -f "$data_file" ] && . "$data_file";
|
||||||
data_dir="$HOME/$KITTY_SSH_KITTEN_DATA_DIR"
|
data_dir="$HOME/$KITTY_SSH_KITTEN_DATA_DIR"
|
||||||
command rm -f "$data_file";
|
mv_files_and_dirs "$tdir/home" "$HOME"
|
||||||
cwd="$PWD";
|
[ -e "$tdir/root" ] && mv_files_and_dirs "$tdir/root" ""
|
||||||
cd "$tdir";
|
|
||||||
command find . -type d -exec mkdir -p "${HOME}/{}" ";"
|
|
||||||
command find . -type f -exec mv "{}" "${HOME}/{}" ";"
|
|
||||||
cd "$cwd";
|
|
||||||
command rm -rf "$tdir";
|
command rm -rf "$tdir";
|
||||||
[ -z "KITTY_SSH_KITTEN_DATA_DIR" ] && die "Failed to read SSH data from tty";
|
[ -z "KITTY_SSH_KITTEN_DATA_DIR" ] && die "Failed to read SSH data from tty";
|
||||||
unset KITTY_SSH_KITTEN_DATA_DIR;
|
unset KITTY_SSH_KITTEN_DATA_DIR;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user