Skip to content

Commit 675bde7

Browse files
committed
fish: Support converting systemd-nspawn paths to and from host paths
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent 69a17f2 commit 675bde7

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

fish/functions/cbl_bld_llvm_korg.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function cbl_bld_llvm_korg -d "Build (and optionally test) LLVM for kernel.org"
5959
for tc in (fd -a -d 1 -t d . $tmp_llvm_install)
6060
for src in $CBL_SRC_C/linux $CBL_SRC_C/linux-stable-$CBL_STABLE_VERSIONS
6161
if using_nspawn
62-
sd_nspawn -r 'cbl_lkt --linux-folder '(nspawn_adjust_path $src)' --llvm-prefix '(nspawn_adjust_path $tc)
62+
sd_nspawn -r 'cbl_lkt --linux-folder '(nspawn_path -c $src)' --llvm-prefix '(nspawn_path -c $tc)
6363
else if dbx_has_82a69f0
6464
dbxe -- fish -c "cbl_lkt --linux-folder $src --llvm-prefix $tc"
6565
else

fish/functions/cbl_test_kvm.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function cbl_test_kvm -d "Test KVM against a Clang built kernel with QEMU"
5656
mkdir -p $TMP_FOLDER
5757
cp -v /boot/vmlinuz-linux $TMP_FOLDER/bzImage
5858
if using_nspawn
59-
sd_nspawn -r 'kboot -a x86_64 -k '(nspawn_adjust_path $TMP_FOLDER)'/bzImage -t 30s'
59+
sd_nspawn -r 'kboot -a x86_64 -k '(nspawn_path -c $TMP_FOLDER)'/bzImage -t 30s'
6060
else if dbx_has_82a69f0
6161
dbxe -- fish -c "kboot -a x86_64 -k $TMP_FOLDER/bzImage -t 30s"
6262
else

fish/functions/mchsh.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ function mchsh -d "Wrapper around 'machinectl shell'"
2525
# Use fish's --init-commands to drop into the current working directory,
2626
# instead of $HOME, which is not really useful if working on the host and
2727
# wanting to drop into the guest to work.
28-
machinectl shell -q $user_host $SHELL -C 'cd '(nspawn_adjust_path $PWD) $mchsh_args
28+
machinectl shell -q $user_host $SHELL -C 'cd '(nspawn_path -c $PWD) $mchsh_args
2929
end

fish/functions/nspawn_adjust_path.fish

Lines changed: 0 additions & 11 deletions
This file was deleted.

fish/functions/nspawn_path.fish

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env fish
2+
# SPDX-License-Identifier: MIT
3+
# Copyright (C) 2024 Nathan Chancellor
4+
5+
function nspawn_path -d "Translate /home paths into systemd-nspawn or host"
6+
set mode $argv[1]
7+
set path $argv[2]
8+
set run_host /run/host
9+
10+
# The path only needs to be adjusted when it actually starts with whatever
11+
# the current $HOME value is, otherwise we assume that it is either already
12+
# in the appropriate format or it does not need to be converted.
13+
if string match -qr ^$HOME $path
14+
switch $mode
15+
# In container mode, the /home path should be prefixed with /run/host
16+
case -c --container
17+
if not string match -qr ^$run_host $path
18+
set prefix $run_host
19+
end
20+
printf '%s%s\n' $prefix $path
21+
22+
# In host mode, /run/host should be stripped from /home
23+
case -H --host
24+
if string match -qr ^/home $path
25+
echo $path
26+
else
27+
string replace -m1 $run_host '' $path
28+
end
29+
end
30+
else
31+
echo $path
32+
end
33+
end

0 commit comments

Comments
 (0)