Blame Scripts/Functions/cli_checkRepoDirSource.sh

4c79b5
#!/bin/bash
4c79b5
#
37881a
# cli_checkRepoDirSource.sh -- This function provides input validation
37881a
# to repository entries considered as source locations.
4c79b5
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
37881a
function cli_checkRepoDirSource {
55d653
                
b6bdc8
    # Check action value to be sure strange characters are kept far
b6bdc8
    # away from path provided.
b6bdc8
    cli_checkPathComponent $ACTIONVAL
4c79b5
37881a
    # Redefine source value to build repository absolute path from
a58b61
    # repository top level on. As we are removing
a58b61
    # /home/centos/artwork/ from all centos-art.sh output (in order to
a58b61
    # save horizontal output space), we need to be sure that all
a58b61
    # strings begining with trunk/..., branches/..., and tags/... use
a58b61
    # the correct absolute path. That is, you can refer trunk's
a58b61
    # entries using both /home/centos/artwork/trunk/... or just
a58b61
    # trunk/..., the /home/centos/artwork/ part is automatically added
a58b61
    # here. 
a58b61
    if [[ $ACTIONVAL =~ '^(trunk|branches|tags)' ]];then
7b46a4
        ACTIONVAL=${HOME}/artwork/$ACTIONVAL 
4c79b5
    fi
4c79b5
37881a
    # Re-define source value to build repository absolute path from
a58b61
    # repository relative paths. This let us to pass repository
37881a
    # relative paths as source value.  Passing relative paths as
37881a
    # source value may save us some typing; specially if we are stood
37881a
    # a few levels up from the location we want to refer to as source
a58b61
    # value.  There is no need to pass the absolute path to it, just
a58b61
    # refere it relatively.
a58b61
    if [[ -d ${ACTIONVAL} ]];then
4c79b5
4c79b5
        # Add directory to the top of the directory stack.
a58b61
        pushd "$ACTIONVAL" > /dev/null
4c79b5
a58b61
        # Check directory existence inside the repository.
7b46a4
        if [[ $(pwd) =~ "^${HOME}/artwork" ]];then
37881a
            # Re-define source value using absolute path.
a58b61
            ACTIONVAL=$(pwd)
a58b61
        else
be03a9
            cli_printMessage "`eval_gettext "The location \\\"\\\$ACTIONVAL\\\" is not valid."`" --as-error-line
a58b61
        fi
a58b61
a58b61
        # Remove directory from the directory stack.
a58b61
        popd > /dev/null
a58b61
a58b61
    elif [[ -f ${ACTIONVAL} ]];then
a58b61
a58b61
        # Add directory to the top of the directory stack.
67b9ac
        pushd "$(dirname "$ACTIONVAL")" > /dev/null
a58b61
a58b61
        # Check directory existence inside the repository.
7b46a4
        if [[ $(pwd) =~ "^${HOME}/artwork" ]];then
37881a
            # Re-define source value using absolute path.
67b9ac
            ACTIONVAL=$(pwd)/$(basename "$ACTIONVAL")
a58b61
        else
be03a9
            cli_printMessage "`eval_gettext "The location \\\"\\\$ACTIONVAL\\\" is not valid."`" --as-error-line
a58b61
        fi
4c79b5
4c79b5
        # Remove directory from the directory stack.
4c79b5
        popd > /dev/null
4c79b5
37881a
    else
37881a
37881a
        # At this there is no existent working copy entry, nor a valid
37881a
        # url. The source value can only be considered as such if it
37881a
        # is an existent working copy or valid url. So, print a
37881a
        # message and stop script execution.
be03a9
        cli_printMessage "`eval_gettext "The location \\\"\\\$ACTIONVAL\\\" is not valid."`" --as-error-line
37881a
4c79b5
    fi
4c79b5
4c79b5
}