Skip to content

Commit

Permalink
Handle cases where directories and files are not-existent
Browse files Browse the repository at this point in the history
New applications will be missing a few different files and directories, which isn't strictly an error case.
  • Loading branch information
josegonzalez committed Jul 29, 2016
1 parent be35741 commit b2fac23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions plugins/apps/subcommands/rename
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ apps_rename_cmd() {
[[ -d "$DOKKU_ROOT/$3" ]] && dokku_log_fail "Name is already taken"
local OLD_APP="$2"
local NEW_APP="$3"
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"

mkdir -p "$DOKKU_ROOT/$NEW_APP"
if ! rmdir "$DOKKU_ROOT/$OLD_APP/cache" > /dev/null 2>&1; then
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$DOKKU_ROOT/$OLD_APP/cache:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR"; then
docker run "$DOKKU_GLOBAL_RUN_ARGS" --rm -v "$OLD_CACHE_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
fi
rm -rf "$DOKKU_ROOT/$OLD_APP/cache"
rm -rf "$OLD_CACHE_DIR"
cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP"
DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP"
sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS"
sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST"
sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive"
[[ -f "$DOKKU_ROOT/$NEW_APP/URLS" ]] && sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS"
[[ -f "$DOKKU_ROOT/$NEW_APP/VHOST" ]] && sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST"
[[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]] && sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive"
ps_rebuild "$NEW_APP"
plugn trigger post-app-rename "$OLD_APP" "$NEW_APP"
echo "Renaming $OLD_APP to $NEW_APP... done"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/10_apps.bats
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ load test_helper
run bash -c "dokku apps:rename $TEST_APP great-test-name"
echo "output: "$output
echo "status: "$status
assert_output $TEST_APP
assert_success
run bash -c "dokku --force apps:destroy great-test-name"
echo "output: "$output
echo "status: "$status
Expand Down

0 comments on commit b2fac23

Please sign in to comment.