aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-05-06 09:22:51 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-05-06 09:22:51 +0000
commitec5da158151c83d01c297bf229f4d55d3da54032 (patch)
treec97c7c96f35ffe646691a427e1bedc9808fe56fa
parent02416c02cb77fdd6ac3c76edb8a070b5f0a6c527 (diff)
downloadperl-URPM-ec5da158151c83d01c297bf229f4d55d3da54032.tar
perl-URPM-ec5da158151c83d01c297bf229f4d55d3da54032.tar.gz
perl-URPM-ec5da158151c83d01c297bf229f4d55d3da54032.tar.bz2
perl-URPM-ec5da158151c83d01c297bf229f4d55d3da54032.tar.xz
perl-URPM-ec5da158151c83d01c297bf229f4d55d3da54032.zip
Add a way to downgrade some errors (file not found) to non-fatal
-rw-r--r--MANIFEST1
-rw-r--r--URPM.pm20
-rw-r--r--URPM.xs25
-rw-r--r--URPM/Resolve.pm4
-rw-r--r--t/fatal.t23
5 files changed, 56 insertions, 17 deletions
diff --git a/MANIFEST b/MANIFEST
index 442bdfa..ec0c410 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -8,6 +8,7 @@ URPM/Build.pm
URPM/Query.pm
URPM/Resolve.pm
URPM/Signature.pm
+t/fatal.t
t/parse.t
t/rpmdb.t
t/synthesis.t
diff --git a/URPM.pm b/URPM.pm
index ee8529f..ea242d2 100644
--- a/URPM.pm
+++ b/URPM.pm
@@ -15,15 +15,17 @@ our $VERSION = '0.94';
URPM->bootstrap($VERSION);
sub new {
- my ($class) = @_;
- bless {
- depslist => [],
- provides => {},
- media => [],
- options => {},
- }, $class;
+ my ($class, %options) = @_;
+ my $self = bless {
+ depslist => [],
+ provides => {},
+ }, $class;
+ $self->{nofatal} = 1 if $options{nofatal};
+ $self;
}
+sub set_nofatal { $_[0]->{nofatal} = $_[1] }
+
sub search {
my ($urpm, $name, %options) = @_;
my $best;
@@ -205,6 +207,10 @@ C<URPM::Package> objects).
B<provides> is an hashref containing as keys the list of items provided by the
URPM object.
+If the constructor is called with the arguments C<< nofatal => 1 >>, various
+fatal error messages are suppressed (file not found in parse_hdlist() and
+parse_synthesis()).
+
=item read_config_files()
Force the re-reading of the RPM configuration files.
diff --git a/URPM.xs b/URPM.xs
index 7980c6f..6f0be1b 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -3324,9 +3324,14 @@ Urpm_parse_synthesis(urpm, filename, ...)
XPUSHs(sv_2mortal(newSViv(start_id)));
XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
}
- } else croak("unable to uncompress synthesis file %s", filename);
- } else croak("first argument should contains a depslist ARRAY reference");
- } else croak("first argument should be a reference to HASH");
+ } else {
+ SV **nofatal = hv_fetch((HV*)SvRV(urpm), "nofatal", 7, 0);
+ errno = ENOENT;
+ if (!nofatal || !SvIV(*nofatal))
+ croak("unable to uncompress synthesis file %s", filename);
+ }
+ } else croak("first argument should contain a depslist ARRAY reference");
+ } else croak("first argument should be a reference to a HASH");
void
Urpm_parse_hdlist(urpm, filename, ...)
@@ -3418,9 +3423,13 @@ Urpm_parse_hdlist(urpm, filename, ...)
XPUSHs(sv_2mortal(newSViv(start_id)));
XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
}
- } else croak("cannot open hdlist file %s", filename);
- } else croak("first argument should contains a depslist ARRAY reference");
- } else croak("first argument should be a reference to HASH");
+ } else {
+ SV **nofatal = hv_fetch((HV*)SvRV(urpm), "nofatal", 7, 0);
+ if (!nofatal || !SvIV(*nofatal))
+ croak("cannot open hdlist file %s", filename);
+ }
+ } else croak("first argument should contain a depslist ARRAY reference");
+ } else croak("first argument should be a reference to a HASH");
void
Urpm_parse_rpm(urpm, filename, ...)
@@ -3478,8 +3487,8 @@ Urpm_parse_rpm(urpm, filename, ...)
XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
XPUSHs(sv_2mortal(newSViv(av_len(depslist))));
} else free(_pkg);
- } else croak("first argument should contains a depslist ARRAY reference");
- } else croak("first argument should be a reference to HASH");
+ } else croak("first argument should contain a depslist ARRAY reference");
+ } else croak("first argument should be a reference to a HASH");
char *
Urpm_verify_rpm(filename, ...)
diff --git a/URPM/Resolve.pm b/URPM/Resolve.pm
index 853f0df..3b0e5ad 100644
--- a/URPM/Resolve.pm
+++ b/URPM/Resolve.pm
@@ -855,8 +855,8 @@ sub compute_installed_flags {
\%sizes;
}
-#- compute flags according to hash describing package to remove
-#- $skip is a hash reference described as follow :
+#- compute flags according to hash describing packages to remove
+#- $val is a hash reference described as follow :
#- key is package name or regular expression on fullname if /.../
#- value is reference to hash indicating sense information ({ '' => undef } if none).
#- options hash :
diff --git a/t/fatal.t b/t/fatal.t
new file mode 100644
index 0000000..5a98286
--- /dev/null
+++ b/t/fatal.t
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More tests => 8;
+use URPM;
+
+my $u = new URPM;
+
+eval { $u->parse_hdlist('non-existent'); };
+like( $@, qr/^cannot open hdlist file non-existent/, 'fatal error on hdlist not found' );
+is( $! + 0, $!{EBADF}, '$! is EBADF' );
+eval { $u->parse_synthesis('non-existent'); };
+like( $@, qr/^unable to uncompress synthesis file non-existent/, 'fatal error on synthesis not found' );
+is( $! + 0, $!{ENOENT}, '$! is ENOENT' );
+
+my $v = new URPM( nofatal => 1 );
+
+eval { $v->parse_hdlist('non-existent'); };
+is( $@, '', 'no error on hdlist not found' );
+is( $! + 0, $!{EBADF}, '$! is EBADF' );
+eval { $v->parse_synthesis('non-existent'); };
+is( $@, '', 'no error on synthesis not found' );
+is( $! + 0, $!{ENOENT}, '$! is ENOENT' );