enter_chroot: re-factor chrome_root mounting to use ensure_mounted

The chrome root code doesn't attempt to mount the tree if there is no
source root configured.  So re-order the code from:
 - is chrome source mounted ?
 - does a chrome source exist ?
 - mount chrome source
to the more logical:
 - does a chrome source exist ?
 - use ensure_mounted to check+mount

This lets us use the mount cache for the chrome mounting and unifies
duplicated mount/checking logic.

BUG=None
TEST=`cros_sdk --enter` still works with simultaneous runs
TEST=`cros_sdk --enter -- ls` still works

Change-Id: I7e6af9dd7f65cefa04438c2862c931f06237060a
Reviewed-on: http://gerrit.chromium.org/gerrit/8032
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Mike Frysinger 2011-09-20 23:37:14 -04:00 committed by Gerrit
parent b4d7c4b7b8
commit 9a50b64449

View File

@ -250,29 +250,24 @@ function setup_env {
fi fi
fi fi
MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_CHROME_ROOT}")" CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root" || :)"
if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then if [ -z "$CHROME_ROOT" ]; then
CHROME_ROOT="$(readlink -f "$FLAGS_chrome_root" || :)" CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \
if [ -z "$CHROME_ROOT" ]; then 2>/dev/null || :)"
CHROME_ROOT="$(cat "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" \ CHROME_ROOT_AUTO=1
2>/dev/null || :)" fi
CHROME_ROOT_AUTO=1 if [[ -n "$CHROME_ROOT" ]]; then
fi if [[ ! -d "${CHROME_ROOT}/src" ]]; then
if [[ -n "$CHROME_ROOT" ]]; then error "Not mounting chrome source"
if [[ ! -d "${CHROME_ROOT}/src" ]]; then sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}"
error "Not mounting chrome source" if [[ ! "$CHROME_ROOT_AUTO" ]]; then
sudo rm -f "${FLAGS_chroot}${CHROME_ROOT_CONFIG}" exit 1
if [[ ! "$CHROME_ROOT_AUTO" ]]; then
exit 1
fi
else
debug "Mounting chrome source at: $INNER_CHROME_ROOT"
sudo bash -c "echo '$CHROME_ROOT' > \
'${FLAGS_chroot}${CHROME_ROOT_CONFIG}'"
mkdir -p "$MOUNTED_PATH"
sudo mount --bind "$CHROME_ROOT" "$MOUNTED_PATH" || \
die "Could not mount $MOUNTED_PATH"
fi fi
else
debug "Mounting chrome source at: $INNER_CHROME_ROOT"
sudo bash -c "echo '$CHROME_ROOT' > \
'${FLAGS_chroot}${CHROME_ROOT_CONFIG}'"
ensure_mounted "$CHROME_ROOT" --bind "$INNER_CHROME_ROOT"
fi fi
fi fi