Don't clear the caller's existing known_hosts file.
Replace truncate call with touch call to avoid truncating user's
existing known_hosts file. We don't want the caller's known_hosts
file to be erased when entering a chroot.
This was introduced with commit add9976e45a9 ("enter_chroot: bind mount
~/.ssh/known_hosts")
BUG=None
TEST=Hosts file remains intact after this change
Change-Id: I5284c47c0571c65b6ba7af96c31bdd7bbfe5760d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2705327
Tested-by: Steve Kendall <skend@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh
index 5f0e1e9..fb810c6 100755
--- a/sdk_lib/enter_chroot.sh
+++ b/sdk_lib/enter_chroot.sh
@@ -508,7 +508,8 @@
local known_hosts="${SUDO_HOME}/.ssh/known_hosts"
if [[ -e ${known_hosts} ]]; then
- truncate -s 0 "${TARGET_DIR}/known_hosts"
+ # Ensure there is a file to bind mount onto for setup_mount.
+ touch "${TARGET_DIR}/known_hosts"
setup_mount "${known_hosts}" --bind "${target_ssh}/known_hosts"
fi
copy_ssh_config "${TARGET_DIR}"