summaryrefslogtreecommitdiffstats
path: root/chrome/installer/mac
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-10 18:50:32 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-10 18:50:32 +0000
commit4c1388f4b695a9ee34bf48412f3b9ceb079382a9 (patch)
tree88346da8cdebc726c3e90980bb8503aba3885614 /chrome/installer/mac
parentdadb98c683876445c412f53ccffc466af2547e58 (diff)
downloadchromium_src-4c1388f4b695a9ee34bf48412f3b9ceb079382a9.zip
chromium_src-4c1388f4b695a9ee34bf48412f3b9ceb079382a9.tar.gz
chromium_src-4c1388f4b695a9ee34bf48412f3b9ceb079382a9.tar.bz2
dirdiffer and dirpatcher should clean up after themselves if an error occurs
or a signal is received during operation. BUG=45017 TEST=none Review URL: http://codereview.chromium.org/2737007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/mac')
-rwxr-xr-xchrome/installer/mac/dirdiffer.sh30
-rwxr-xr-xchrome/installer/mac/dirpatcher.sh26
2 files changed, 54 insertions, 2 deletions
diff --git a/chrome/installer/mac/dirdiffer.sh b/chrome/installer/mac/dirdiffer.sh
index 6f93220..216e33d 100755
--- a/chrome/installer/mac/dirdiffer.sh
+++ b/chrome/installer/mac/dirdiffer.sh
@@ -138,6 +138,25 @@ readonly BZ2_SUFFIX='$bz2'
readonly GZ_SUFFIX='$gz'
readonly PLAIN_SUFFIX='$raw'
+declare -a g_cleanup
+
+cleanup() {
+ local status=${?}
+
+ trap - EXIT
+ trap '' HUP INT QUIT TERM
+
+ if [[ ${status} -ge 128 ]]; then
+ err "Caught signal $((${status} - 128))"
+ fi
+
+ if [[ "${#g_cleanup[@]}" -gt 0 ]]; then
+ rm -rf "${g_cleanup[@]}"
+ fi
+
+ exit ${status}
+}
+
err() {
local error="${1}"
@@ -309,11 +328,11 @@ verify_patch_dir() {
local verify_temp_dir verify_dir
verify_temp_dir="$(mktemp -d -t "${ME}")"
+ g_cleanup[${#g_cleanup[@]}]="${verify_temp_dir}"
verify_dir="${verify_temp_dir}/patched"
if ! "${DIRPATCHER}" "${old_dir}" "${patch_dir}" "${verify_dir}"; then
err "patch application for verification failed"
- rm -rf "${verify_temp_dir}"
exit 15
fi
@@ -324,11 +343,11 @@ verify_patch_dir() {
if ! rsync_output="$(rsync -clprt --delete --out-format=%n \
"${new_dir}/" "${verify_dir}")"; then
err "rsync for verification failed"
- rm -rf "${verify_temp_dir}"
exit 15
fi
rm -rf "${verify_temp_dir}"
+ unset g_cleanup[${#g_cleanup[@]}]
if [[ -n "${rsync_output}" ]]; then
err "verification failed"
@@ -370,6 +389,8 @@ main() {
new_dir="$(shell_safe_path "${2}")"
patch_dir="$(shell_safe_path "${3}")"
+ trap cleanup EXIT HUP INT QUIT TERM
+
if ! [[ -d "${old_dir}" ]] || ! [[ -d "${new_dir}" ]]; then
err "old_dir and new_dir must exist and be directories"
usage
@@ -404,9 +425,14 @@ main() {
exit 6
fi
+ g_cleanup[${#g_cleanup[@]}]="${patch_dir}"
+
make_patch_dir "${old_dir}" "${new_dir}" "${patch_dir}"
verify_patch_dir "${old_dir}" "${new_dir}" "${patch_dir}"
+
+ unset g_cleanup[${#g_cleanup[@]}]
+ trap - EXIT
}
if [[ ${#} -ne 3 ]]; then
diff --git a/chrome/installer/mac/dirpatcher.sh b/chrome/installer/mac/dirpatcher.sh
index 1f5e6b1..d5b062c 100755
--- a/chrome/installer/mac/dirpatcher.sh
+++ b/chrome/installer/mac/dirpatcher.sh
@@ -96,6 +96,25 @@ readonly BZ2_SUFFIX='$bz2'
readonly GZ_SUFFIX='$gz'
readonly PLAIN_SUFFIX='$raw'
+declare -a g_cleanup
+
+cleanup() {
+ local status=${?}
+
+ trap - EXIT
+ trap '' HUP INT QUIT TERM
+
+ if [[ ${status} -ge 128 ]]; then
+ err "Caught signal $((${status} - 128))"
+ fi
+
+ if [[ "${#g_cleanup[@]}" -gt 0 ]]; then
+ rm -rf "${g_cleanup[@]}"
+ fi
+
+ exit ${status}
+}
+
err() {
local error="${1}"
@@ -289,6 +308,8 @@ main() {
patch_dir="$(shell_safe_path "${2}")"
new_dir="$(shell_safe_path "${3}")"
+ trap cleanup EXIT HUP INT QUIT TERM
+
if ! [[ -d "${old_dir}" ]] || ! [[ -d "${patch_dir}" ]]; then
err "old_dir and patch_dir must exist and be directories"
usage
@@ -323,7 +344,12 @@ main() {
exit 6
fi
+ g_cleanup[${#g_cleanup[@]}]="${new_dir}"
+
patch_dir "${old_dir}" "${patch_dir}" "${new_dir}"
+
+ unset g_cleanup[${#g_cleanup[@]}]
+ trap - EXIT
}
if [[ ${#} -ne 3 ]]; then