From 9bd22ea1b3ad1b94328d3d32b6a8cfb9d6ee7a09 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 11 Aug 2011 17:51:04 +0100 Subject: Improve db compact script: handle spaces in filenames nicely, output errors to STDERR, and don't do anything if there's a half-finished attempt still lying around. --- script/compact-xapian-database | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'script') diff --git a/script/compact-xapian-database b/script/compact-xapian-database index 5c12b5dae..f1a6058b0 100755 --- a/script/compact-xapian-database +++ b/script/compact-xapian-database @@ -1,16 +1,25 @@ #!/bin/bash -RAILS_ENV=$1 +export RAILS_ENV=$1 set -e + if [ -x /usr/bin/xapian-compact ]; then - XAPIAN_DB_DIR="$( cd "$( dirname "$0" )" && pwd )/../vendor/plugins/acts_as_xapian/xapiandbs" - OWNER=`stat -c %U $XAPIAN_DB_DIR/$RAILS_ENV` - su -c "xapian-compact $XAPIAN_DB_DIR/$RAILS_ENV $XAPIAN_DB_DIR/$RAILS_ENV.new" $OWNER - mv $XAPIAN_DB_DIR/$RAILS_ENV $XAPIAN_DB_DIR/$RAILS_ENV.tmp - mv $XAPIAN_DB_DIR/$RAILS_ENV.new $XAPIAN_DB_DIR/$RAILS_ENV - rm -rf $XAPIAN_DB_DIR/$RAILS_ENV.tmp - /etc/init.d/apache2 restart + XAPIAN_DB_DIR=$( cd "$( dirname "$0" )" && pwd )/../vendor/plugins/acts_as_xapian/xapiandbs + if [ -e "$XAPIAN_DB_DIR/$RAILS_ENV.new" ]; then + echo >&2 "Didn't compact Xapian database because there was an existing database at $XAPIAN_DB_DIR/$RAILS_ENV.new" + exit 1 + else + OWNER=$(stat -c %U "$XAPIAN_DB_DIR/$RAILS_ENV") + export XAPIAN_DB_DIR RAILS_ENV + su "$OWNER" <&2 "Could not find xapian-compact script; have you installed xapian-tools?" exit 1 -fi \ No newline at end of file +fi -- cgit v1.2.3