Copy ~/.gdata_token to chroot upon enter_chroot.

The refresh-packages builder needs to start using auth tokens for logging into
Google Docs, rather than email/password each time, so this copies ~/.gdata_token
into the chroot in the same way as ~/gdata_cred.txt.

BUG=chromium-os:23819
TEST=Put a file at ~/.gdata_token outside chroot, then run:
`cros_sdk true ; cmp {chroot/home/$USER/,~/}.gdata_token`, which passes.

Change-Id: Ib688a01aa88e0fd0f0211236bb0354813ef1fbb3
Reviewed-on: https://gerrit.chromium.org/gerrit/15550
Commit-Ready: Matt Tennant <mtennant@chromium.org>
Reviewed-by: Matt Tennant <mtennant@chromium.org>
Tested-by: Matt Tennant <mtennant@chromium.org>
diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh
index de484af..df3aaf3 100755
--- a/sdk_lib/enter_chroot.sh
+++ b/sdk_lib/enter_chroot.sh
@@ -195,6 +195,12 @@
   sed "/^.*\(${filter}\).*$/d" "${sshc}" > "${chroot_ssh_dir}/config"
 }
 
+function copy_into_chroot_if_exists {
+  # $1 is file path outside of chroot to copy to path $2 inside chroot.
+  [ -e "$1" ] || return
+  cp "$1" "${FLAGS_chroot}/$2"
+}
+
 function setup_env {
   # Validate sudo timestamp before entering the critical section so that we
   # don't stall for a password while we have the lockfile.
@@ -389,11 +395,11 @@
     git config -f ${FLAGS_chroot}/home/${USER}/.gitconfig --replace-all \
       user.email "${ident_email}" || true
 
-    # Copy ~/.gdata_cred.txt to chroot if it exists.  This file contains
-    # credentials for reading/writing Google Docs on chromium.org.
-    if [ -f "$HOME/.gdata_cred.txt" ]; then
-      cp "$HOME/.gdata_cred.txt" "${FLAGS_chroot}/home/${USER}/.gdata_cred.txt"
-    fi
+    # Copy ~/.gdata_cred.txt and ~/.gdata_token to chroot if they exist.  These
+    # files contain credentials for reading/writing Google Docs on chromium.org.
+    for fn in ".gdata_cred.txt" ".gdata_token"; do
+      copy_into_chroot_if_exists "${HOME}/${fn}" "/home/${USER}/${fn}"
+    done
 
     # Make sure user's requested locales are available
     # http://crosbug.com/19139