diff --git a/github_archive_updater.py b/github_archive_updater.py
index 3abe5be6bb349a13f7cbf7c5f87557722fe1da58..e42e7b092121234f112d0bd9b26f7379003ad3c7 100644
--- a/github_archive_updater.py
+++ b/github_archive_updater.py
@@ -118,5 +118,7 @@ class GithubArchiveUpdater():
self._write_metadata(latest_url, package_dir)
updater_utils.replace_package(package_dir, self.proj_path)
finally:
- shutil.rmtree(temporary_dir, ignore_errors=True)
+ # Don't remove the temporary directory, or it'll be impossible
+ # to debug the failure...
+ # shutil.rmtree(temporary_dir, ignore_errors=True)
urllib.request.urlcleanup()
diff --git a/update_package.sh b/update_package.sh
index 8b9629a6f6d5f97ee25471fc535c562d47d9d601..0a854a7674a0624669e25f0cfb7f7318d008880b 100644
--- a/update_package.sh
+++ b/update_package.sh
@@ -15,36 +15,50 @@
# limitations under the License.
# This script is used by external_updater to replace a package. Don't
-# invoke directly
-
-cd $1
-
-# Copies all files we want to reserve.
-cp -a -n $2/Android.bp $1/ 2> /dev/null
-cp -a -n $2/Android.mk $1/ 2> /dev/null
-cp -a -n $2/LICENSE $1/ 2> /dev/null
-cp -a -n $2/NOTICE $1/ 2> /dev/null
-cp -a -n $2/MODULE_LICENSE_* $1/ 2> /dev/null
-cp -a -n $2/METADATA $1/ 2> /dev/null
-cp -a -n $2/.git $1/ 2> /dev/null
-cp -a -n $2/.gitignore $1/ 2> /dev/null
-cp -a -n $2/patches $1/ 2> /dev/null
-cp -a -n $2/post_update.sh $1/ 2> /dev/null
-
-# Applies all patches
-for p in $1/patches/*.diff
+# invoke directly.
+
+set -e
+
+tmp_dir=$1
+external_dir=$2
+
+echo "Entering $tmp_dir..."
+cd $tmp_dir
+
+function CopyIfPresent() {
+ if [ -e $external_dir/$1 ]; then
+ cp -a -n $external_dir/$1 .
+ fi
+}
+
+echo "Copying preserved files..."
+CopyIfPresent "Android.bp"
+CopyIfPresent "Android.mk"
+CopyIfPresent "LICENSE"
+CopyIfPresent "NOTICE"
+cp -a -f -n $external_dir/MODULE_LICENSE_* .
+CopyIfPresent "METADATA"
+CopyIfPresent ".git"
+CopyIfPresent ".gitignore"
+CopyIfPresent "patches"
+CopyIfPresent "post_update.sh"
+
+echo "Applying patches..."
+for p in $tmp_dir/patches/*.diff
do
[ -e "$p" ] || continue
- echo Applying $p
- patch -p1 -d $1 < $p;
+ echo "Applying $p..."
+ patch -p1 -d $tmp_dir < $p;
done
-if [ -f $1/post_update.sh ]
+if [ -f $tmp_dir/post_update.sh ]
then
- echo Running post update script
- $1/post_update.sh $1 $2
+ echo "Running post update script"
+ $tmp_dir/post_update.sh $tmp_dir $external_dir
fi
-# Swap old and new.
-rm -rf $2
-mv $1 $2
+echo "Swapping old and new..."
+rm -rf $external_dir
+mv $tmp_dir $external_dir
+
+exit 0
diff --git a/updater.sh b/updater.sh
index 4f03c89710f3ceb112118da17f68ed57ea8ee68b..b8078c640f2adf05bdba8f3da51301744e0a51be 100755
--- a/updater.sh
+++ b/updater.sh
@@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+set -e
+
cd $(dirname "$0")/../..
source build/envsetup.sh
lunch aosp_arm-eng