From 5ed8cc71bb4a24dcf6b8f0e1ea2b655c1fc24713 Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Thu, 4 Nov 2004 16:22:30 +0000 Subject: Factor some system()s --- urpm/download.pm | 5 +++-- urpm/util.pm | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'urpm') diff --git a/urpm/download.pm b/urpm/download.pm index 734487d9..f9f4be2d 100644 --- a/urpm/download.pm +++ b/urpm/download.pm @@ -160,8 +160,9 @@ sub sync_file { foreach (@_) { my ($in) = m!^(?:removable[^:]*:/|file:/)(/.*)!; propagate_sync_callback($options, 'start', $_); - system("cp", "-p", "-R", $in || $_, ref($options) ? $options->{dir} : $options) - and die N("copy failed"); + require urpm::util; + urpm::util::copy($in || $_, ref($options) ? $options->{dir} : $options) + or die N("copy failed"); propagate_sync_callback($options, 'end', $_); } } diff --git a/urpm/util.pm b/urpm/util.pm index eb2fc912..8abb816e 100644 --- a/urpm/util.pm +++ b/urpm/util.pm @@ -75,7 +75,17 @@ sub offset_pathname { sub md5sum { #- Use an external command to avoid depending on perl my ($file) = @_; - return( (split ' ', `md5sum '$file'`)[0] ); + return((split ' ', `md5sum '$file'`)[0]); +} + +sub copy { + my ($file, $dest) = @_; + !system("/bin/cp", "-p", "-R", $file, $dest); +} + +sub move { + my ($file, $dest) = @_; + rename($file, $dest) or !system("/bin/mv", "-f", $file, $dest); } 1; -- cgit v1.2.1