use URI::Escape;
use Encode;
use Digest::SHA1;
+use Text::ParseWords;
+use String::ShellQuote;
our @EXPORT_OK = qw(
lock_file
my $outfh = IO::File->new ($filename, O_WRONLY|O_CREAT|O_EXCL, $perm) ||
die "unable to create output file '$filename' - $!\n";
- chown $wwwid, $outfh;
+ chown $wwwid, -1, $outfh;
return $outfh;
};
sub shellquote {
my $str = shift;
- return "''" if !defined ($str) || ($str eq '');
-
- die "unable to quote string containing null (\\000) bytes"
- if $str =~ m/\x00/;
-
- # from String::ShellQuote
- if ($str =~ m|[^\w!%+,\-./:@^]|) {
-
- # ' -> '\''
- $str =~ s/'/'\\''/g;
-
- $str = "'$str'";
- $str =~ s/^''//;
- $str =~ s/''$//;
- }
-
- return $str;
+ return String::ShellQuote::shell_quote($str);
}
-# a clumsy way to split an shell argument string into an array,
-# we simply pass it to the cli (exec call)
-# fixme: use Text::ParseWords::shellwords() ?
+# split an shell argument string into an array,
sub split_args {
my ($str) = @_;
- my $args = [];
-
- return $args if !$str;
-
- my $cmd = 'perl -e \'foreach my $a (@ARGV) { print "$a\n"; } \' -- ' . $str;
-
- eval {
- run_command($cmd, outfunc => sub {
- my $data = shift;
- push @$args, $data;
- });
- };
-
- my $err = $@;
-
- die "unable to parse args: $str\n" if $err;
-
- return $args;
+ return $str ? [ Text::ParseWords::shellwords($str) ] : [];
}
1;