Explorar o código

Ticket #585 - Behaviours of "db2ldif -a <filename>" and "db2ldif.pl -a <filename>" are inconsistent

Bug description: If -a "filename" is given to db2ldif or
db2ldif.pl and it is not a full path representation, the
file is not created in the location relative to the
current working directory.

Fix description: This patch gets the current working
directory in the both utilities, and completes the path
relative to the current working directory.

https://fedorahosted.org/389/ticket/585

Reviewed by Rich (Thanks!!)
Noriko Hosoi %!s(int64=12) %!d(string=hai) anos
pai
achega
919585769b

+ 20 - 4
ldap/admin/src/scripts/db2ldif.in

@@ -11,6 +11,8 @@ export LD_LIBRARY_PATH
 SHLIB_PATH=$LD_LIBRARY_PATH
 export SHLIB_PATH
 
+cwd=`pwd`
+
 usage()
 {
     echo "Usage: db2ldif [-Z serverID] {-n backend_instance}* | {-s includesuffix}* [{-x excludesuffix}*] [-a outputfile]"
@@ -39,8 +41,21 @@ make_ldiffile()
     do
         if [ "$1" = "-a" ]; then
             shift
-            echo $1
-            return 1
+            if [ `expr "$1" : "/.*"` -gt 0 ]; then 
+	            if [ `expr "$1" : "/.*"` -gt 0 ]; then 
+	                # full path 
+	                echo $1 
+	                return 1 
+	            else 
+	                echo $cwd/$1 
+	                shift 
+	                return 0 
+	            fi 
+            else 
+                echo $cwd/$1 
+                shift 
+                return 0 
+            fi
         elif [ "$1" = "-n" ]; then
             shift
             if [ "$be" = "" ]; then
@@ -83,7 +98,7 @@ then
     exit 1
 fi
     
-while getopts "hZ:n:s:x:a:NrCuUmM1qvd:D:ESt:o" flag
+while getopts "hZ:n:s:x:a:NrCuUmM1qvd:D:ESt:oc:" flag
 do
     case $flag in
         h) usage
@@ -110,6 +125,7 @@ do
         M) args=$args" -M";;
         1) args=$args" -1";;
         q) args=$args" -q";;        
+        c) cwd=$OPTARG;;
         ?) usage
            exit 1;;
     esac
@@ -140,5 +156,5 @@ if [ $rn -eq 1 ]
 then
     @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix $outputFile $args
 else
-    @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix -a $ldif_file $args
+    @sbindir@/ns-slapd db2ldif -D $configdir $benameopt $includeSuffix $excludeSuffix $args -a $ldif_file
 fi

+ 9 - 1
ldap/admin/src/scripts/db2ldif.pl.in

@@ -41,6 +41,7 @@
 
 use lib qw(@perlpath@);
 use DSUtil;
+use Cwd;
 
 DSUtil::libpath_add("@nss_libdir@");
 DSUtil::libpath_add("/usr/lib");
@@ -63,6 +64,7 @@ $insti = 0;
 $incli = 0;
 $excli = 0;
 $decrypt_on_export = 0;
+$cwd = cwd();
 
 sub usage {
     print(STDERR "Usage: db2ldif.pl [-v] [-Z serverID] [-D rootdn] { -w password | -w - | -j pwfilename }\n");
@@ -177,6 +179,8 @@ while ($i <= $#ARGV) {
         $i++; $protocol = $ARGV[$i];
     } elsif ("$ARGV[$i]" eq "-v") {    # verbose
         $verbose = 1;
+    } elsif ("$ARGV[$i]" eq "-c") {    # cwd
+        $i++; $cwd = $ARGV[$i];
     } else {
         &usage; exit(1);
     }
@@ -247,7 +251,11 @@ if ($ldiffile eq "") {
     } else {
         $ldiffile = "${ldifdir}/${servid}-${be}-${yr}_${mn}_${dy}_${h}_${m}_${s}.ldif";
     }
-}
+} elsif ($ldiffile =~ "^/") { 
+    ; # full path 
+} else { 
+    $ldiffile = $cwd . "/" . $ldiffile; 
+} 
 $nsreplica = "";
 if ($doreplica != 0) { $nsreplica = "nsExportReplica: true\n"; }
 $nsnobase64 = "";

+ 3 - 2
ldap/admin/src/scripts/template-db2ldif.in

@@ -1,5 +1,6 @@
 #!/bin/sh
 
+cwd=`pwd`
 cd {{SERVERBIN-DIR}}
-./db2ldif "$@" -Z {{SERV-ID}}
-exit $?
+./db2ldif "$@" -Z {{SERV-ID}} -c $cwd
+exit $?

+ 5 - 1
ldap/admin/src/scripts/template-db2ldif.pl.in

@@ -39,6 +39,8 @@
 # END COPYRIGHT BLOCK
 #
 
+use Cwd;
+
 # We lose args that are quoted when passing ARGV to a wrapper
 while ($i <= $#ARGV) {
         if($ARGV[$i] =~ /^-/){
@@ -49,6 +51,8 @@ while ($i <= $#ARGV) {
         $i++;
 }
 
-exec "{{SERVERBIN-DIR}}/db2ldif.pl @wrapperArgs -Z {{SERV-ID}}";
+$cwd = cwd();
+
+exec "{{SERVERBIN-DIR}}/db2ldif.pl -c $cwd @wrapperArgs -Z {{SERV-ID}}";
 
 exit ($?);