]> arthur.barton.de Git - netatalk.git/blobdiff - contrib/shell_utils/apple_dump.in
Merge remote branch 'sf/product-2-2' into develop
[netatalk.git] / contrib / shell_utils / apple_dump.in
index e98ad357e31a7dcc70ab30706023ffb55618d30f..e207151d5c3f1d625a1e7ac953f21efc3a3859b7 100755 (executable)
@@ -59,6 +59,8 @@ if (     0 == system("which getfattr > /dev/null 2>&1")) {
     $eacommand = 2;
 } elsif (0 == system("which runat > /dev/null 2>&1")) {
     $eacommand = 3;
+} elsif (0 == system("which getextattr > /dev/null 2>&1")) {
+    $eacommand = 4;
 } else {
     $eacommand = 0;
 }
@@ -67,18 +69,20 @@ if (     0 == system("which getfattr > /dev/null 2>&1")) {
 
 # parse command line -----------------------------------------------
 
+$stdinputmode = 0;
 $eaoption = 0;
 $finderinfo = 0;              #  0: unknown   1: file   2: directory
 while ($arg = shift @ARGV)
 {
     if  ($arg =~ /^(-h|-help|--help)$/ ) {
-        printf ("usage: %s [-a] FILE|DIR\n"           ,basename($0));
+        printf ("usage: %s [-a] [FILE|DIR]\n"         ,basename($0));
         printf (" or:   %s -e FILE|DIR\n"             ,basename($0));
-        printf (" or:   %s -f FILE\n"                 ,basename($0));
-        printf (" or:   %s -d FILE\n"                 ,basename($0));
+        printf (" or:   %s -f [FILE]\n"               ,basename($0));
+        printf (" or:   %s -d [FILE]\n"               ,basename($0));
         printf (" or:   %s -h|-help|--help\n"         ,basename($0));
         printf (" or:   %s -v|-version|--version\n"   ,basename($0));
         printf ("Dump AppleSingle/AppleDouble format data.\n");
+        printf ("With no FILE|DIR, or when FILE|DIR is -, read standard input.\n");
         printf ("\n");
         printf ("  -a (default)     Dump a AppleSingle/AppleDouble data for FILE or DIR\n");
         printf ("                   automatically.\n");
@@ -115,6 +119,8 @@ while ($arg = shift @ARGV)
         $finderinfo = 1;
     } elsif ($arg eq "-d") {
         $finderinfo = 2;
+    } elsif ($arg eq "-") {
+        $stdinputmode = 1;
     } elsif ($arg =~ /^-/) {
         printf (STDERR "%s: invalid option %s\n", basename($0), $arg);
         printf (STDERR "Try \`%s\ -h' for more information.\n", basename($0));
@@ -125,10 +131,8 @@ while ($arg = shift @ARGV)
 }
 
 if (!($afile)) {
-    printf (STDERR "missing file operand.\n");
-    exit 1;
-}
-if (!( -e $afile)) {
+    $stdinputmode = 1;
+} elsif (!( -e $afile)) {
     printf (STDERR "\"%s\" is not found.\n", $afile);
     exit 1;
 }
@@ -138,7 +142,12 @@ if (!( -e $afile)) {
 $abspath = File::Spec->rel2abs($afile);
 ($basename, $path, $ext) = fileparse($abspath);
 
-if ( $eaoption == 1 ) {
+if ( $stdinputmode == 1) {
+    ($eatempfh, $openfile) = tempfile(UNLINK => 1);
+    system("cat - > $openfile");
+    close($eatempfh);
+    $openmessage = "Dumping Standard Input...\n";
+} elsif ( $eaoption == 1 ) {
     if ( -f $afile ) {
         $finderinfo = 1;
     } elsif ( -d $afile ) {
@@ -155,6 +164,7 @@ if ( $eaoption == 1 ) {
     $openmessage = "Dumping \"$afile\"'s extended attribute...\n";
 } elsif ( $finderinfo != 0 ) {
     $openfile = $afile;
+    $openmessage = "Dumping \"$openfile\"...\n";
 } elsif ( -f $afile ) {
     if ( $basename eq ".Parent") {
         $finderinfo = 2;
@@ -192,6 +202,7 @@ if ( $eaoption == 1 ) {
         }
         if ( -e $netatalkfile ) {
             printf ("\"%s\" is found.\n", $netatalkfile);
+            $adcount++;
             $openfile = $netatalkfile;
             $openmessage = "Dumping \"$openfile\"...\n";
         }
@@ -864,6 +875,17 @@ sub checkea {
         }
         close (EALIST);
         return 0;
+    } elsif ( $eacommand == 4 ) {
+        open(EALIST, "lsextattr -q user \"$file\" |");
+        while(<EALIST>) {
+            $_ = "\t".$_;
+            if ( $_ =~ /\torg\.netatalk\.Metadata[\n\t]/ ) {
+                close (EALIST);
+                return 1;
+            }
+        }
+        close (EALIST);
+        return 0;
     } else {
         return 0;
     }
@@ -884,6 +906,8 @@ sub eaopenfile {
         system("attr -q -g org.netatalk.Metadata \"$file\" > $eatempfile");
     } elsif ( $eacommand == 3 ) {
         system("runat \"$file\" cat org.netatalk.Metadata > $eatempfile");
+    } elsif ( $eacommand == 4 ) {
+        system("getextattr -q user org.netatalk.Metadata \"$file\" > $eatempfile");
     } else {
         return "";
     }