aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-11-01 16:24:26 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-11-01 19:58:08 +0100
commitba7820b18c0ee8631505f7a2a764f7222a732d44 (patch)
tree82bc1d530e1f815e8d8687fa642dd5c84a59c114
parent93e2978fbe5582440d79c47b5975659d9cbf701b (diff)
downloadapp.sh-ba7820b18c0ee8631505f7a2a764f7222a732d44.tar.gz
app.sh-ba7820b18c0ee8631505f7a2a764f7222a732d44.tar.bz2
app.sh-ba7820b18c0ee8631505f7a2a764f7222a732d44.tar.xz
app.sh-ba7820b18c0ee8631505f7a2a764f7222a732d44.zip
bin/app-upgrade: Removing unreachable code. Fixing it so it comparesv0.2-dev
against the currently installed version instead of the last resolved version which makes it possible to retry installation of the same version. libexec/app-install-file: Allowing installation of the same file twice. Checks if the file has been unpacked earlier or not. Removes the unpacked version on failure.
-rwxr-xr-xbin/app-upgrade36
-rwxr-xr-xlibexec/app-install-file30
-rwxr-xr-xlibexec/app-resolver-file2
-rwxr-xr-xtest/app-init.bats14
-rwxr-xr-xtest/app-upgrade.bats30
-rwxr-xr-xtest/data/app-a/hooks/post-install8
-rwxr-xr-xtest/data/app-a/hooks/pre-install11
7 files changed, 91 insertions, 40 deletions
diff --git a/bin/app-upgrade b/bin/app-upgrade
index 1a8329a..db40f4e 100755
--- a/bin/app-upgrade
+++ b/bin/app-upgrade
@@ -19,40 +19,34 @@ fi
assert_is_app
+version=`app-conf get app.version`
+installed_version=`app-conf get app.installed_version`
+
+# TODO: should this explicitly check for a discrepancy between
+# resolved_version and installed_version? This indicates an app that's
+# not completely installed.
+
+# Find the resolver and resolve the version
resolver_name=`app-conf get app.resolver`
resolver=`find_resolver "$resolver_name"`
-old_version=`app-conf get app.resolved_version`
-echo "Resolving version $old_version"
+echo "Resolving version $version"
"$resolver" resolve-version
-new_version=`app-conf get app.resolved_version`
+resolved_version=`app-conf get app.resolved_version`
-if [[ $new_version == $old_version ]]
+if [[ $resolved_version == $installed_version ]]
then
echo "No new version available" 2>&1
exit
fi
-echo "Resolved version to $new_version"
-
-if [ "$new_version" = "" ]
-then
- new_version=`app-conf get app.resolved_version`
-fi
-
-if [ "$new_version" = "" ]
+if [ "$resolved_version" = "" ]
then
fatal "app.resolved_version is not set."
fi
-installed_version=`app-conf get app.installed_version`
-
-if [ "$new_version" = "$installed_version" ]
-then
- echo "$new_version is already installed"
- exit 0
-fi
+echo "Resolved version to $resolved_version"
-"$resolver" download-version -v "$new_version" -f .app/latest.zip
+"$resolver" download-version -v "$resolved_version" -f .app/latest.zip
-app-install-file -v "$new_version" -f .app/latest.zip
+app-install-file -v "$resolved_version" -f .app/latest.zip
diff --git a/libexec/app-install-file b/libexec/app-install-file
index c31f1f4..32b0407 100755
--- a/libexec/app-install-file
+++ b/libexec/app-install-file
@@ -48,21 +48,29 @@ then
usage
fi
-if [ -d versions/$version ]
+re="[.a-zA-Z0-9]"
+
+if [[ ! $version =~ $re ]]
then
- echo "Version $version is already installed"
- exit 1
+ fatal "Invalid version: $version"
fi
-mkdir -p versions/$version
-
-echo "Unpacking..."
-unzip -q -d versions/$version $file
-
-if [ ! -d versions/$version/root ]
+if [ -d versions/$version ]
then
- echo "Invalid zip file, did not contain a ./root directory." >&2
- exit 1
+ echo "Version $version is already unpacked"
+else
+ mkdir -p versions/$version.tmp
+
+ echo "Unpacking..."
+ unzip -q -d versions/$version.tmp $file
+
+ if [ ! -d versions/$version.tmp/root ]
+ then
+ echo "Invalid zip file, did not contain a 'root' directory." >&2
+ rm -rf versions/$version.tmp
+ exit 1
+ fi
+ mv versions/$version.tmp versions/$version
fi
if [ -n "$prepend_config" ]
diff --git a/libexec/app-resolver-file b/libexec/app-resolver-file
index 2b708e8..5972926 100755
--- a/libexec/app-resolver-file
+++ b/libexec/app-resolver-file
@@ -47,7 +47,7 @@ init() {
resolve_version() {
path=$(app-conf get file.path)
- local s=$(stat -c %Z $path)
+ local s=$(stat -c %Y $path)
app-conf set app.resolved_version "$s"
}
diff --git a/test/app-init.bats b/test/app-init.bats
index 2b5d724..484fe13 100755
--- a/test/app-init.bats
+++ b/test/app-init.bats
@@ -31,9 +31,10 @@ load utils
match '${lines[2]}' "Downloading org.example:app-a:1.0-*"
eq '${lines[3]}' "Unpacking..."
match '${lines[4]}' "Importing config from versions/1.0-*"
- match '${lines[5]}' "Creating current symlink for version 1.0-*"
- eq '${lines[6]}' "Post install"
- eq '${#lines[*]}' 7
+ eq '${lines[5]}' "pre-install"
+ match '${lines[6]}' "Creating current symlink for version 1.0-*"
+ eq '${lines[7]}' "post-install"
+ eq '${#lines[*]}' 8
is_directory "my-app/.app"
# Created by post-install
@@ -50,9 +51,10 @@ load utils
match '${lines[1]}' "Downloading org.example:app-a:1.0-*"
eq '${lines[2]}' "Unpacking..."
match '${lines[3]}' "Importing config from versions/1.0-*"
- match '${lines[4]}' "Creating current symlink for version 1.0-*"
- eq '${lines[5]}' "Post install"
- eq '${#lines[*]}' 6
+ eq '${lines[4]}' "pre-install"
+ match '${lines[5]}' "Creating current symlink for version 1.0-*"
+ eq '${lines[6]}' "post-install"
+ eq '${#lines[*]}' 7
is_directory "my-app/.app"
# Created by post-install
diff --git a/test/app-upgrade.bats b/test/app-upgrade.bats
index d27c6e7..9a282e3 100755
--- a/test/app-upgrade.bats
+++ b/test/app-upgrade.bats
@@ -38,3 +38,33 @@ load utils
describe new_resolved_version = $new_resolved_version
neq $new_resolved_version $resolved_version
}
+
+@test "app-upgrade - when pre-install fails the first run" {
+ mkzip app-a
+ file=$APPSH_HOME/test/data/app-a.zip
+ touch -t 01010101 $file
+
+ app init -d my-app file $file
+
+ cd my-app
+
+ # A new version is available, but make sure pre-install fails.
+ touch -t 02020202 $file
+ touch fail-pre-install
+ check_status=no
+ app upgrade
+ eq '${status}' 1
+
+ # Try to reinstall the same file
+ rm fail-pre-install
+ app upgrade
+ eq '${lines[0]}' "Resolving version "
+ eq '${lines[1]}' "Resolved version to 1359766920"
+ eq '${lines[2]}' "Version 1359766920 is already unpacked"
+ eq '${lines[3]}' "Importing config from versions/1359766920/app.config"
+ eq '${lines[4]}' "pre-install"
+ eq '${lines[5]}' "Changing current symlink from 1356998460 to 1359766920"
+ eq '${lines[6]}' "post-install"
+
+ eq '${#lines[*]}' 7
+}
diff --git a/test/data/app-a/hooks/post-install b/test/data/app-a/hooks/post-install
index 1dfb7be..0717f2a 100755
--- a/test/data/app-a/hooks/post-install
+++ b/test/data/app-a/hooks/post-install
@@ -2,7 +2,13 @@
set -u
-echo "Post install"
+echo "post-install"
+
+if [[ -e $APP_HOME/fail-post-install ]]
+then
+ echo "Simulating failure."
+ exit 1
+fi
NAME=`basename $APP_HOME`
diff --git a/test/data/app-a/hooks/pre-install b/test/data/app-a/hooks/pre-install
new file mode 100755
index 0000000..4b95ac4
--- /dev/null
+++ b/test/data/app-a/hooks/pre-install
@@ -0,0 +1,11 @@
+#!/bin/bash -e
+
+set -u
+
+echo "pre-install"
+
+if [[ -e $APP_HOME/fail-pre-install ]]
+then
+ echo "Simulating failure."
+ exit 1
+fi