]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/Tools.pm
fix bug #23: add gid parameter to chown call
[pve-common.git] / data / PVE / Tools.pm
index 5cd8460db707bbef381a02611afa188ba982a6a0..b991ba5afef2a2592d6519fe05057f6d5fffbaf7 100644 (file)
@@ -13,6 +13,8 @@ use base 'Exporter';
 use URI::Escape;
 use Encode;
 use Digest::SHA1;
+use Text::ParseWords;
+use String::ShellQuote;
 
 our @EXPORT_OK = qw(
 lock_file 
@@ -618,7 +620,7 @@ sub upid_open {
  
     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;
 };
@@ -690,49 +692,14 @@ sub random_ether_addr {
 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;