Skip to content

Commit

Permalink
[build] add another housekeeping file in the datadir for data_version…
Browse files Browse the repository at this point in the history
…. Blow away the exiting files if that file either doesn't exist or doesn't contain a matching version string to help with upgrades
  • Loading branch information
albarrentine committed Apr 7, 2017
1 parent 4f9b0ef commit 7f7aada
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/libpostal_data
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ COMMAND=$1
FILE=$2
LIBPOSTAL_DATA_DIR=$3

LIBPOSTAL_DATA_VERSION_FILE=$LIBPOSTAL_DATA_DIR/data_version
LIBPOSTAL_DATA_DIR_VERSION=

mkdir -p $LIBPOSTAL_DATA_DIR

LIBPOSTAL_DATA_UPDATED_PATH=$LIBPOSTAL_DATA_DIR/last_updated
Expand Down Expand Up @@ -137,6 +140,26 @@ download_file() {
}

if [ $COMMAND = "download" ]; then
if [ -e $LIBPOSTAL_DATA_VERSION_FILE ]; then
LIBPOSTAL_DATA_DIR_VERSION=$(cat $LIBPOSTAL_DATA_VERSION_FILE)
fi

if [ "$LIBPOSTAL_DATA_DIR_VERSION" != "$LIBPOSTAL_VERSION_STRING" ]; then
echo "Old version of datadir detected, removing..."
for subdir in $BASIC_MODULE_DIRS $PARSER_MODULE_DIR $LANGUAGE_CLASSIFIER_MODULE_DIR; do
rm -rf $LIBPOSTAL_DATA_DIR/$subdir;
done

# Legacy, blow it away too to be nice
if [ -e $LIBPOSTAL_DATA_DIR/geodb ]; then
rm -rf $LIBPOSTAL_DATA_DIR/geodb;
fi

rm -f $LIBPOSTAL_DATA_UPDATED_PATH
rm -f $LIBPOSTAL_LANG_CLASS_UPDATED_PATH
rm -f $LIBPOSTAL_PARSER_UPDATED_PATH
fi

mkdir -p $LIBPOSTAL_DATA_DIR

if [ $FILE = "base" ] || [ $FILE = "all" ]; then
Expand All @@ -153,6 +176,10 @@ if [ $COMMAND = "download" ]; then
download_file $LIBPOSTAL_LANG_CLASS_UPDATED_PATH $LIBPOSTAL_DATA_DIR $lang_class_s3_prefix $LIBPOSTAL_LANG_CLASS_FILE "language classifier data file" $LANGUAGE_CLASSIFIER_MODULE_DIR
fi

if [ "$LIBPOSTAL_DATA_DIR_VERSION" != "$LIBPOSTAL_VERSION_STRING" ]; then
echo $LIBPOSTAL_VERSION_STRING > $LIBPOSTAL_DATA_VERSION_FILE;
fi

elif [ $COMMAND = "upload" ]; then

if [ $FILE = "base" ] || [ $FILE = "all" ]; then
Expand Down

0 comments on commit 7f7aada

Please sign in to comment.