package urpm;
# $Id$
use strict;
use MDK::Common;
use File::Find ();
use urpm::msg;
use urpm::download;
use urpm::util;
use urpm::sys;
use urpm::cfg;
our $VERSION = '4.6.1';
our @ISA = qw(URPM);
use URPM;
use URPM::Resolve;
use POSIX;
BEGIN {
# this won't work in 5.10 when encoding::warnings will be lexical
if ($ENV{DEBUG_URPMI}) {
require encoding::warnings;
encoding::warnings->import;
}
}
#- create a new urpm object.
sub new {
my ($class) = @_;
my $self;
$self = bless {
# from URPM
depslist => [],
provides => {},
config => "/etc/urpmi/urpmi.cfg",
skiplist => "/etc/urpmi/skip.list",
instlist => "/etc/urpmi/inst.list",
statedir => "/var/lib/urpmi",
cachedir => "/var/cache/urpmi",
media => undef,
options => {},
proxy => get_proxy(),
#- sync: first argument is options hashref, others are urls to fetch.
sync => sub { $self->sync_webfetch(@_) },
fatal => sub { printf STDERR "%s\n", $_[1]; exit($_[0]) },
error => sub { printf STDERR "%s\n", $_[0] },
log => sub { printf STDERR "%s\n", $_[0] },
ui_msg => sub { $self->{log}($_[0]); $self->{ui} and $self->{ui}{msg}->($_[1]) },
}, $class;
$self->set_nofatal(1);
$self;
}
#- syncing algorithms.
#- currently wget and curl methods are implemented; trying to find the best
#- (and one which will work :-)
sub sync_webfetch {
my $urpm = shift @_;
my $options = shift @_;
my %files;
#- currently ftp and http protocols are managed by curl or wget,
#- ssh and rsync protocols are managed by rsync *AND* ssh.
foreach (@_) {
/^([^:_]*)[^:]*:/ or die N("unknown protocol defined for %s", $_);
push @{$files{$1}}, $_;
}
if ($files{removable} || $files{file}) {
eval {
sync_file($options, @{$files{removable} || []}, @{$files{file} || []});
};
$urpm->{fatal}(10, $@) if $@;
delete @files{qw(removable file)};
}
if ($files{ftp} || $files{http} || $files{https}) {
my @webfetch = qw(curl wget);
my @available_webfetch = grep { -x "/usr/bin/$_" } @webfetch;
my $preferred;
|