summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-29 14:39:18 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-29 14:39:18 +0000
commitdf95f65347ad42a943b273e0bbaaf865826c93cc (patch)
treefd78a201e90f35fb22051d468df7b643de432383
parentd5358dfaa2c196e595693b09dee13da02578b5d7 (diff)
downloadurpmi-df95f65347ad42a943b273e0bbaaf865826c93cc.tar
urpmi-df95f65347ad42a943b273e0bbaaf865826c93cc.tar.gz
urpmi-df95f65347ad42a943b273e0bbaaf865826c93cc.tar.bz2
urpmi-df95f65347ad42a943b273e0bbaaf865826c93cc.tar.xz
urpmi-df95f65347ad42a943b273e0bbaaf865826c93cc.zip
factorize --nolock and --root option handling
-rw-r--r--urpm/args.pm21
-rw-r--r--urpme8
-rwxr-xr-xurpmi26
3 files changed, 24 insertions, 31 deletions
diff --git a/urpm/args.pm b/urpm/args.pm
index a8260803..b1d10f32 100644
--- a/urpm/args.pm
+++ b/urpm/args.pm
@@ -120,11 +120,11 @@ my %options_spec = (
'skip=s' => \$options{skip},
'root=s' => sub {
require File::Spec;
- $::root = File::Spec->rel2abs($_[1]);
- if (!-d $::root) {
+ $options{root} = File::Spec->rel2abs($_[1]);
+ if (!-d $options{root}) {
$urpm->{fatal}->(9, N("chroot directory doesn't exist"));
}
- $::nolock = 1;
+ $options{nolock} = 1;
},
'use-distrib=s' => \$options{usedistrib},
'probe-synthesis' => sub { $options{probe_with} = 'synthesis' },
@@ -137,7 +137,7 @@ my %options_spec = (
repackage => sub { $urpm->{options}{repackage} = 1 },
'more-choices' => sub { $urpm->{options}{morechoices} = 1 },
'expect-install!' => \$::expect_install,
- 'nolock' => \$::nolock,
+ 'nolock' => \$options{nolock},
restricted => \$::restricted,
'no-md5sum' => \$::nomd5sum,
'force-key' => \$::forcekey,
@@ -229,14 +229,6 @@ my %options_spec = (
sources => \$options{sources},
force => \$options{force},
'skip=s' => \$options{skip},
- 'root=s' => sub {
- require File::Spec;
- $options{root} = File::Spec->rel2abs($_[1]);
- if (!-d $options{root}) {
- $urpm->{fatal}->(9, N("chroot directory doesn't exist"));
- }
- $options{nolock} = 1;
- },
'use-distrib=s' => sub {
if ($< != 0) {
print STDERR N("You need to be root to use --use-distrib"), "\n";
@@ -246,7 +238,6 @@ my %options_spec = (
},
'parallel=s' => \$options{parallel},
'env=s' => \$options{env},
- 'nolock' => \$options{nolock},
d => \$options{deps},
u => \$options{upgrade},
a => \$options{all},
@@ -365,6 +356,10 @@ foreach my $k ("help|h", "version", "no-locales", "test!", "force", "root=s", "u
{
$options_spec{urpme}{$k} = $options_spec{urpmi}{$k};
}
+foreach my $k ("root=s", "nolock")
+{
+ $options_spec{urpmq}{$k} = $options_spec{urpmi}{$k};
+}
foreach my $k ("help|h", "version", "no-locales", "update", "media|mediums=s",
"excludemedia|exclude-media=s", "sortmedia|sort-media=s",
diff --git a/urpme b/urpme
index 613fd3fb..b4f3e045 100644
--- a/urpme
+++ b/urpme
@@ -31,7 +31,7 @@ use urpm::select;
$ENV{PATH} = "/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin";
delete @ENV{qw(ENV BASH_ENV IFS CDPATH)};
-our ($root, $test, $parallel, $auto, $matches, $verbose, $force, $noscripts, $repackage, @l, $bundle, $restricted);
+our ($test, $parallel, $auto, $matches, $verbose, $force, $noscripts, $repackage, @l, $bundle, $restricted);
# Translator: Add here the keys which might be pressed in the "Yes"-case.
my $yesexpr = N("Yy");
@@ -76,7 +76,7 @@ if ($< && !$test) {
#- rurpme checks
if ($restricted) {
- urpm::error_restricted($urpm) if $root || $options{usedistrib} || $noscripts || $parallel;
+ urpm::error_restricted($urpm) if $options{root} || $options{usedistrib} || $noscripts || $parallel;
}
unless ($test) {
@@ -87,7 +87,7 @@ unless ($test) {
my $_urpmi_lock = urpm::lock::urpmi_db($urpm);
urpm::media::configure($urpm,
synthesis => ($parallel ? 'none' : ''),
- root => $root,
+ root => $options{root},
parallel => $parallel,
probe_with => $options{probe_with},
usedistrib => $options{usedistrib},
@@ -117,7 +117,7 @@ my @toremove = urpm::select::find_packages_to_remove($urpm,
#- Warning : the following message is parsed in urpm::parallel_*
$urpm->{error}(N("removing package %s will break your system", $_));
} 0 },
- root => $root,
+ root => $options{root},
) or $urpm->{fatal}(0, N("Nothing to remove"));
my $list = urpm::select::translate_why_removed($urpm, $state, @toremove);
diff --git a/urpmi b/urpmi
index 9f0ec5bc..56d4c365 100755
--- a/urpmi
+++ b/urpmi
@@ -56,14 +56,12 @@ our $force = 0;
our $parallel = '';
our $env = '';
our $test = 0;
-our $root = '';
our $all = 0;
our $rpm_opt = "vh";
our $use_provides = 1;
our $verbose = 0;
our $logfile = '';
our $restricted = 0;
-our $nolock = 0;
our $nomd5sum = 0;
our $forcekey = 0;
@@ -222,7 +220,7 @@ if ($install_src) {
push @src_names, @names;
@names = ();
#- allow to use --install-src as a non-root user
- $nolock = 1;
+ $options{nolock} = 1;
}
#- rurpmi checks
@@ -231,7 +229,7 @@ if ($restricted) {
#- force some options
foreach (qw(keep verify-rpm)) { $urpm->{options}{$_} = 1 }
#- forbid some other options
- urpm::error_restricted($urpm) if $root || $options{usedistrib} || $force || $env || $parallel || $synthesis || $auto_update;
+ urpm::error_restricted($urpm) if $options{root} || $options{usedistrib} || $force || $env || $parallel || $synthesis || $auto_update;
foreach (qw(allow-nodeps allow-force curl-options rsync-options wget-options prozilla-options noscripts)) {
urpm::error_restricted($urpm) if $urpm->{options}{$_};
}
@@ -267,7 +265,7 @@ if ($env) {
}
}
-unless ($bug || $install_src || $env || $urpm->{options}{'allow-force'} || $root) {
+unless ($bug || $install_src || $env || $urpm->{options}{'allow-force'} || $options{root}) {
require urpm::sys;
urpm::sys::check_fs_writable() or $urpm->{fatal}(1, N("Error: %s appears to be mounted read-only.
Use --allow-force to force operation.", $urpm::sys::mountpoint));
@@ -335,10 +333,10 @@ if (exists $urpm->{options}{'priority-upgrade'} && $urpm->{options}{'priority-up
require urpm::sys;
urpm::sys::fix_fd_leak();
# also, clean up rpm db log files, because rpm might have been upgraded
- unlink glob('/var/lib/rpm/__db.*') unless $root;
+ unlink glob('/var/lib/rpm/__db.*') unless $options{root};
}
-my $urpmi_lock = !$env && !$nolock && urpm::lock::urpmi_db($urpm);
+my $urpmi_lock = !$env && !$options{nolock} && urpm::lock::urpmi_db($urpm);
#- should we ignore arch compatibility
if ($urpm->{options}{ignorearch}) { urpm::shunt_ignorearch() }
@@ -348,7 +346,7 @@ my %config_hash = (
media => $media,
nocheck_access => $env || $< != 0,
parallel => $parallel,
- root => $root,
+ root => $options{root},
searchmedia => $searchmedia,
cmdline_skiplist => $options{skip},
sortmedia => $sortmedia,
@@ -358,7 +356,7 @@ my %config_hash = (
probe_with => $options{probe_with},
);
-$root and $urpm->{options}{'priority-upgrade'} = '';
+$options{root} and $urpm->{options}{'priority-upgrade'} = '';
if ($auto_update && !$bug && !$env) {
#- For translators : there are several media here
$urpm->{log}(N("Updating media...\n"));
@@ -383,7 +381,7 @@ urpm::media::configure($urpm, %config_hash);
if ($bug) {
require urpm::bug_report;
- urpm::bug_report::rpmdb_to_synthesis($urpm, "$bug/rpmdb.cz", $root);
+ urpm::bug_report::rpmdb_to_synthesis($urpm, "$bug/rpmdb.cz", $options{root});
}
#- get back activated default values of boolean options.
@@ -403,7 +401,7 @@ if ($bug) {
urpm::bug_report::copy_requested($urpm, $bug, \%requested);
}
-my $rpm_lock = !$env && !$nolock && urpm::lock::rpm_db($urpm, 'exclusive');
+my $rpm_lock = !$env && !$options{nolock} && urpm::lock::rpm_db($urpm, 'exclusive');
#- search the packages according to the selection given by the user.
my $search_result = '';
@@ -515,7 +513,7 @@ if (@ask_unselect) {
my @ask_remove = $urpm->{options}{'allow-force'} ? @{[]} : urpm::select::removed_packages($urpm, $state);
if (@ask_remove) {
{
- my $db = urpm::db_open_or_die($urpm, $root);
+ my $db = urpm::db_open_or_die($urpm, $options{root});
urpm::select::find_removed_from_basesystem($urpm, $db, $state, sub {
my $urpm = shift @_;
foreach (@_) {
@@ -683,7 +681,7 @@ foreach my $set (@{$state->{transaction} || []}) {
#- install source package only (whatever the user is root or not, but use rpm for that).
if ($install_src) {
if (my @l = grep { /\.src\.rpm$/ } values %transaction_sources_install, values %transaction_sources) {
- system("rpm", "-i$rpm_opt", @l, ($root ? ("--root", $root) : @{[]}));
+ system("rpm", "-i$rpm_opt", @l, ($options{root} ? ("--root", $options{root}) : @{[]}));
#- Warning : the following message is parsed in urpm::parallel_*
if ($?) {
print N("Installation failed"), "\n";
@@ -834,7 +832,7 @@ if ($nok) {
}
}
-unless ($env || $nolock) {
+unless ($env || $options{nolock}) {
$urpmi_lock->unlock;
$rpm_lock->unlock;