Blame Scripts/Bash/Functions/cli_checkRepoDirTarget.sh

328582
#!/bin/bash
328582
#
328582
# cli_checkRepoDirTarget.sh -- This function provides input validation
328582
# to repository entries considered as target location.
328582
#
72c8a5
# Copyright (C) 2009-2011  Alain Reguera Delgado
328582
# 
328582
# This program is free software; you can redistribute it and/or
328582
# modify it under the terms of the GNU General Public License as
328582
# published by the Free Software Foundation; either version 2 of the
328582
# License, or (at your option) any later version.
328582
# 
328582
# This program is distributed in the hope that it will be useful, but
328582
# WITHOUT ANY WARRANTY; without even the implied warranty of
328582
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
328582
# General Public License for more details.
328582
#
328582
# You should have received a copy of the GNU General Public License
328582
# along with this program; if not, write to the Free Software
328582
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
328582
# USA.
328582
# 
328582
# ----------------------------------------------------------------------
328582
# $Id: cli_checkRepoDirTarget.sh 547 2010-11-26 16:58:06Z al $
328582
# ----------------------------------------------------------------------
328582
328582
function cli_checkRepoDirTarget {
328582
328582
    # Check target value before making an absolute path from it. 
328582
    if [[ $TARGET =~ '(\.\.(/)?)' ]];then
328582
        cli_printMessage "`gettext "The path provided can't be processed."`" 'AsErrorLine'
328582
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
328582
    fi
328582
    if [[ ! $TARGET =~ '^[A-Za-z0-9\.:/-]+$' ]];then
328582
        cli_printMessage "`gettext "The path provided can't be processed."`" 'AsErrorLine'
328582
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
328582
    fi
328582
328582
    # Redefine target value to build repository absolute path from
328582
    # repository top level on. As we are removing
328582
    # /home/centos/artwork/ from all centos-art.sh output (in order to
328582
    # save horizontal output space), we need to be sure that all
328582
    # strings begining with trunk/..., branches/..., and tags/... use
328582
    # the correct absolute path. That is, you can refer trunk's
328582
    # entries using both /home/centos/artwork/trunk/... or just
328582
    # trunk/..., the /home/centos/artwork/ part is automatically added
328582
    # here. 
328582
    if [[ $TARGET =~ '^(trunk|branches|tags)/.+$' ]];then
328582
        TARGET=/home/centos/artwork/$TARGET 
328582
    fi
328582
328582
    # Check target value.
328582
    if [[ -a ${TARGET} ]];then
328582
328582
        # At this point target value does existent as working copy
328582
        # entry. We don't use existent locations as target.  So, print
328582
        # a message and stop script execution.
328582
        cli_printMessage "`eval_gettext "The location \\\`\\\$TARGET' already exists."`" 'AsErrorLine'
328582
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
328582
328582
    else
328582
328582
        # At this point existent locations inside working copy and
328582
        # invalid urls have been discarded. Assume a new target
328582
        # location has being specified. So, build the absolute path
328582
        # for it.
328582
328582
        # Add directory to the top of the directory stack.
328582
        pushd "$(dirname $TARGET)" > /dev/null
328582
328582
        # Check directory existence inside the repository.
328582
        if [[ $(pwd) =~ '^/home/centos/artwork' ]];then
328582
            # Re-define target value using absolute path.
328582
            TARGET=$(pwd)/$(basename $TARGET)
328582
        fi
328582
328582
        # Remove directory from the directory stack.
328582
        popd > /dev/null
328582
328582
        # Verify target location. It is required that target location
328582
        # points to an entry under (trunk|branches|tags)/Identity/...
328582
        # directory structure *only*.  Remember that Identity parent
328582
        # directory structure is the reference used to create parallel
328582
        # directories (i.e., documentation, configuration scripts,
328582
        # translations, etc.). We don't manipulate parallel
328582
        # directories with path ---or any other--- functionality
328582
        # directly.  Consider manipulation of parallel directories as
328582
        # a consequence of a previous manipulation of Identity parent
328582
        # directory structure.
328582
        if [[ ! ${TARGET} =~ '^.+/(trunk|branches|tags)/Identity/.+$' ]];then
328582
            cli_printMessage "`eval_gettext "cannot create \\\`\\\$TARGET': It isn't an identity directory structure."`" 'AsErrorLine'
328582
            cli_printMessage "$(caller)" 'AsToKnowMoreLine'
328582
        fi
328582
    fi
328582
328582
}