DO NOT REPLY [Bug 4621] "-p" option to simulate "mkdir -p" for rsync

samba-bugs at samba.org samba-bugs at samba.org
Tue Sep 4 18:32:58 GMT 2007


https://bugzilla.samba.org/show_bug.cgi?id=4621





------- Comment #1 from hq4ever at gmail.com  2007-09-04 13:32 CST -------
Hi,

I would like to add that I've created a wrapper for rsync to implemented this
functionality in the mean time, if/when it will be available via rsync itself.

Bash:

"""
function cp() {
# PARAMS:
#       $1 : What to Sync?
#       $2 : Where To?
#
        if [ $# -lt 1 ]; then
                echo "Usage: "
                echo " cp <source> <target>"
                echo " cp <source>"
                echo " cp <source> /absolute/path/to/file"
                exit 1
        fi

        # The following is a very strange way to load last variable into
RSYNC_TARGET (don't ask...)
        for RSYNC_TARGET; do :; done

        # If the destination we got is not /absolute/path/to/somewhere, append
$TARGET_DIR
        #  infact, if we got empty target, assume root of TARGET_DIR

        # If we get full path - assume user tell us where to put it
        if [ "${RSYNC_TARGET:0:1}" != '/' ]; then
                RSYNC_TARGET="$TARGET_DIR/$RSYNC_TARGET"
        # Else if we got only 1 parameter, in this case - just take the file
name and store it under build root dir.
        elif [ $# -eq 1 ]; then
                RSYNC_TARGET="${TARGET_DIR}/${1##*/}"
        fi

        RSYNC_SOURCE="$1"

        # Are we syncing directory as source?
        # If we are syncing directory, then we need to make sure it exists for
rsync not fail.
        # If we are syncing multiple file selection, the destination must be a
directory.

        # If we are syncing multiple file selection, the destination must be a
directory.
        if [ -d "$RSYNC_SOURCE" -o $# -gt 2 ]; then
                # If target directory does not exists, create it.
                if [ ! -d "$RSYNC_TARGET" ]; then
                        mkdir -p "$RSYNC_TARGET"
                fi
        else # Anything other then a directory, make sure the dir path exists.
                if [ ! -d "${RSYNC_TARGET%/*}" ]; then
                        mkdir -p "${RSYNC_TARGET%/*}"
                fi
        fi


        # Load $1..$$-1 into bash array. Why? because this is <long param
with-spaces> safe.
        declare -a RSYNC_ACTION
        local RSYNC_ACTION

        # If we got only 1 parameter (only source).
        if [ $# -eq 1 ]; then
                RSYNC_ACTION[0]="$1"
                RSYNC_ACTION[1]="$RSYNC_TARGET"
        else
        # for more then one... load them all into array.
                for (( i=0; $# > 1; i++ ))
                do
                        RSYNC_ACTION[$i]="$1"
                        shift
                done
                RSYNC_ACTION[i++]="$RSYNC_TARGET"
        fi

        rsync --recursive --quiet --links --safe-links --hard-links --perms
--times --one-file-system --exclude='.svn' "${RSYNC_ACTION[@]}"
}


-- 
Configure bugmail: https://bugzilla.samba.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.


More information about the rsync mailing list