]> arthur.barton.de Git - netatalk.git/commitdiff
apple_dump: use open2(), from Oichinokata
authorHAT <hat@fa2.so-net.ne.jp>
Tue, 16 Oct 2012 13:55:39 +0000 (22:55 +0900)
committerHAT <hat@fa2.so-net.ne.jp>
Tue, 16 Oct 2012 13:55:39 +0000 (22:55 +0900)
contrib/shell_utils/apple_dump.in

index 6054e0f8bb26bb5a71382a9f3736619e981ba0f1..30dbb425ba957317765dbfb3d152b862e184be22 100755 (executable)
@@ -50,6 +50,7 @@ use File::Basename;
 use File::Spec;
 use File::Temp qw /tempfile/;
 use bigint; # require perl >= 5.8
+use IPC::Open2 qw /open2/;
 
 # check command for extended attributes -----------------------------------
 
@@ -841,50 +842,46 @@ sub hexdump {
 sub checkea {
     my ($file) = @_;
 
-    $file =~ s/\\/\\\\/g;
-    $file =~ s/\"/\\\"/g;
-    $file =~ s/\$/\\\$/g;
-    $file =~ s/\`/\\\`/g;
     if ( $eacommand == 1 ) {
-        open(EALIST, "getfattr \"$file\" |");
+        open2(\*EALIST, \*EAIN, 'getfattr', $file) or die $@;
         while(<EALIST>) {
             if ( $_ eq "user.org.netatalk.Metadata\n" ) {
-                close (EALIST);
+                close (EALIST, EAIN);
                 return 1;
             }
         }
-        close (EALIST);
+        close (EALIST, EAIN);
         return 0;
     } elsif ( $eacommand == 2 ) {
-        open(EALIST, "attr -q -l \"$file\" |");
+        open2(\*EALIST, \*EAIN, 'attr', '-q', '-l', $file) or die $@;
         while(<EALIST>) {
             if ( $_ eq "org.netatalk.Metadata\n" ) {
-                close (EALIST);
+                close (EALIST, EAIN);
                 return 1;
             }
         }
-        close (EALIST);
+        close (EALIST, EAIN);
         return 0;
     } elsif ( $eacommand == 3 ) {
-        open(EALIST, "runat \"$file\" ls -1 |");
+        open2(\*EALIST, \*EAIN, 'runat', $file, 'ls', '-1') or die $@;
         while(<EALIST>) {
             if ( $_ eq "org.netatalk.Metadata\n" ) {
-                close (EALIST);
+                close (EALIST, EAIN);
                 return 1;
             }
         }
-        close (EALIST);
+        close (EALIST, EAIN);
         return 0;
     } elsif ( $eacommand == 4 ) {
-        open(EALIST, "lsextattr -q user \"$file\" |");
+        open2(\*EALIST, \*EAIN, 'lsextattr', '-q', 'user', $file) or die $@;
         while(<EALIST>) {
             $_ = "\t".$_;
             if ( $_ =~ /\torg\.netatalk\.Metadata[\n\t]/ ) {
-                close (EALIST);
+                close (EALIST, EAIN);
                 return 1;
             }
         }
-        close (EALIST);
+        close (EALIST, EAIN);
         return 0;
     } else {
         return 0;
@@ -893,25 +890,24 @@ sub checkea {
 
 sub eaopenfile {
     my ($file) = @_;
-
-    $file =~ s/\\/\\\\/g;
-    $file =~ s/\"/\\\"/g;
-    $file =~ s/\$/\\\$/g;
-    $file =~ s/\`/\\\`/g;
-    ($eatempfh, $eatempfile) = tempfile(UNLINK => 1);
+    my @eacommands = ();
 
     if ( $eacommand == 1 ) {
-        system("getfattr --only-values -n user.org.netatalk.Metadata \"$file\" > $eatempfile");
+        @eacommands = ('getfattr', '--only-values', '-n', 'user.org.netatalk.Metadata', $file);
     } elsif ( $eacommand == 2 ) {
-        system("attr -q -g org.netatalk.Metadata \"$file\" > $eatempfile");
+        @eacommands = ('attr', '-q', '-g', 'org.netatalk.Metadata', $file);
     } elsif ( $eacommand == 3 ) {
-        system("runat \"$file\" cat org.netatalk.Metadata > $eatempfile");
+        @eacommands = ('runat', $file, 'cat', 'org.netatalk.Metadata',);
     } elsif ( $eacommand == 4 ) {
-        system("getextattr -q user org.netatalk.Metadata \"$file\" > $eatempfile");
+        @eacommands = ('getextattr', '-q', 'user', 'org.netatalk.Metadata', $file);
     } else {
         return "";
     }
 
+    my ($eatempfh, $eatempfile) = tempfile(UNLINK => 1);
+    open2(my $ealist, my $eain, @eacommands) or die $@;
+    print $eatempfh $_ while(<$ealist>);
+    close($ealist, $eain);
     close($eatempfh);
     return $eatempfile;
 }