Whamcloud - gitweb
LU-2302 scripts: null-terminated file lists in lfs_migrate
authorDaniel Kobras <d.kobras@science-computing.de>
Wed, 28 Nov 2012 18:12:24 +0000 (10:12 -0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 17 Dec 2012 06:43:45 +0000 (01:43 -0500)
New option -0 allows to use a null-terminated list of file names
on stdin. Changed internal lfs find to use null-terminates lists.

Signed-off-by: Daniel Kobras <d.kobras@science-computing.de>
Change-Id: Iccd928a766968a7513833035684d41a1060c4a4d
Reviewed-on: http://review.whamcloud.com/4700
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Keith Mannthey <keith.mannthey@intel.com>
lustre/scripts/lfs_migrate

index 1f35568..7d9386f 100755 (executable)
@@ -20,7 +20,7 @@ LFS=${LFS:-lfs}
 
 usage() {
     cat -- <<USAGE 1>&2
 
 usage() {
     cat -- <<USAGE 1>&2
-usage: lfs_migrate [-c <stripe_count>] [-h] [-l] [-n] [-q] [-R] [-s] [-y]
+usage: lfs_migrate [-c <stripe_count>] [-h] [-l] [-n] [-q] [-R] [-s] [-y] [-0]
                    [file|dir ...]
     -c <stripe_count>
        restripe file using the specified stripe count
                    [file|dir ...]
     -c <stripe_count>
        restripe file using the specified stripe count
@@ -31,6 +31,7 @@ usage: lfs_migrate [-c <stripe_count>] [-h] [-l] [-n] [-q] [-R] [-s] [-y]
     -R restripe file using default directory striping
     -s skip file data comparison after migrate
     -y answer 'y' to usage question
     -R restripe file using default directory striping
     -s skip file data comparison after migrate
     -y answer 'y' to usage question
+    -0 input file names on stdin are separated by a null character
 
 The -c <stripe_count> option may not be specified at the same time as
 the -R option.
 
 The -c <stripe_count> option may not be specified at the same time as
 the -R option.
@@ -47,7 +48,7 @@ USAGE
 OPT_CHECK=y
 OPT_STRIPE_COUNT=""
 
 OPT_CHECK=y
 OPT_STRIPE_COUNT=""
 
-while getopts "c:hlnqRsy" opt $*; do
+while getopts "c:hlnqRsy0" opt $*; do
     case $opt in
        c) OPT_STRIPE_COUNT=$OPTARG;;
        l) OPT_NLINK=y;;
     case $opt in
        c) OPT_STRIPE_COUNT=$OPTARG;;
        l) OPT_NLINK=y;;
@@ -56,6 +57,7 @@ while getopts "c:hlnqRsy" opt $*; do
        R) OPT_RESTRIPE=y;;
        s) OPT_CHECK="";;
        y) OPT_YES=y;;
        R) OPT_RESTRIPE=y;;
        s) OPT_CHECK="";;
        y) OPT_YES=y;;
+       0) OPT_NULL=y;;
        h|\?) usage;;
     esac
 done
        h|\?) usage;;
     esac
 done
@@ -89,7 +91,7 @@ $RSYNC --help 2>&1 | grep -q acls && RSYNC_OPTS="$RSYNC_OPTS -A"
 strings $(which $RSYNC) 2>&1 | grep -q lustre && LFS=:
 
 lfs_migrate() {
 strings $(which $RSYNC) 2>&1 | grep -q lustre && LFS=:
 
 lfs_migrate() {
-       while read OLDNAME; do
+       while IFS='' read -d '' OLDNAME; do
                $ECHO -n "$OLDNAME: "
 
                # avoid duplicate stat if possible
                $ECHO -n "$OLDNAME: "
 
                # avoid duplicate stat if possible
@@ -163,13 +165,17 @@ lfs_migrate() {
 }
 
 if [ "$#" -eq 0 ]; then
 }
 
 if [ "$#" -eq 0 ]; then
-       lfs_migrate
+       if [ "$OPT_NULL" ]; then
+               lfs_migrate
+       else
+               tr '\n' '\0' | lfs_migrate
+       fi
 else
        while [ "$1" ]; do
                if [ -d "$1" ]; then
 else
        while [ "$1" ]; do
                if [ -d "$1" ]; then
-                       lfs find "$1" -type f | lfs_migrate
+                       lfs find "$1" -type f -print0 | lfs_migrate
                else
                else
-                       echo $1 | lfs_migrate
+                       echo -en "$1\0" | lfs_migrate
                fi
                shift
        done
                fi
                shift
        done