[pve-devel] [PATCH RFC manager 1/8] aplinfo: replace system() with run_command/rename

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Aug 23 16:27:17 CEST 2016


---
 PVE/API2/Nodes.pm |  2 +-
 PVE/APLInfo.pm    | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 8487518..93e793e 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -1133,7 +1133,7 @@ __PACKAGE__->register_method({
 		    die "wrong checksum: $md5 != $pd->{md5sum}\n";
 		}
 
-		if (system ('mv', $tmpdest, $dest) != 0) {
+		if (!rename($tmpdest, $dest)) {
 		    die "unable to save file - $!\n";
 		}
 	    };
diff --git a/PVE/APLInfo.pm b/PVE/APLInfo.pm
index 1f51918..c68db76 100644
--- a/PVE/APLInfo.pm
+++ b/PVE/APLInfo.pm
@@ -3,6 +3,7 @@ package PVE::APLInfo;
 use strict;
 use IO::File;
 use PVE::SafeSyslog;
+use PVE::Tools;
 use LWP::UserAgent;
 use POSIX qw(strftime);
 
@@ -181,9 +182,10 @@ sub download_aplinfo {
 	    die "update failed - no data file '$aplsrcurl'\n";
 	}
  
-	if (system("zcat -f $tmpgz >$tmp 2>/dev/null") != 0) {
-	    die "update failed: unable to unpack '$tmpgz'\n";
-	} 
+       eval {
+           PVE::Tools::run_command(["gunzip", "-f", $tmpgz]);
+       };
+       die "update failed: unable to unpack '$tmpgz'\n" if $@;
 
 	# verify signature
 
@@ -226,7 +228,7 @@ sub download_aplinfo {
 	};
 	die "update failed: $@" if $@;
 
-	if (system("mv $tmp $aplinfodir/$host 2>/dev/null") != 0) { 
+	if (!rename($tmp, "$aplinfodir/$host")) {
 	    die "update failed: unable to store data\n";
 	}
 
@@ -256,7 +259,7 @@ sub update {
 
     my $size;
     if (($size = (-s $logfile) || 0) > (1024*50)) {
-	system ("mv $logfile $logfile.0");
+	rename($logfile, "$logfile.0");
     }
     my $logfd = IO::File->new (">>$logfile");
     logmsg($logfd, "starting update");
-- 
2.1.4





More information about the pve-devel mailing list