Blame Scripts/Functions/Help/Texinfo/texinfo_deleteEntry.sh

4c79b5
#!/bin/bash
4c79b5
#
993f6a
# texinfo_deleteEntry.sh -- This function removes a documentation entry
5285d6
# from documentation directory structure.
4c79b5
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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
993f6a
function texinfo_deleteEntry {
4c79b5
38ef08
    local MANUAL_ENTRY=''
38ef08
    local MANUAL_ENTRY_DIR=''
38ef08
    local MANUAL_ENTRY_SUBDIR=''
bb2d0f
bb2d0f
    # Define list of entries to remove using the entry specified in
bb2d0f
    # the command line.
edaa9d
    local MANUAL_ENTRIES=$(${FLAG_BACKEND}_getEntry "$@")
bb2d0f
635e5d
    # Print separator line.
18be6e
    cli_printMessage '-' --as-separator-line
635e5d
bb2d0f
    # Define list of dependen entries. Dependent entries are stored
bb2d0f
    # inside a directory with the same name of the entry being
bb2d0f
    # removed.
38ef08
    for MANUAL_ENTRY in $MANUAL_ENTRIES;do
4c79b5
bb2d0f
        # Define directory where dependent documentation entries are
bb2d0f
        # stored in.
9fa13b
        MANUAL_ENTRY_DIR=$(echo $MANUAL_ENTRY \
9fa13b
            | sed -r "s/\.${MANUAL_EXTENSION}$//")
449927
38ef08
        if [[ -d $MANUAL_ENTRY_DIR ]];then
449927
bb2d0f
            # Add dependent documentation entries to the list of
bb2d0f
            # documentation entries that will be deleted.
9fa13b
            MANUAL_ENTRIES="${MANUAL_ENTRIES} $(cli_getFilesList ${MANUAL_ENTRY_DIR} \
9fa13b
                --pattern=".*\.${MANUAL_EXTENSION}")"
449927
38ef08
            for MANUAL_ENTRY in $MANUAL_ENTRIES;do
4c79b5
bb2d0f
                # Define directory name for dependent documentation
bb2d0f
                # entries which have their own dependent directories.
9fa13b
                MANUAL_ENTRY_SUBDIR=$(basename $MANUAL_ENTRY \
9fa13b
                    | sed -r "s/\.${MANUAL_EXTENSION}$//")
bb2d0f
bb2d0f
                # Add directory paths from dependent documentation
bb2d0f
                # entries which have their own dependent directories
bb2d0f
                # to the list of documentation entries that will be
bb2d0f
                # deleted.
38ef08
                MANUAL_ENTRIES="${MANUAL_ENTRIES} $(cli_getFilesList \
38ef08
                    ${MANUAL_ENTRY_DIR} \
38ef08
                    --pattern=".*/${MANUAL_ENTRY_SUBDIR}" \
38ef08
                    --type='d')"
bb2d0f
bb2d0f
            done
bb2d0f
bb2d0f
        fi
4c79b5
bb2d0f
    done
bb2d0f
bb2d0f
    # Sanitate list of documentation entries that will be removed.
38ef08
    MANUAL_ENTRIES=$(echo ${MANUAL_ENTRIES} | tr ' ' "\n" | sort -r | uniq | tr "\n" ' ')
638bf8
b45dde
    # Verify existence of entries before deleting them. We cannot
b45dde
    # delete an entry which doesn't exist. Assuming that an entry
b45dde
    # doesn't exist, end script execution with an error message.
38ef08
    cli_checkFiles "$MANUAL_ENTRIES"
b45dde
    
635e5d
    # Remove documentation entry using Subversion's `delete' command
635e5d
    # to know when the action took place.  Do not use regular `rm'
635e5d
    # command here.
38ef08
    for MANUAL_ENTRY in $MANUAL_ENTRIES;do
38ef08
        cli_printMessage "$MANUAL_ENTRY" --as-deleting-line
38ef08
        svn del ${MANUAL_ENTRY} --quiet
b45dde
    done
635e5d
635e5d
    # Verify exit status from subversion command to be sure everything
bb2d0f
    # went well. Otherwise stop script execution with an error
bb2d0f
    # message.
136786
    if [[ $? -ne 0 ]];then
bb2d0f
        cli_printMessage "`gettext "An error occurred when deleting entries."`" --as-toknowmore-line
136786
    fi
4456e8
449927
    # Print separator line.
18be6e
    cli_printMessage '-' --as-separator-line
449927
449927
    # Print action message.
bb2d0f
    cli_printMessage "`gettext "Updating menus, nodes and cross-references."`" --as-response-line
449927
449927
    # Process list of entries in order to update menus, nodes and
449927
    # cross references. Since we are verifying entry status before
449927
    # remove the we cannot update the information in the same loop we
449927
    # remove files. This would modify some file before be removed and
449927
    # that would stop script execution. Similary, if we do update
449927
    # menus, nodes and cross references before removing files it would
449927
    # be needed to remove farther status verification in order for the
449927
    # script to continue its execution. Thereby, I can't see a
449927
    # different way but removing files first using status verification
635e5d
    # and later go through entries list again to update menus, nodes
635e5d
    # and cross references in remaining files.
38ef08
    for MANUAL_ENTRY in ${MANUAL_ENTRIES};do
3385aa
bb2d0f
        # Skip all directories, they are not documentation entries on
bb2d0f
        # themselves. Use documentation entries only.
9fa13b
        if [[ ! $MANUAL_ENTRY =~ "\.${MANUAL_EXTENSION}$" ]];then
bb2d0f
            continue
bb2d0f
        fi
bb2d0f
449927
        # Update menu and node definitions from manual sections to
449927
        # reflect the changes.
edaa9d
        ${FLAG_BACKEND}_updateMenu "remove-entry"
edaa9d
        ${FLAG_BACKEND}_updateNodes
4456e8
449927
        # Update cross reference definitions from manual to reflect
449927
        # the changes.
edaa9d
        ${FLAG_BACKEND}_deleteCrossReferences $MANUAL_ENTRY
f8fb31
4456e8
    done
4456e8
 
4c79b5
}