use File::Spec;
use File::Temp qw /tempfile/;
use bigint; # require perl >= 5.8
+use IPC::Open2 qw /open2/;
# check command for extended attributes -----------------------------------
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;
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;
}