summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-08-11 11:40:43 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-08-11 11:40:43 +0000
commit58c4003c40a63ce57cc587b4651926c3a34c3632 (patch)
tree7d24d46e6c85915e0a88acc07c3b13defea9aead /urpm
parentf71c4570e3918f9fb10e633cce55a214f476d828 (diff)
downloadurpmi-58c4003c40a63ce57cc587b4651926c3a34c3632.tar
urpmi-58c4003c40a63ce57cc587b4651926c3a34c3632.tar.gz
urpmi-58c4003c40a63ce57cc587b4651926c3a34c3632.tar.bz2
urpmi-58c4003c40a63ce57cc587b4651926c3a34c3632.tar.xz
urpmi-58c4003c40a63ce57cc587b4651926c3a34c3632.zip
- all tools
o new option --wait-lock (#13025)
Diffstat (limited to 'urpm')
-rw-r--r--urpm/args.pm4
-rw-r--r--urpm/lock.pm43
-rw-r--r--urpm/media.pm9
3 files changed, 29 insertions, 27 deletions
diff --git a/urpm/args.pm b/urpm/args.pm
index 68feea57..b5694863 100644
--- a/urpm/args.pm
+++ b/urpm/args.pm
@@ -52,6 +52,7 @@ my %options_spec_all = (
'q|quiet' => sub { --$options{verbose} },
'v|verbose' => sub { ++$options{verbose} },
'urpmi-root=s' => sub { urpm::set_files($urpm, $_[1]) },
+ 'wait-lock' => \$options{wait_lock},
'use-copied-hdlist' => sub { $urpm->{options}{use_copied_hdlist} = 1 },
);
@@ -422,6 +423,9 @@ sub parse_cmdline {
if ($options{probe_with} && $options{probe_with} eq 'rpms' && $options{virtual}) {
die N("Can't use %s with %s", "--probe-rpms", "--virtual");
}
+ if ($options{nolock} && $options{wait_lock}) {
+ warn N("Can't use %s with %s", "--wait-lock", "--nolock") . "\n";
+ }
if ($tool eq 'urpmf' && @ARGV && $ARGV[0] eq '--') {
if (@ARGV == 2) {
my $p = $ARGV[1];
diff --git a/urpm/lock.pm b/urpm/lock.pm
index 0b9cf7f7..dbd237ba 100644
--- a/urpm/lock.pm
+++ b/urpm/lock.pm
@@ -15,22 +15,25 @@ my ($LOCK_SH, $LOCK_EX, $LOCK_NB, $LOCK_UN) = (1, 2, 4, 8);
#- lock policy concerning chroot :
# - lock rpm db in chroot
# - lock urpmi db in /
+# (options: nofatal, wait)
sub rpm_db {
- my ($urpm, $b_exclusive) = @_;
+ my ($urpm, $b_exclusive, %options) = @_;
my $f = ($urpm->{root} && !$urpm->{urpmi_root} ? "$urpm->{root}/" : '') . "$urpm->{statedir}/.RPMLOCK";
- urpm::lock->new($urpm, $f, 'rpm', $b_exclusive);
+ urpm::lock->new($urpm, $f, 'rpm', $b_exclusive, %options);
}
+# (options: nofatal, wait)
sub urpmi_db {
- my ($urpm, $b_exclusive, $b_nofatal) = @_;
- urpm::lock->new($urpm, "$urpm->{statedir}/.LOCK", 'urpmi', $b_exclusive, $b_nofatal);
+ my ($urpm, $b_exclusive, %options) = @_;
+ urpm::lock->new($urpm, "$urpm->{statedir}/.LOCK", 'urpmi', $b_exclusive, %options);
}
################################################################################
#- methods
+# (options: nofatal, wait)
sub new {
- my ($_class, $urpm, $file, $db_name, $b_exclusive, $b_nofatal) = @_;
+ my ($_class, $urpm, $file, $db_name, $b_exclusive, %options) = @_;
my $fh;
#- we don't care what the mode is. ">" allow creating the file, but can't be done as user
@@ -38,40 +41,34 @@ sub new {
my $lock = bless {
fh => $fh, db_name => $db_name,
- fatal => $b_nofatal ? $urpm->{error} : sub { $urpm->{fatal}(7, $_[0]) },
+ fatal => $options{nofatal} ? $urpm->{error} : sub { $urpm->{fatal}(7, $_[0]) },
+ info => $urpm->{info},
log => $urpm->{log},
};
- _lock($lock, $b_exclusive);
+ _lock($lock, $b_exclusive, $options{wait});
$lock;
}
-sub _flock_failed {
- my ($lock) = @_;
- $lock->{fatal}(N("%s database locked", $lock->{db_name}));
-}
-
sub _lock {
- my ($lock, $b_exclusive) = @_;
+ my ($lock, $b_exclusive, $b_wait) = @_;
$b_exclusive ||= '';
if ($lock->{log}) {
my $action = $lock->{exclusive} && !$b_exclusive ? 'releasing exclusive' : $b_exclusive ? 'getting exclusive' : 'getting';
$lock->{log}("$action lock on $lock->{db_name}");
}
my $mode = $b_exclusive ? $LOCK_EX : $LOCK_SH;
- flock $lock->{fh}, $mode|$LOCK_NB or _flock_failed($lock);
+ if (!flock($lock->{fh}, $mode | $LOCK_NB)) {
+ if ($b_wait) {
+ $lock->{info}(N("%s database locked. waiting...", $lock->{db_name}));
+ flock($lock->{fh}, $mode) or $lock->{fatal}(N("aborting"));
+ } else {
+ $lock->{fatal}(N("%s database locked", $lock->{db_name}));
+ }
+ }
$lock->{locked} = 1;
$lock->{exclusive} = $b_exclusive;
}
-sub get_exclusive {
- my ($lock) = @_;
- _lock($lock, 'exclusive');
-}
-sub release_exclusive {
- my ($lock) = @_;
- _lock($lock);
-}
-
sub unlock {
my ($lock) = @_;
$lock->{fh} or warn "lock $lock->{db_name} already released\n", return;
diff --git a/urpm/media.pm b/urpm/media.pm
index 16384249..883e5dce 100644
--- a/urpm/media.pm
+++ b/urpm/media.pm
@@ -1539,12 +1539,12 @@ sub _get_pubkey_and_descriptions {
}
sub _read_cachedir_pubkey {
- my ($urpm, $medium) = @_;
+ my ($urpm, $medium, $b_wait_lock) = @_;
-s "$urpm->{cachedir}/partial/pubkey" or return;
$urpm->{log}(N("examining pubkey file of \"%s\"...", $medium->{name}));
- my $_rpm_lock = urpm::lock::rpm_db($urpm, 'exclusive');
+ my $_rpm_lock = urpm::lock::rpm_db($urpm, 'exclusive', wait => $b_wait_lock);
my %key_ids;
$urpm->import_needed_pubkeys(
@@ -1779,6 +1779,7 @@ sub _update_media__handle_some_flags {
#- nopubkey : don't use rpm pubkeys
#- probe_with : probe synthesis or hdlist (or none)
#- quiet : download hdlists quietly
+#- wait_lock : block until lock can be acquired
sub update_media {
my ($urpm, %options) = @_;
@@ -1787,7 +1788,7 @@ sub update_media {
$options{nopubkey} ||= $urpm->{options}{nopubkey};
if (!$options{nopubkey} && !$urpm->{keys}) {
#- get gpg-pubkey signature.
- my $_rpm_lock = urpm::lock::rpm_db($urpm);
+ my $_rpm_lock = urpm::lock::rpm_db($urpm, '', wait => $options{wait_lock});
$urpm->{log}(qq(getting "gpg-pubkey"s from rpmdb));
$urpm->parse_pubkeys(root => $urpm->{root});
}
@@ -1827,7 +1828,7 @@ sub update_media {
if ($medium->{really_modified}) {
_get_pubkey_and_descriptions($urpm, $medium, $options{nopubkey});
- _read_cachedir_pubkey($urpm, $medium);
+ _read_cachedir_pubkey($urpm, $medium, $options{wait_lock});
generate_medium_names($urpm, $medium);
}
}