diff options
Diffstat (limited to 'urpm')
-rw-r--r-- | urpm/media.pm | 62 | ||||
-rw-r--r-- | urpm/removable.pm | 98 |
2 files changed, 85 insertions, 75 deletions
diff --git a/urpm/media.pm b/urpm/media.pm index 2317d80a..f421ad7a 100644 --- a/urpm/media.pm +++ b/urpm/media.pm @@ -233,8 +233,7 @@ sub add_existing_medium { check_existing_medium($urpm, $medium); - #- probe removable device. - probe_removable_device($urpm, $medium); + _migrate_removable_device($urpm, $medium); #- clear URLs for trailing /es. $medium->{url} and $medium->{url} =~ s|(.*?)/*$|$1|; @@ -390,32 +389,22 @@ sub remove_user_media_info_files { } #- probe device associated with a removable device. -sub probe_removable_device { +sub _migrate_removable_device { my ($urpm, $medium) = @_; - if ($medium->{url} && $medium->{url} =~ /^removable/) { - #- try to find device name in url scheme, this is deprecated, use medium option "removable" instead - if ($medium->{url} =~ /^removable_?([^_:]*)/) { - $medium->{removable} ||= $1 && "/dev/$1"; - } - } else { - delete $medium->{removable}; - return; - } + # always drop {removable}, it is obsolete + # (nb: for iso files, {removable} has already been renamed into {iso} internally) + delete $medium->{removable}; - #- try to find device to open/close for removable medium. - if (my $dir = file_from_local_medium($medium)) { - if (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\"", - $entry->{device}, $medium->{name})); - } - $medium->{removable} = $entry->{device}; + if ($medium->{url} && $medium->{url} =~ /^removable/) { + $medium->{url} =~ s!^removable(.*?)://!/!; + #- handle device name in url scheme, this is deprecated + if ($medium->{url} =~ s!/(mnt|media)/cd\w+/?!cdrom://!i) { + # success! } else { - $urpm->{error}(N("unable to retrieve pathname for removable medium \"%s\"", $medium->{name})); + $urpm->{error}(N("failed to migrate removable device, ignoring media")); + $medium->{ignore} = 1; } - } else { - $urpm->{error}(N("unable to retrieve pathname for removable medium \"%s\"", $medium->{name})); } } @@ -679,7 +668,7 @@ sub add_medium { if ($options{virtual}) { $medium->{virtual} = 1; } else { - probe_removable_device($urpm, $medium); + _migrate_removable_device($urpm, $medium); } if (!$medium->{url} && $options{mirrorlist}) { @@ -739,9 +728,11 @@ sub add_distrib_media { my $distribconf; - if (my $dir = $url && urpm::file_from_local_url($url)) { - urpm::removable::try_mounting_($urpm, $dir) - or $urpm->{error}(N("unable to mount the distribution medium")), return (); + if ($url && urpm::is_local_url($url)) { + my $m = { url => $url }; + urpm::removable::try_mounting_medium($urpm, $m) or return (); + my $dir = file_from_local_medium($m); + $distribconf = MDV::Distribconf->new($dir, undef); $distribconf->load or $urpm->{error}(N("this location doesn't seem to contain any distribution")), return (); @@ -800,7 +791,7 @@ sub add_distrib_media { $is_update_media or next; } - my $use_copied_synthesis = $urpm->{options}{use_copied_hdlist} || $distribconf->getvalue($media, 'use_copied_hdlist'); + my $use_copied_synthesis = urpm::is_cdrom_url($url) || $urpm->{options}{use_copied_hdlist} || $distribconf->getvalue($media, 'use_copied_hdlist'); my $with_synthesis = $use_copied_synthesis && offset_pathname( $url, $distribconf->getpath($media, 'path'), @@ -941,10 +932,10 @@ sub _probe_with_try_list { sub may_reconfig_urpmi { my ($urpm, $medium) = @_; - $medium->{url} or return; # we should handle mirrorlist? + $medium->{url} && !urpm::is_cdrom_url($medium->{url}) or return; # we should handle mirrorlist? my $f; - if (my $dir = file_from_local_medium($medium)) { + if (my $dir = file_from_file_url($medium->{url})) { $f = reduce_pathname("$dir/reconfig.urpmi"); } else { unlink($f = "$urpm->{cachedir}/partial/reconfig.urpmi"); @@ -1237,18 +1228,11 @@ sub _is_statedir_MD5SUM_uptodate { sub _update_medium__parse_if_unmodified__local { my ($urpm, $medium, $options) = @_; - my $dir = $options->{probe_with} ne 'rpms' && _valid_synthesis_dir($medium) - ? _synthesis_dir($medium) : file_from_local_medium($medium); - - if (!-d $dir) { + if ($options->{probe_with} ne 'rpms') { #- the directory given does not exist and may be accessible #- by mounting some other directory. Try to figure it out and mount #- everything that might be necessary. - urpm::removable::try_mounting($urpm, - $dir, - $medium->{iso}, - ) or $urpm->{error}(N("unable to access medium \"%s\", -this could happen if you mounted manually the directory when creating the medium.", $medium->{name})), return; + urpm::removable::try_mounting_medium($urpm, $medium) or return; } #- try to probe for possible with_synthesis parameter, unless diff --git a/urpm/removable.pm b/urpm/removable.pm index cae0acaa..a0e7897c 100644 --- a/urpm/removable.pm +++ b/urpm/removable.pm @@ -18,6 +18,53 @@ sub is_iso { $removable_dev && $removable_dev =~ /\.iso$/i; } +sub _file_or_synthesis_dir { + my ($medium, $o_url) = @_; + + urpm::media::_valid_synthesis_dir($medium) && !$o_url ? + urpm::media::_synthesis_dir($medium) : + file_from_local_medium($medium, $o_url); +} + +#- side-effects: $medium->{mntpoint} +sub look_for_mounted_cdrom { + my ($urpm, $medium, $o_url) = @_; + + my @mntpoints = map { $_->{mntpoint} } + grep { $_->{fs} eq 'iso9660' || $_->{fs} eq 'udf' } urpm::sys::read_mtab(); + foreach (@mntpoints) { + # set it, then verify + $medium->{mntpoint} = $_; + if (-r _file_or_synthesis_dir($medium, $o_url)) { + $urpm->{log}("using cdrom mounted in $_"); + return 1; + } + } + 0; +} + +#- side-effects: +#- + those of _try_mounting_medium ($medium->{mntpoint}) +sub try_mounting_medium { + my ($urpm, $medium, $o_url) = @_; + + my $rc = _try_mounting_medium($urpm, $medium, $o_url); + $rc or $urpm->{error}(N("unable to access medium \"%s\".", $medium->{name})); + $rc; +} + +#- side-effects: +#- + those of look_for_mounted_cdrom ($medium->{mntpoint}) +sub _try_mounting_medium { + my ($urpm, $medium, $o_url) = @_; + + if (urpm::is_cdrom_url($medium->{url})) { + look_for_mounted_cdrom($urpm, $medium, $o_url); + } else { + -r _file_or_synthesis_dir($medium, $o_url); + } +} + #- side-effects: #- + those of try_mounting_ ($urpm->{removable_mounted}, "mount") #- + those of try_mounting_iso ($urpm->{removable_mounted}, "mount") @@ -100,12 +147,12 @@ sub try_umounting_removables { } #- side-effects: -#- + those of try_mounting_ ($urpm->{removable_mounted}, "mount") +#- + those of try_mounting_medium ($medium->{mntpoint}) sub _mount_and_check_notfound { - my ($urpm, $blist, $dir) = @_; + my ($urpm, $blist, $medium) = @_; - try_mounting_($urpm, $dir); - -e $dir or return 2; + my ($first_url) = values %{$blist->{list}}; + try_mounting_medium($urpm, $medium, $first_url) or return 1; _check_notfound($blist); } @@ -146,23 +193,20 @@ sub _mount_it { my ($urpm, $blist, $o_ask_for_medium) = @_; my $medium = $blist->{medium}; - my $dir = file_from_local_medium($medium); - #- the directory given does not exist and may be accessible #- by mounting some other directory. Try to figure it out and mount #- everything that might be necessary. - while (_mount_and_check_notfound($urpm, $blist, $dir)) { + while (_mount_and_check_notfound($urpm, $blist, $medium)) { $o_ask_for_medium or $urpm->{fatal}(4, N("medium \"%s\" is not available", $medium->{name})); + my $dir; # TODO try_umounting($urpm, $dir); system("/usr/bin/eject '$medium->{removable}' 2>/dev/null"); $o_ask_for_medium->(remove_internal_name($medium->{name}), $medium->{removable}) or $urpm->{fatal}(4, N("medium \"%s\" is not available", $medium->{name})); } - - $dir; } #- side-effects: none @@ -198,7 +242,7 @@ sub _do_the_copy { sub _examine_removable_medium_ { my ($urpm, $blist, $sources, $o_ask_for_medium) = @_; - my $dir = _mount_it($urpm, $blist, $o_ask_for_medium); + _mount_it($urpm, $blist, $o_ask_for_medium); while (my ($i, $url) = each %{$blist->{list}}) { my $filepath = _filepath($blist->{medium}, $url) or next; @@ -217,9 +261,10 @@ sub _examine_removable_medium_ { sub try_mounting_non_cdroms { my ($urpm, $list) = @_; - my @used_media = map { $_->{medium} } _create_blists($urpm->{media}, $list); + my $blist = _create_blists($urpm->{media}, $list); + my @used_media = map { $_->{medium} } @$blist; - foreach my $medium (grep { !$_->{removable} } @used_media) { + foreach my $medium (grep { !urpm::is_cdrom_url($_->{url}) } @used_media) { try_mounting_non_cdrom($urpm, $medium); } } @@ -238,22 +283,6 @@ sub try_mounting_non_cdrom { } #- side-effects: none -sub _get_cdroms { - my ($blists) = @_; - - my %removables; - - foreach (@$blists) { - #- examine non removable device but that may be mounted. - if (my $device = $_->{medium}{removable}) { - next if $device =~ m![^a-zA-Z0-9_./-]!; #- bad path - push @{$removables{$device} ||= []}, $_; - } - } - values %removables; -} - -#- side-effects: none sub _create_blists { my ($media, $list) = @_; @@ -290,15 +319,12 @@ sub copy_packages_of_removable_media { my ($urpm, $list, $sources, $o_ask_for_medium) = @_; my $blists = _create_blists($urpm->{media}, $list); + #- If more than one media uses this device, we have to sort + #- needed packages to copy the needed rpm files. + my @l = _sort_media(grep { urpm::is_cdrom_url($_->{medium}{url}) } @$blists); - foreach my $l (_get_cdroms($blists)) { - - #- Here we have only removable devices. - #- If more than one media uses this device, we have to sort - #- needed packages to copy the needed rpm files. - foreach my $blist (_sort_media(@$l)) { - _examine_removable_medium($urpm, $blist, $sources, $o_ask_for_medium); - } + foreach my $blist (@l) { + _examine_removable_medium($urpm, $blist, $sources, $o_ask_for_medium); } 1; |