summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
Diffstat (limited to 'urpm')
-rw-r--r--urpm/media.pm14
-rw-r--r--urpm/removable.pm20
-rw-r--r--urpm/sys.pm21
3 files changed, 32 insertions, 23 deletions
diff --git a/urpm/media.pm b/urpm/media.pm
index 6aff6977..2e8abb70 100644
--- a/urpm/media.pm
+++ b/urpm/media.pm
@@ -403,20 +403,14 @@ sub probe_removable_device {
#- try to find device to open/close for removable medium.
if (my $dir = file_from_local_url($medium->{url})) {
- my %infos;
- my @mntpoints = urpm::sys::find_mntpoints($dir, \%infos);
- if (@mntpoints > 1) { #- return value is suitable for an hash.
- $urpm->{log}(N("too many mount points for removable medium \"%s\"", $medium->{name}));
- $urpm->{log}(N("taking removable device as \"%s\"", join ',', map { $infos{$_}{device} } @mntpoints));
- }
if (urpm::removable::is_iso($medium->{removable})) {
$urpm->{log}(N("Medium \"%s\" is an ISO image, will be mounted on-the-fly", $medium->{name}));
- } elsif (@mntpoints) {
- if ($medium->{removable} && $medium->{removable} ne $infos{$mntpoints[-1]}{device}) {
+ } elsif (my $entry = urpm::sys::find_a_mntpoint($dir)) {
+ if ($medium->{removable} && $medium->{removable} ne $entry->{device}) {
$urpm->{log}(N("using different removable device [%s] for \"%s\"",
- $infos{$mntpoints[-1]}{device}, $medium->{name}));
+ $entry->{device}, $medium->{name}));
}
- $medium->{removable} = $infos{$mntpoints[-1]}{device};
+ $medium->{removable} = $entry->{device};
} else {
$urpm->{error}(N("unable to retrieve pathname for removable medium \"%s\"", $medium->{name}));
}
diff --git a/urpm/removable.pm b/urpm/removable.pm
index 80bfbd20..80a2004c 100644
--- a/urpm/removable.pm
+++ b/urpm/removable.pm
@@ -23,13 +23,13 @@ sub try_mounting {
my ($urpm, $dir, $o_removable) = @_;
my $is_iso = is_iso($o_removable);
- my @mntpoints = $is_iso
+ my $mntpoint = $is_iso
#- note: for isos, we don't parse the fstab because it might not be declared in it.
#- so we try to remove suffixes from the dir name until the dir exists
? ($dir = urpm::sys::trim_until_d($dir))
- : _non_mounted_mntpoints($dir);
+ : _non_mounted_mntpoint($dir);
- foreach my $mntpoint (@mntpoints) {
+ if ($mntpoint) {
$urpm->{log}(N("mounting %s", $mntpoint));
if ($is_iso) {
#- to mount an iso image, grab the first loop device
@@ -49,7 +49,7 @@ sub try_mounting {
sub try_umounting {
my ($urpm, $dir) = @_;
- foreach my $mntpoint (reverse _mounted_mntpoints($dir)) {
+ if (my $mntpoint = _mounted_mntpoint($dir)) {
$urpm->{log}(N("unmounting %s", $mntpoint));
sys_log("umount $mntpoint");
system("umount '$mntpoint' 2>/dev/null");
@@ -59,18 +59,18 @@ sub try_umounting {
}
#- side-effects: none
-sub _mounted_mntpoints {
+sub _mounted_mntpoint {
my ($dir) = @_;
- my %infos;
$dir = reduce_pathname($dir);
- grep { $infos{$_}{mounted} } urpm::sys::find_mntpoints($dir, \%infos);
+ my $entry = urpm::sys::find_a_mntpoint($dir);
+ $entry->{mounted} && $entry->{mntpoint};
}
#- side-effects: none
-sub _non_mounted_mntpoints {
+sub _non_mounted_mntpoint {
my ($dir) = @_;
- my %infos;
$dir = reduce_pathname($dir);
- grep { !$infos{$_}{mounted} } urpm::sys::find_mntpoints($dir, \%infos);
+ my $entry = urpm::sys::find_a_mntpoint($dir);
+ !$entry->{mounted} && $entry->{mntpoint};
}
#- side-effects: $urpm->{removable_mounted}
diff --git a/urpm/sys.pm b/urpm/sys.pm
index 4dc160c1..d4484458 100644
--- a/urpm/sys.pm
+++ b/urpm/sys.pm
@@ -39,9 +39,24 @@ sub _read_fstab_or_mtab {
@l;
}
-#- find used mount point from a pathname
+sub find_a_mntpoint {
+ my ($dir) = @_;
+ _find_a_mntpoint($dir, {});
+}
+
+# deprecated
sub find_mntpoints {
my ($dir, $infos) = @_;
+ if (my $entry = _find_a_mntpoint($dir, $infos)) {
+ $entry->{mntpoint};
+ } else {
+ ();
+ }
+}
+
+#- find used mount point from a pathname
+sub _find_a_mntpoint {
+ my ($dir, $infos) = @_;
#- read /etc/fstab and check for existing mount point.
foreach (_read_fstab_or_mtab("/etc/fstab")) {
@@ -66,13 +81,13 @@ sub find_mntpoints {
#- will go outside the device itself (or at least will go into
#- regular already mounted device like /).
#- for simplification we refuse also any other device and stop here.
- return $pdir;
+ return $infos->{$pdir};
} elsif (-l $pdir) {
unshift @paths, split '/', _expand_symlink($pdir);
$pdir = '';
}
}
- ();
+ undef;
}
sub _expand_symlink {