enter_chroot: extend ensure_mounted api to use it with depot_tools

The depot_tools mount code is exactly like ensure_mounted except that it
prints a warning instead of dying when things can't be mounted.  So take
the current api and extend it slightly to support warning or dying.  This
also lets us re-use the existing mount cache and avoid the forks as well
as clean up duplicated code.

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

Change-Id: I89336778b6aa16191e79d900a51774929cadf06b
Reviewed-on: http://gerrit.chromium.org/gerrit/8031
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:24:24 -04:00 committed by chrome-bot
parent 564dcfbde6
commit b4d7c4b7b8

View File

@ -92,6 +92,7 @@ function ensure_mounted {
local source="$1"
local mount_args="$2"
local target="$3"
local warn="$4"
local mounted_path="$(readlink -f "${FLAGS_chroot}/$target")"
@ -107,8 +108,14 @@ function ensure_mounted {
# NB: mount_args deliberately left unquoted
debug mount ${mount_args} "${source}" "${mounted_path}"
sudo -- mount ${mount_args} "${source}" "${mounted_path}" || \
die "Could not mount ${source} on ${mounted_path}"
if ! sudo -- mount ${mount_args} "${source}" "${mounted_path}" ; then
if [ -z "${warn}" ]; then
die "Could not mount ${source} on ${mounted_path}"
else
warn "Failed to mount ${source}; perhaps it's on NFS?"
warn "${warn}"
fi
fi
;;
esac
}
@ -269,17 +276,11 @@ function setup_env {
fi
fi
MOUNTED_PATH="$(readlink -f "${FLAGS_chroot}${INNER_DEPOT_TOOLS_ROOT}")"
if [ -z "$(mount | grep -F "on $MOUNTED_PATH ")" ]; then
if DEPOT_TOOLS=$(type -P gclient) ; then
DEPOT_TOOLS=${DEPOT_TOOLS%/*} # dirname
debug "Mounting depot_tools"
mkdir -p "$MOUNTED_PATH"
if ! sudo mount --bind "$DEPOT_TOOLS" "$MOUNTED_PATH"; then
warn "depot_tools failed to mount; perhaps it's on NFS?"
warn "This may impact chromium build."
fi
fi
if DEPOT_TOOLS=$(type -P gclient) ; then
DEPOT_TOOLS=${DEPOT_TOOLS%/*} # dirname
debug "Mounting depot_tools"
ensure_mounted "$DEPOT_TOOLS" --bind "$INNER_DEPOT_TOOLS_ROOT" \
"This may impact chromium build."
fi
# Install fuse module. Skip modprobe when possible for slight