From 3880463a92142896704deca4d341af93be762b84 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 19 Dec 2007 12:16:49 +0000 Subject: - all tools: o drop hdlist support (will be replaced with xml media_info) --- urpm/args.pm | 4 +- urpm/bug_report.pm | 7 +- urpm/cfg.pm | 7 +- urpm/md5sum.pm | 4 +- urpm/media.pm | 773 ++++++++++++++--------------------------------------- 5 files changed, 216 insertions(+), 579 deletions(-) (limited to 'urpm') diff --git a/urpm/args.pm b/urpm/args.pm index 14ebaf57..5b5f9920 100644 --- a/urpm/args.pm +++ b/urpm/args.pm @@ -146,7 +146,7 @@ my %options_spec = ( 'root=s' => sub { set_root($urpm, $_[1]) }, 'use-distrib=s' => \$options{usedistrib}, 'probe-synthesis' => sub { $options{probe_with} = 'synthesis' }, - 'probe-hdlist' => sub { $options{probe_with} = 'hdlist' }, + 'probe-hdlist' => sub { $options{probe_with} = 'synthesis' }, #- ignored, kept for compatibility 'excludepath|exclude-path=s' => sub { $urpm->{options}{excludepath} = $_[1] }, 'excludedocs|exclude-docs' => sub { $urpm->{options}{excludedocs} = 1 }, 'ignoresize' => sub { $urpm->{options}{ignoresize} = 1 }, @@ -394,7 +394,7 @@ foreach my $k ("y") { $options_spec{'urpmi.removemedia'}{$k} = $options_spec{urpmi}{$k}; } -foreach my $k ("probe-synthesis", "probe-hdlist") +foreach my $k ("probe-synthesis", "probe-hdlist") # probe-hdlist is obsolete { $options_spec{'urpmi.addmedia'}{$k} = $options_spec{urpme}{$k} = diff --git a/urpm/bug_report.pm b/urpm/bug_report.pm index f4265870..d6aeb492 100644 --- a/urpm/bug_report.pm +++ b/urpm/bug_report.pm @@ -27,13 +27,10 @@ sub rpmdb_to_synthesis { sub write_urpmdb { my ($urpm, $bug_report_dir) = @_; - require URPM::Build; foreach (@{$urpm->{media}}) { - #- take care of virtual medium this way. - #- now build directly synthesis file, this is by far the simplest method. if (urpm::media::is_valid_medium($_)) { - $urpm->build_synthesis(start => $_->{start}, end => $_->{end}, synthesis => "$bug_report_dir/synthesis." . urpm::media::_hdlist($_)); - $urpm->{log}(N("built hdlist synthesis file for medium \"%s\"", $_->{name})); + system('cp', urpm::media::any_synthesis($urpm, $_), + "$bug_report_dir/" . urpm::media::_synthesis($_)) == 0 or $urpm->{fatal}(1, "failed to copy $_->{name} synthesis"); } } #- fake configuration written to convert virtual media on the fly. diff --git a/urpm/cfg.pm b/urpm/cfg.pm index 0c3b63a4..68421910 100644 --- a/urpm/cfg.pm +++ b/urpm/cfg.pm @@ -144,6 +144,7 @@ sub load_config_raw { } elsif (/^(hdlist |list |with_hdlist + |with_synthesis |media_info_dir |removable |md5sum @@ -161,7 +162,9 @@ sub load_config_raw { $block->{$1} = $2; } elsif (/^key[-_]ids\s*:\s*['"]?(.*?)['"]?$/) { $block->{'key-ids'} = $1; - } elsif (/^(hdlist|$no_para_option_regexp)$/) { + } elsif (/^(hdlist|synthesis)$/) { + # ignored, kept for compatibility + } elsif (/^($no_para_option_regexp)$/) { #- positive flags $block->{$1} = 1; } elsif (my ($no, $k, $v) = @@ -229,8 +232,6 @@ sub dump_config_raw { my @l = map { if (/^($no_para_option_regexp)$/) { $_; - } elsif ($_ eq 'hdlist' && $m->{$_} eq '1') { - $_; } elsif ($_ ne 'priority') { "$_: " . $substitute_back->($m, $_); } diff --git a/urpm/md5sum.pm b/urpm/md5sum.pm index 71ccc5b5..05176086 100644 --- a/urpm/md5sum.pm +++ b/urpm/md5sum.pm @@ -41,8 +41,8 @@ sub compute_on_local_medium { my ($urpm, $medium) = @_; require urpm::media; #- help perl_checker - my $f = urpm::media::statedir_hdlist_or_synthesis($urpm, $medium, 's'); - $urpm->{log}(N("computing md5sum of existing source hdlist (or synthesis) [%s]", $f)); + my $f = urpm::media::statedir_synthesis($urpm, $medium); + $urpm->{log}(N("computing md5sum of existing source synthesis [%s]", $f)); -e $f && compute($f); } diff --git a/urpm/media.pm b/urpm/media.pm index ac9aeb91..73d769c8 100644 --- a/urpm/media.pm +++ b/urpm/media.pm @@ -28,6 +28,7 @@ our @PER_MEDIA_OPT = qw( verify-rpm virtual with_hdlist + with_synthesis ); sub only_media_opts { @@ -96,22 +97,26 @@ sub remove_passwords_and_write_private_netrc { sub recover_url_from_list { my ($urpm, $medium) = @_; + my $list = delete $medium->{list} or return; + my $statedir_list = "$urpm->{statedir}/$list"; + #- /./ is end of url marker in list file (typically generated by a #- find . -name "*.rpm" > list #- for exportable list file. - if (my @probe = map { m!^(.*)/\./! || m!^(.*)/[^/]*$! } cat_(statedir_list($urpm, $medium))) { - $urpm->{log}("recovering url from " . statedir_list($urpm, $medium)); + if (my @probe = map { m!^(.*)/\./! || m!^(.*)/[^/]*$! } cat_($statedir_list)) { + $urpm->{log}("recovering url from $statedir_list"); ($medium->{url}) = sort { length($a) <=> length($b) } @probe; $urpm->{modified} = 1; #- ensure urpmi.cfg is handled using only partially hidden url + netrc, since file list won't be generated anymore + unlink $statedir_list; } } #- Loads /etc/urpmi/urpmi.cfg and performs basic checks. #- Does not handle old format: [with ] #- options : -#- - nocheck_access : don't check presence of hdlist and other files +#- - nocheck_access : don't check presence of synthesis and other files sub read_config { - my ($urpm, $b_nocheck_access, $b_auto_correct) = @_; + my ($urpm, $b_nocheck_access) = @_; return if $urpm->{media}; #- media already loaded $urpm->{media} = []; my $config = urpm::cfg::load_config($urpm->{config}) @@ -130,14 +135,14 @@ sub read_config { $medium->{url} or $urpm->{error}("unable to find url in list file $medium->{name}, medium ignored"); } - add_existing_medium($urpm, $medium, $b_nocheck_access, $b_auto_correct); + add_existing_medium($urpm, $medium, $b_nocheck_access); } eval { require urpm::ldap; urpm::ldap::load_ldap_media($urpm) }; #- read MD5 sums (not in urpmi.cfg but in a separate file) foreach (@{$urpm->{media}}) { - if (my $md5sum = urpm::md5sum::from_MD5SUM("$urpm->{statedir}/MD5SUM", statedir_hdlist_or_synthesis($urpm, $_, 's'))) { + if (my $md5sum = urpm::md5sum::from_MD5SUM("$urpm->{statedir}/MD5SUM", statedir_synthesis($urpm, $_))) { $_->{md5sum} = $md5sum; } } @@ -145,105 +150,52 @@ sub read_config { #- if invalid, set {ignore} sub check_existing_medium { - my ($urpm, $medium, $b_nocheck_access, $b_auto_correct) = @_; - - if ($medium->{virtual}) { - #- a virtual medium needs to have an url available without using a list file. - if ($medium->{list}) { - $medium->{ignore} = 1; - $urpm->{error}(N("virtual medium \"%s\" should not have defined hdlist or list file, medium ignored", - $medium->{name})); - } elsif (!$medium->{url}) { - $medium->{ignore} = 1; - $urpm->{error}(N("virtual medium \"%s\" should have a clear url, medium ignored", - $medium->{name})); - } - } else { - if ($medium->{hdlist}) { - #- is this check really needed? keeping just in case - $medium->{hdlist} ne 'list' && $medium->{hdlist} ne 'pubkey' or - $medium->{ignore} = 1, - $urpm->{error}(N("invalid hdlist name")); - } - if (!$medium->{ignore} && !$medium->{list}) { - unless (defined $medium->{url}) { - $medium->{list} = "list.$medium->{name}"; - unless (-e statedir_list($urpm, $medium)) { - $medium->{ignore} = 1, - $urpm->{error}(N("unable to find list file for \"%s\", medium ignored", $medium->{name})); - } - } - } - } - - - #- check the presence of hdlist and list files if necessary. - if (!$b_nocheck_access && !$medium->{ignore}) { - if ($medium->{virtual} && -r hdlist_or_synthesis_for_virtual_medium($medium, 's')) {} - elsif (-r statedir_hdlist_or_synthesis($urpm, $medium, 's')) {} - elsif (-r statedir_hdlist($urpm, $medium)) { - $b_auto_correct and delete $urpm->{synthesis}; - $urpm->{error}(N("\"synthesis\" should not be set (medium \"%s\")", $medium->{name})); - } elsif (-r statedir_synthesis($urpm, $medium)) { - $medium->{synthesis} = 1; - $urpm->{error}(N("\"synthesis\" should be set (medium \"%s\")", $medium->{name})); - } else { - $medium->{ignore} = 1; - $urpm->{error}(N("unable to access hdlist file of \"%s\", medium ignored", $medium->{name})); - } - if ($medium->{list} && -r statedir_list($urpm, $medium)) {} - elsif ($medium->{url}) { - if ($medium->{list}) { - $b_auto_correct and delete $medium->{list}; #- remove buggy list - $urpm->{error}(N("unable to access list file of \"%s\"", $medium->{name})); - } - } else { - $medium->{ignore} = 1; - $urpm->{error}(N("unable to access list file of \"%s\", medium ignored", $medium->{name})); - } - } - - foreach my $field ('hdlist', 'list') { - $medium->{$field} && $medium->{$field} ne '1' or next; - if (grep { $_->{$field} eq $medium->{$field} } @{$urpm->{media}}) { - $medium->{ignore} = 1; - $urpm->{error}( - $field eq 'hdlist' - ? N("medium \"%s\" trying to use an already used hdlist, medium ignored", $medium->{name}) - : N("medium \"%s\" trying to use an already used list, medium ignored", $medium->{name})); - } + my ($urpm, $medium, $b_nocheck_access) = @_; + + my $err; + if (!$medium->{url}) { + $err = $medium->{virtual} ? + N("virtual medium \"%s\" should have a clear url, medium ignored", + $medium->{name}) : + N("unable to access list file of \"%s\", medium ignored", $medium->{name}); + } elsif (!$b_nocheck_access && !$medium->{ignore} + && !-r any_synthesis($urpm, $medium)) { + $err = N("unable to access synthesis file of \"%s\", medium ignored", $medium->{name}); + } + if ($err) { + $medium->{ignore} = 1; + $urpm->{error}($err); } } -sub _migrate__with_hdlist { - my ($medium) = @_; - - grep { $_ eq '..' } split('/', $medium->{with_hdlist}) and return; +sub _migrate__with_synthesis { + my ($medium, $with_synthesis) = @_; #- try to migrate to media_info_dir - my $b = basename($medium->{with_hdlist}); - if ($b eq ($medium->{synthesis} ? 'synthesis.hdlist.cz' : 'hdlist.cz')) { - $medium->{media_info_dir} = dirname(delete $medium->{with_hdlist}); - 1; + my $b = basename($with_synthesis); + if ($b eq 'synthesis.hdlist.cz' || $b eq 'hdlist.cz') { + $medium->{media_info_dir} = dirname($with_synthesis); } else { - 0; + $with_synthesis =~ s/(synthesis\.)?(hdlist.*\.cz)$/synthesis.$2/; + $medium->{with_synthesis} = $with_synthesis; } } #- probe medium to be used, take old medium into account too. sub add_existing_medium { - my ($urpm, $medium, $b_nocheck_access, $b_auto_correct) = @_; + my ($urpm, $medium, $b_nocheck_access) = @_; if (name2medium($urpm, $medium->{name})) { $urpm->{error}(N("trying to override existing medium \"%s\", skipping", $medium->{name})); return; } - if ($medium->{with_hdlist} && _migrate__with_hdlist($medium)) { + if ($medium->{with_hdlist}) { + _migrate__with_synthesis($medium, delete $medium->{with_hdlist}); $urpm->{modified} = 1; } - check_existing_medium($urpm, $medium, $b_nocheck_access, $b_auto_correct); + check_existing_medium($urpm, $medium, $b_nocheck_access); #- probe removable device. probe_removable_device($urpm, $medium); @@ -254,71 +206,47 @@ sub add_existing_medium { push @{$urpm->{media}}, $medium; } -sub _set_synthesis_or_hdlist { - my ($medium, $want_synthesis) = @_; - - $medium->{$want_synthesis ? 'synthesis' : 'hdlist'} = 1; -} - sub file_from_file_url { my ($url) = @_; $url =~ m!^(?:file:/)?(/.*)! && $1; } -sub _synthesis_or_not { - my ($medium, $prefer_synthesis) = @_; - $medium->{synthesis} || !$medium->{hdlist} && $prefer_synthesis; -} -sub _url_with_hdlist_basename { - my ($medium, $prefer_synthesis) = @_; +sub _url_with_synthesis_basename { + my ($medium) = @_; - $medium->{with_hdlist} - ? basename($medium->{with_hdlist}) - : _synthesis_or_not($medium, $prefer_synthesis) ? 'synthesis.hdlist.cz' : 'hdlist.cz'; + $medium->{with_synthesis} + ? basename($medium->{with_synthesis}) + : 'synthesis.hdlist.cz'; } -sub _hdlist_dir { +sub _synthesis_dir { my ($medium) = @_; my $base = file_from_local_url($medium->{url}) || $medium->{url}; - $medium->{with_hdlist} - ? reduce_pathname("$base/$medium->{with_hdlist}/..") + $medium->{with_synthesis} + ? reduce_pathname("$base/$medium->{with_synthesis}/..") : $medium->{media_info_dir} && reduce_pathname("$base/$medium->{media_info_dir}"); } -sub _url_with_hdlist { - my ($medium, $prefer_synthesis) = @_; +sub _url_with_synthesis { + my ($medium) = @_; my $base = file_from_local_url($medium->{url}) || $medium->{url}; - $medium->{with_hdlist} - ? reduce_pathname("$base/$medium->{with_hdlist}") - : _hdlist_dir($medium) . "/" . _url_with_hdlist_basename($medium, $prefer_synthesis); + $medium->{with_synthesis} + ? reduce_pathname("$base/$medium->{with_synthesis}") + : _synthesis_dir($medium) . "/" . _url_with_synthesis_basename($medium); } -sub hdlist_or_synthesis_for_virtual_medium { - my ($medium, $prefer_synthesis) = @_; - file_from_file_url($medium->{url}) && _url_with_hdlist($medium, $prefer_synthesis); +sub synthesis_for_virtual_medium { + my ($medium) = @_; + file_from_file_url($medium->{url}) && _url_with_synthesis($medium); } -sub _hdlist { +sub _synthesis { my ($medium) = @_; - $medium->{hdlist} && $medium->{hdlist} ne '1' - ? $medium->{hdlist} - : $medium->{name} && "hdlist.$medium->{name}.cz"; + $medium->{name} && "synthesis.hdlist.$medium->{name}.cz"; } -sub statedir_hdlist_or_synthesis { - my ($urpm, $medium, $prefer_synthesis) = @_; - "$urpm->{statedir}/" . (_synthesis_or_not($medium, $prefer_synthesis) ? 'synthesis.' : '') . _hdlist($medium); -} -sub statedir_hdlist { - my ($urpm, $medium) = @_; - "$urpm->{statedir}/" . _hdlist($medium); -} sub statedir_synthesis { my ($urpm, $medium) = @_; - "$urpm->{statedir}/synthesis." . _hdlist($medium); -} -sub statedir_list { - my ($urpm, $medium) = @_; - $medium->{list} && "$urpm->{statedir}/$medium->{list}"; + "$urpm->{statedir}/" . _synthesis($medium); } sub statedir_descriptions { my ($urpm, $medium) = @_; @@ -328,27 +256,13 @@ sub statedir_names { my ($urpm, $medium) = @_; $medium->{name} && "$urpm->{statedir}/names.$medium->{name}"; } -sub cachedir_with_hdlist { - my ($urpm, $medium, $prefer_synthesis) = @_; - _url_with_hdlist($medium, $prefer_synthesis) && "$urpm->{cachedir}/partial/" . _url_with_hdlist_basename($medium, $prefer_synthesis); -} -sub cachedir_list { +sub cachedir_with_synthesis { my ($urpm, $medium) = @_; - $medium->{list} && "$urpm->{cachedir}/partial/$medium->{list}"; -} -sub any_hdlist { - my ($urpm, $medium) = @_; - my $f = statedir_hdlist($urpm, $medium); - if ($medium->{virtual} && !$medium->{synthesis} - || !-e $f && file_from_local_url($medium->{url}) && !$medium->{synthesis} && !$medium->{hdlist}) { - $f = _url_with_hdlist($medium, ''); - } - -e $f && $f; + _url_with_synthesis($medium) && "$urpm->{cachedir}/partial/" . _url_with_synthesis_basename($medium); } sub any_synthesis { my ($urpm, $medium) = @_; - my $f = $medium->{virtual} && !$medium->{hdlist} - ? _url_with_hdlist($medium, 's') + my $f = $medium->{virtual} ? _url_with_synthesis($medium) : statedir_synthesis($urpm, $medium); -e $f && $f; } @@ -404,7 +318,7 @@ sub write_MD5SUM { #- write MD5SUM file my $fh = urpm::sys::open_safe($urpm, '>', "$urpm->{statedir}/MD5SUM") or return 0; foreach my $medium (grep { $_->{md5sum} } @{$urpm->{media}}) { - my $s = basename(statedir_hdlist_or_synthesis($urpm, $medium, 's')); + my $s = basename(statedir_synthesis($urpm, $medium)); print $fh "$medium->{md5sum} $s\n"; } @@ -456,8 +370,8 @@ sub _tempignore { #- nocheck_access (used by read_config) #- #- callback (urpmf) -#- need_hdlist (for urpmf: to be able to have info not available in synthesis) -#- nodepslist (for urpmq: we don't need the hdlist/synthesis) +#- need_xml (for urpmf: to be able to have info not available in synthesis) +#- nodepslist (for urpmq: we don't need the synthesis) #- no_skiplist (urpmf) #- no_second_pass (urpmf) #- @@ -510,7 +424,7 @@ sub configure { $urpm->{media} = []; add_distrib_media($urpm, "Virtual", $options{usedistrib}, %options, 'virtual' => 1); } else { - read_config($urpm, $options{nocheck_access}, 1); + read_config($urpm, $options{nocheck_access}); if (!$options{media} && $urpm->{options}{'default-media'}) { $options{media} = $urpm->{options}{'default-media'}; } @@ -543,7 +457,7 @@ sub configure { my @remaining = difference2($urpm->{media}, \@sorted_media); $urpm->{media} = [ @sorted_media, @remaining ]; } - _parse_media($urpm, 0, \%options) if !$options{nodepslist}; + _parse_media($urpm, \%options) if !$options{nodepslist}; } #- determine package to withdraw (from skip.list file) only if something should be withdrawn. if (!$options{nodepslist}) { @@ -553,39 +467,22 @@ sub configure { } sub _parse_media { - my ($urpm, $is_second_pass, $options) = @_; + my ($urpm, $options) = @_; - my $need_second_pass; foreach (grep { !$_->{ignore} && (!$options->{update} || $_->{update}) } @{$urpm->{media} || []}) { our $currentmedia = $_; #- hack for urpmf delete @$_{qw(start end)}; - my $want_hdlist = $options->{need_hdlist} || $is_second_pass; - if (!$want_hdlist && - _parse_synthesis($urpm, $_, any_synthesis($urpm, $_), $options->{callback})) { - #- cool - } elsif (_parse_hdlist($urpm, $_, any_hdlist($urpm, $_), $options->{callback})) { - $need_second_pass = 1 if !$is_second_pass && !$options->{no_second_pass}; - } else { - $options->{need_hdlist} - and $urpm->{error}(N("Note: no hdlist for medium \"%s\", unable to return any result for it", $_->{name})); + _parse_synthesis_or_ignore($urpm, $_, $options->{callback}); - _parse_synthesis($urpm, $_, any_synthesis($urpm, $_), $options->{callback}); - } - unless ($_->{ignore}) { - _check_after_reading_hdlist_or_synthesis($urpm, $_); + if ($options->{need_xml}) { + # TODO + # _parse_xml_($urpm, $_, any_xml($urpm, $_), $options->{callback}); } if ($_->{searchmedia}) { $urpm->{searchmedia} = 1; $urpm->{log}(N("Search start: %s end: %s", $_->{start}, $_->{end})); } } - - if ($need_second_pass) { - require URPM::Build; - $urpm->{log}(N("performing second pass to compute dependencies\n")); - $urpm->unresolved_provides_clean; - _parse_media($urpm, 1, $options); - } } sub _compute_flags_for_skiplist { @@ -623,9 +520,9 @@ sub _compute_flags_for_instlist { #- add a new medium, sync the config file accordingly. #- returns the new medium's name. (might be different from the requested #- name if index_name was specified) -#- options: ignore, index_name, nolock, hdlist, synthesis, update, virtual, media_info_dir +#- options: ignore, index_name, nolock, update, virtual, media_info_dir sub add_medium { - my ($urpm, $name, $url, $with_hdlist, %options) = @_; + my ($urpm, $name, $url, $with_synthesis, %options) = @_; #- make sure configuration has been read. $urpm->{media} or die "caller should have used ->read_config or ->configure first"; @@ -649,7 +546,7 @@ sub add_medium { url => $url, modified => !$options{ignore}, }; - foreach (qw(downloader update ignore hdlist synthesis media_info_dir)) { + foreach (qw(downloader update ignore media_info_dir)) { $medium->{$_} = $options{$_} if exists $options{$_}; } @@ -660,10 +557,8 @@ sub add_medium { probe_removable_device($urpm, $medium); } - if ($with_hdlist) { - _set_synthesis_or_hdlist($medium, $with_hdlist =~ m!(?:^|/)synthesis\.!); - $medium->{with_hdlist} = $with_hdlist; - _migrate__with_hdlist($medium); + if ($with_synthesis) { + _migrate__with_synthesis($medium, $with_synthesis); } #- local media have priority, other are added at the end. @@ -693,7 +588,7 @@ sub add_medium { #- returns the list of names of added media. #- options : #- - initial_number : when adding several numbered media, start with this number -#- - probe_with : force use of synthesis/hdlist/rpms instead of using both synthesis&hdlist +#- - probe_with : force use of rpms instead of using synthesis #- - ask_media : callback to know whether each media should be added #- - only_updates : only add "update" media (used by rpmdrake) #- other options are passed to add_medium(): ignore, nolock, virtual @@ -762,18 +657,18 @@ sub add_distrib_media { $is_update_media or next; } - my $use_copied_hdlist = $urpm->{options}{use_copied_hdlist} || $distribconf->getvalue($media, 'use_copied_hdlist'); - my $with_hdlist = $use_copied_hdlist && offset_pathname( + my $use_copied_synthesis = $urpm->{options}{use_copied_hdlist} || $distribconf->getvalue($media, 'use_copied_hdlist'); + my $with_synthesis = $use_copied_synthesis && offset_pathname( $url, $distribconf->getpath($media, 'path'), - ) . '/' . $distribconf->getpath($media, $options{probe_with} eq 'synthesis' ? 'synthesis' : 'hdlist'); + ) . '/' . $distribconf->getpath($media, 'synthesis'); push @newnames, add_medium($urpm, $name ? "$media_name ($name$medium_index)" : $media_name, reduce_pathname($distribconf->getfullpath($media, 'path')), - $with_hdlist, - !$use_copied_hdlist ? (media_info_dir => 'media_info') : (), - !$use_copied_hdlist && $options{probe_with} ? ($options{probe_with} => 1) : (), + $with_synthesis, + !$use_copied_synthesis ? (media_info_dir => 'media_info') : (), + !$use_copied_synthesis && $options{probe_with} ? ($options{probe_with} => 1) : (), index_name => $name ? undef : 0, $add_by_default ? () : (ignore => 1), %options, @@ -848,7 +743,7 @@ sub remove_media { $urpm->{modified} = 1; #- remove files associated with this medium. - unlink grep { $_ } map { $_->($urpm, $medium) } \&statedir_hdlist, \&statedir_list, \&statedir_synthesis, \&statedir_descriptions, \&statedir_names; + unlink grep { $_ } map { $_->($urpm, $medium) } \&statedir_synthesis, \&statedir_descriptions, \&statedir_names; #- remove proxy settings for this media urpm::download::remove_proxy_media($medium->{name}); @@ -858,49 +753,21 @@ sub remove_media { } sub _probe_with_try_list { - my ($urpm, $medium, $probe_with, $f) = @_; - - my $probe = sub { - my ($synthesis, $media_info_dir) = @_; - - my $base = file_from_local_url($medium->{url}) || $medium->{url}; - my $url = reduce_pathname("$base/$media_info_dir") . '/' . ($synthesis ? 'synthesis.hdlist.cz' : 'hdlist.cz'); - $f->($url) or return; - - $urpm->{debug} and $urpm->{debug}("found hdlist/synthesis: $url"); - - $medium->{media_info_dir} = $media_info_dir; - if ($probe_with) { - _set_synthesis_or_hdlist($medium, $synthesis); - } - 1; - }; + my ($urpm, $medium, $f) = @_; - - my $want_synthesis = !$probe_with || $probe_with eq 'synthesis'; my @media_info_dirs = ('media_info', '.'); + my $base = file_from_local_url($medium->{url}) || $medium->{url}; + foreach my $media_info_dir (@media_info_dirs) { - if ($probe->($want_synthesis, $media_info_dir)) { - return 1 if $probe_with; - last; - } - } - if ($medium->{media_info_dir}) { - #- try to have both synthesis and hdlist :-) - if (file_from_file_url($medium->{url}) && - !$probe->(!$want_synthesis, $medium->{media_info_dir})) { - #- sad, only one available. - _set_synthesis_or_hdlist($medium, $want_synthesis); + my $url = reduce_pathname("$base/$media_info_dir") . '/synthesis.hdlist.cz'; + if ($f->($url)) { + $urpm->{debug} and $urpm->{debug}("found synthesis: $url"); + $medium->{media_info_dir} = $media_info_dir; + return 1; } - 1; - } else { - foreach my $media_info_dir (@media_info_dirs) { - $probe->(!$want_synthesis, $media_info_dir) - and return 1; - } - ''; } + undef; } sub may_reconfig_urpmi { @@ -949,7 +816,7 @@ sub reconfig_urpmi { } my $reconfigured = 0; - my @reconfigurable = qw(url with_hdlist media_info_dir); + my @reconfigurable = qw(url with_synthesis media_info_dir); my %orig = %$medium; @@ -983,35 +850,24 @@ sub reconfig_urpmi { $reconfigured; } -sub _guess_hdlist_suffix { +sub _guess_synthesis_suffix { my ($url) = @_; $url =~ m!\bmedia/(\w+)/*\Z! && $1; } -sub _hdlist_suffix { +sub _synthesis_suffix { my ($medium) = @_; - $medium->{with_hdlist} =~ /hdlist(.*?)(?:\.src)?\.cz$/ ? $1 : ''; + $medium->{with_synthesis} =~ /synthesis\.hdlist(.*?)(?:\.src)?\.cz$/ ? $1 : ''; } -sub _parse_hdlist_or_synthesis__when_not_modified { - my ($urpm, $medium) = @_; - - delete @$medium{qw(start end)}; - - _parse_synthesis($urpm, $medium, any_synthesis($urpm, $medium)) or - _parse_hdlist($urpm, $medium, any_hdlist($urpm, $medium)); - - _check_after_reading_hdlist_or_synthesis($urpm, $medium); -} - -sub _parse_hdlist_or_synthesis__virtual { +sub _parse_synthesis__virtual { my ($urpm, $medium) = @_; delete $medium->{modified}; $medium->{really_modified} = 1; $urpm->{md5sum_modified} = 1; - _parse_hdlist_or_synthesis__when_not_modified($urpm, $medium); + _parse_synthesis_or_ignore($urpm, $medium); } #- names. is used by external progs (namely for bash-completion) @@ -1034,61 +890,48 @@ sub generate_medium_names { } -sub _read_existing_synthesis_and_hdlist_if_same_time_and_msize { +sub _read_existing_synthesis_if_same_time_and_msize { my ($urpm, $medium) = @_; - same_size_and_mtime(cachedir_with_hdlist($urpm, $medium, 's'), - statedir_hdlist_or_synthesis($urpm, $medium, 's')) or return; + same_size_and_mtime(cachedir_with_synthesis($urpm, $medium), + statedir_synthesis($urpm, $medium)) or return; - _read_existing_synthesis_and_hdlist($urpm, $medium); + _read_existing_synthesis($urpm, $medium); 1; } -sub _read_existing_synthesis_and_hdlist_if_same_md5sum { +sub _read_existing_synthesis_if_same_md5sum { my ($urpm, $medium, $retrieved_md5sum) = @_; - #- if an existing hdlist or synthesis file has the same md5sum, we assume the + #- if an existing synthesis file has the same md5sum, we assume the #- files are the same. #- if local md5sum is the same as distant md5sum, this means there is no need to - #- download hdlist or synthesis file again. + #- download synthesis file again. $retrieved_md5sum && $medium->{md5sum} eq $retrieved_md5sum or return; - _read_existing_synthesis_and_hdlist($urpm, $medium); + _read_existing_synthesis($urpm, $medium); 1; } -sub _read_existing_synthesis_and_hdlist { +sub _read_existing_synthesis { my ($urpm, $medium) = @_; - unlink cachedir_with_hdlist($urpm, $medium, 's'); + unlink cachedir_with_synthesis($urpm, $medium); $urpm->{info}(N("medium \"%s\" is up-to-date", $medium->{name})); #- the medium is now considered not modified. $medium->{modified} = 0; - #- XXX we could link the new hdlist to the old one. + #- XXX we could link the new synthesis to the old one. #- (However links need to be managed. see bug #12391.) #- as previously done, just read synthesis file here, this is enough. - if (!_parse_synthesis($urpm, $medium, statedir_synthesis($urpm, $medium))) { - _parse_hdlist($urpm, $medium, statedir_hdlist($urpm, $medium)); - _check_after_reading_hdlist_or_synthesis($urpm, $medium); - } + _parse_synthesis_or_ignore($urpm, $medium); 1; } -sub _parse_hdlist { - my ($urpm, $medium, $hdlist_file, $o_callback) = @_; - - -e $hdlist_file or return; - - $urpm->{log}(N("examining hdlist file [%s]", $hdlist_file)); - ($medium->{start}, $medium->{end}) = - $urpm->parse_hdlist($hdlist_file, packing => 1, $o_callback ? (callback => $o_callback) : @{[]}); -} - sub _parse_synthesis { my ($urpm, $medium, $synthesis_file, $o_callback) = @_; @@ -1098,46 +941,12 @@ sub _parse_synthesis { ($medium->{start}, $medium->{end}) = $urpm->parse_synthesis($synthesis_file, $o_callback ? (callback => $o_callback) : @{[]}); } -sub _parse_hdlist_or_synthesis { - my ($urpm, $medium, $hdlist_or, $prefer_synthesis) = @_; - - if (_synthesis_or_not($medium, $prefer_synthesis)) { - _parse_synthesis($urpm, $medium, $hdlist_or); - } else { - _parse_hdlist($urpm, $medium, $hdlist_or); - } -} -sub _build_hdlist_using_rpm_headers { - my ($urpm, $medium) = @_; - - $urpm->{log}(N("building hdlist [%s]", statedir_hdlist($urpm, $medium))); - #- finish building operation of hdlist. - $urpm->build_hdlist(start => $medium->{start}, - end => $medium->{end}, - dir => "$urpm->{cachedir}/headers", - hdlist => statedir_hdlist($urpm, $medium), - ); -} - -sub _build_synthesis { - my ($urpm, $medium) = @_; +sub _parse_synthesis_or_ignore { + my ($urpm, $medium, $o_callback) = @_; - eval { $urpm->build_synthesis( - start => $medium->{start}, - end => $medium->{end}, - synthesis => statedir_synthesis($urpm, $medium), - ) }; - if (my $err = $@) { - chomp($err); - $urpm->{error}(N("Unable to build synthesis file for medium \"%s\". Your hdlist file may be corrupted.", $medium->{name})); - $urpm->{error}($err); - unlink statedir_synthesis($urpm, $medium); - } else { - $urpm->{log}(N("built hdlist synthesis file for medium \"%s\"", $medium->{name})); - } - #- keep in mind we have a modified database, sure at this point. - $urpm->{md5sum_modified} = 1; + _parse_synthesis($urpm, $medium, any_synthesis($urpm, $medium), $o_callback) or + _ignore_medium_on_parse_error($urpm, $medium); } sub is_valid_medium { @@ -1145,19 +954,17 @@ sub is_valid_medium { defined $medium->{start} && defined $medium->{end}; } -sub _check_after_reading_hdlist_or_synthesis { +sub _ignore_medium_on_parse_error { my ($urpm, $medium) = @_; - if (!is_valid_medium($medium)) { - $urpm->{error}(N("problem reading hdlist or synthesis file of medium \"%s\"", $medium->{name})); - $medium->{ignore} = 1; - } + $urpm->{error}(N("problem reading synthesis file of medium \"%s\"", $medium->{name})); + $medium->{ignore} = 1; } sub _get_list_or_pubkey__local { my ($urpm, $medium, $name) = @_; - my $path = _hdlist_dir($medium) . "/$name" . _hdlist_suffix($medium); + my $path = _synthesis_dir($medium) . "/$name" . _synthesis_suffix($medium); -e $path or $path = file_from_local_url($medium->{url}) . "/media_info/$name"; if (-e $path) { $urpm->{log}(N("copying [%s] for medium \"%s\"...", $path, $medium->{name})); @@ -1171,17 +978,17 @@ sub _get_list_or_pubkey__remote { my ($urpm, $medium, $name) = @_; my $found; - if (_hdlist_suffix($medium)) { - my $local_name = $name . _hdlist_suffix($medium); + if (_synthesis_suffix($medium)) { + my $local_name = $name . _synthesis_suffix($medium); - if (urpm::download::sync($urpm, $medium, [_hdlist_dir($medium) . "/$local_name"], + if (urpm::download::sync($urpm, $medium, [_synthesis_dir($medium) . "/$local_name"], quiet => 1)) { rename("$urpm->{cachedir}/partial/$local_name", "$urpm->{cachedir}/partial/$name"); $found = 1; } } if (!$found) { - urpm::download::sync($urpm, $medium, [_hdlist_dir($medium) . "/$name"], quiet => 1) + urpm::download::sync($urpm, $medium, [_synthesis_dir($medium) . "/$name"], quiet => 1) or unlink "$urpm->{cachedir}/partial/$name"; } } @@ -1220,14 +1027,14 @@ sub get_descriptions_remote { urpm::util::move("$urpm->{cachedir}/partial/descriptions", statedir_descriptions($urpm, $medium)); } } -sub get_hdlist_or_synthesis__local { +sub get_synthesis__local { my ($urpm, $medium, $callback) = @_; - my $f = cachedir_with_hdlist($urpm, $medium, 's'); + my $f = cachedir_with_synthesis($urpm, $medium); unlink $f; - $urpm->{log}(N("copying [%s] for medium \"%s\"...", _url_with_hdlist($medium, 's'), $medium->{name})); + $urpm->{log}(N("copying [%s] for medium \"%s\"...", _url_with_synthesis($medium), $medium->{name})); $callback and $callback->('copy', $medium->{name}); - if (copy_and_own(_url_with_hdlist($medium, 's'), $f)) { + if (copy_and_own(_url_with_synthesis($medium), $f)) { $callback and $callback->('done', $medium->{name}); $urpm->{log}(N("...copying done")); if (file_size($f) < 20) { @@ -1243,12 +1050,12 @@ sub get_hdlist_or_synthesis__local { 0; } } -sub get_hdlist_or_synthesis__remote { +sub get_synthesis__remote { my ($urpm, $medium, $callback, $quiet) = @_; - if (urpm::download::sync($urpm, $medium, [ _url_with_hdlist($medium, 's') ], + if (urpm::download::sync($urpm, $medium, [ _url_with_synthesis($medium) ], quiet => $quiet, callback => $callback) && - file_size(cachedir_with_hdlist($urpm, $medium, 's')) >= 20) { + file_size(cachedir_with_synthesis($urpm, $medium)) >= 20) { 1; } else { chomp(my $err = $@); @@ -1257,94 +1064,52 @@ sub get_hdlist_or_synthesis__remote { } } -sub get_hdlist_or_synthesis_and_check_md5sum__local { +sub get_synthesis_and_check_md5sum__local { my ($urpm, $medium, $retrieved_md5sum, $callback) = @_; - get_hdlist_or_synthesis__local($urpm, $medium, $callback) or return; + get_synthesis__local($urpm, $medium, $callback) or return; #- keep checking md5sum of file just copied ! (especially on nfs or removable device). if ($retrieved_md5sum) { - $urpm->{log}(N("computing md5sum of copied source hdlist (or synthesis)")); - urpm::md5sum::compute(cachedir_with_hdlist($urpm, $medium, 's')) eq $retrieved_md5sum or - $urpm->{error}(N("copy of [%s] failed (md5sum mismatch)", _url_with_hdlist($medium, 's'))), return; + $urpm->{log}(N("computing md5sum of copied source synthesis")); + urpm::md5sum::compute(cachedir_with_synthesis($urpm, $medium)) eq $retrieved_md5sum or + $urpm->{error}(N("copy of [%s] failed (md5sum mismatch)", _url_with_synthesis($medium))), return; } 1; } -sub get_hdlist_or_synthesis_and_check_md5sum__remote { +sub get_synthesis_and_check_md5sum__remote { my ($urpm, $medium, $retrieved_md5sum, $callback, $quiet) = @_; - get_hdlist_or_synthesis__remote($urpm, $medium, $callback, $quiet) or return; + get_synthesis__remote($urpm, $medium, $callback, $quiet) or return; #- check downloaded file has right signature. if ($retrieved_md5sum) { - $urpm->{log}(N("computing md5sum of retrieved source hdlist (or synthesis)")); - urpm::md5sum::compute(cachedir_with_hdlist($urpm, $medium, 's')) eq $retrieved_md5sum or + $urpm->{log}(N("computing md5sum of retrieved source synthesis")); + urpm::md5sum::compute(cachedir_with_synthesis($urpm, $medium)) eq $retrieved_md5sum or $urpm->{error}(N("...retrieving failed: md5sum mismatch")), return; } 1; } -sub _read_rpms_from_dir { - my ($urpm, $medium, $clean_cache) = @_; - - my $dir = file_from_local_url($medium->{url}); - - require File::Glob; - $medium->{rpm_files} = [ File::Glob::glob("$dir/*.rpm") ]; - - #- check files contains something good! - if (!@{$medium->{rpm_files}}) { - $urpm->{error}(N("no rpm files found from [%s]", $dir)); - $medium->{ignore} = 1; - return; - } - - #- we need to rebuild from rpm files the hdlist. - - $urpm->{log}(N("reading rpm files from [%s]", $dir)); - my @unresolved_before = grep { - ! defined $urpm->{provides}{$_}; - } keys %{$urpm->{provides} || {}}; - $medium->{start} = @{$urpm->{depslist}}; +sub _call_genhdlist2 { + my ($urpm, $medium) = @_; - eval { - $medium->{headers} = [ $urpm->parse_rpms_build_headers( - dir => "$urpm->{cachedir}/headers", - rpms => $medium->{rpm_files}, - clean => $$clean_cache, - packing => 1, - ) ]; - }; - if ($@) { - $urpm->{error}(N("unable to read rpm files from [%s]: %s", $dir, $@)); - delete $medium->{headers}; #- do not propagate these. - return; - } + !$medium->{with_synthesis} or $urpm->{fatal}(1, 'with_synthesis not handled with --probe-rpms'); - $medium->{end} = $#{$urpm->{depslist}}; - if ($medium->{start} > $medium->{end}) { - #- an error occured (provided there are files in input.) - delete $medium->{start}; - delete $medium->{end}; - $urpm->{fatal}(9, N("no rpms read")); - } - - #- make sure the headers will not be removed for another media. - $$clean_cache = 0; + my $dir = file_from_local_url($medium->{url}); - my @unresolved = grep { - ! defined $urpm->{provides}{$_}; - } keys %{$urpm->{provides} || {}}; - @unresolved_before == @unresolved or $medium->{need_second_pass} = 1; + system('genhdlist2', + $urpm->{debug} ? '--verbose' : (), '--no-hdlist', + '--media_info-dir', "$urpm->{cachedir}/partial", $dir) == 0 + or $urpm->{error}(N("genhdlist2 failed on %s", $dir)), return; - delete $medium->{synthesis}; #- when building hdlist by ourself, drop synthesis property. 1; } #- options: callback, force, nomd5sum, nopubkey, probe_with sub _update_medium__parse_if_unmodified__local { - my ($urpm, $medium, $clean_cache, $options) = @_; + my ($urpm, $medium, $options) = @_; my $dir = file_from_local_url($medium->{url}); @@ -1353,18 +1118,18 @@ sub _update_medium__parse_if_unmodified__local { #- by mounting some other directory. Try to figure it out and mount #- everything that might be necessary. urpm::removable::try_mounting($urpm, - $options->{probe_with} ne 'rpms' && _hdlist_dir($medium) - ? _hdlist_dir($medium) : $dir, + $options->{probe_with} ne 'rpms' && _synthesis_dir($medium) + ? _synthesis_dir($medium) : $dir, #- in case of an iso image, pass its name urpm::removable::is_iso($medium->{removable}) && $medium->{removable}, ) 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; } - #- try to probe for possible with_hdlist parameter, unless + #- try to probe for possible with_synthesis parameter, unless #- it is already defined (and valid). - if (!_hdlist_dir($medium) && $options->{probe_with} ne 'rpms') { - _probe_with_try_list($urpm, $medium, $options->{probe_with}, sub { + if (!_synthesis_dir($medium) && $options->{probe_with} ne 'rpms') { + _probe_with_try_list($urpm, $medium, sub { my ($url) = @_; -e $url or return; if (file_size($url) >= 20) { @@ -1378,41 +1143,42 @@ this could happen if you mounted manually the directory when creating the medium if ($medium->{virtual}) { #- syncing a virtual medium is very simple, just try to read the file in order to - #- determine its type, once a with_hdlist has been found (but is mandatory). - _parse_hdlist_or_synthesis__virtual($urpm, $medium); + #- determine its type, once a with_synthesis has been found (but is mandatory). + _parse_synthesis__virtual($urpm, $medium); 1; - } elsif ($options->{probe_with} eq 'rpms' || !_hdlist_dir($medium)) { - #- build hdlist/synthesis from rpms - _read_rpms_from_dir($urpm, $medium, $clean_cache); - } elsif (_hdlist_dir($medium)) { + } elsif ($options->{probe_with} eq 'rpms' || !_synthesis_dir($medium)) { + _call_genhdlist2($urpm, $medium) or return ''; + 1; + } elsif (_synthesis_dir($medium)) { my ($retrieved_md5sum); - if (!$options->{nomd5sum} && file_size(_hdlist_dir($medium) . '/MD5SUM') > 32) { - $retrieved_md5sum = urpm::md5sum::from_MD5SUM__or_warn($urpm, _hdlist_dir($medium) . '/MD5SUM', - _url_with_hdlist_basename($medium, 's')); + if (!$options->{nomd5sum} && file_size(_synthesis_dir($medium) . '/MD5SUM') > 32) { + $retrieved_md5sum = urpm::md5sum::from_MD5SUM__or_warn($urpm, _synthesis_dir($medium) . '/MD5SUM', + _url_with_synthesis_basename($medium)); if (urpm::md5sum::on_local_medium($urpm, $medium, $options->{force})) { - _read_existing_synthesis_and_hdlist_if_same_md5sum($urpm, $medium, $retrieved_md5sum) + _read_existing_synthesis_if_same_md5sum($urpm, $medium, $retrieved_md5sum) and return 'unmodified'; } } - if (get_hdlist_or_synthesis_and_check_md5sum__local($urpm, $medium, $retrieved_md5sum, $options->{callback})) { + if (get_synthesis_and_check_md5sum__local($urpm, $medium, $retrieved_md5sum, $options->{callback})) { $medium->{md5sum} = $retrieved_md5sum if $retrieved_md5sum; #- check if the files are equal... and no force copy... if (!$options->{force}) { - _read_existing_synthesis_and_hdlist_if_same_time_and_msize($urpm, $medium) + _read_existing_synthesis_if_same_time_and_msize($urpm, $medium) and return 'unmodified'; } 1; } else { - #- if copying hdlist has failed, try to build it directly. + #- if copying synthesis has failed, try to build it directly. if ($urpm->{options}{'build-hdlist-on-error'}) { - #- no available hdlist/synthesis, try to build it from rpms - _read_rpms_from_dir($urpm, $medium, $clean_cache); + #- no available synthesis, try to build it from rpms + _call_genhdlist2($urpm, $medium) or return ''; + 1; } else { - $urpm->{error}(N("unable to access hdlist file of \"%s\", medium ignored", $medium->{name})); + $urpm->{error}(N("unable to access synthesis file of \"%s\", medium ignored", $medium->{name})); $medium->{ignore} = 1; ''; } @@ -1426,10 +1192,10 @@ sub _update_medium__parse_if_unmodified__remote { my ($retrieved_md5sum); #- examine if a distant MD5SUM file is available. - #- this will only be done if $with_hdlist is not empty in order to use - #- an existing hdlist or synthesis file, and to check if download was good. + #- this will only be done if $with_synthesis is not empty in order to use + #- an existing synthesis file, and to check if download was good. #- if no MD5SUM is available, do it as before... - if (_hdlist_dir($medium)) { + if (_synthesis_dir($medium)) { #- we can assume at this point a basename is existing, but it needs #- to be checked for being valid, nothing can be deduced if no MD5SUM #- file is present. @@ -1437,70 +1203,70 @@ sub _update_medium__parse_if_unmodified__remote { unlink "$urpm->{cachedir}/partial/MD5SUM"; if (!$options->{nomd5sum} && urpm::download::sync($urpm, $medium, - [ reduce_pathname(_hdlist_dir($medium) . '/MD5SUM') ], + [ reduce_pathname(_synthesis_dir($medium) . '/MD5SUM') ], quiet => 1) && file_size("$urpm->{cachedir}/partial/MD5SUM") > 32) { if (urpm::md5sum::on_local_medium($urpm, $medium, $options->{force} >= 2)) { $retrieved_md5sum = urpm::md5sum::from_MD5SUM__or_warn($urpm, "$urpm->{cachedir}/partial/MD5SUM", - _url_with_hdlist_basename($medium, 's')); - _read_existing_synthesis_and_hdlist_if_same_md5sum($urpm, $medium, $retrieved_md5sum) + _url_with_synthesis_basename($medium)); + _read_existing_synthesis_if_same_md5sum($urpm, $medium, $retrieved_md5sum) and return 'unmodified'; } } } - #- try to probe for possible with_hdlist parameter, unless + #- try to probe for possible with_synthesis parameter, unless #- it is already defined (and valid). - $urpm->{log}(N("retrieving source hdlist (or synthesis) of \"%s\"...", $medium->{name})); + $urpm->{log}(N("retrieving source synthesis of \"%s\"...", $medium->{name})); $options->{callback} and $options->{callback}('retrieve', $medium->{name}); my $error = sub { my ($msg) = @_; $urpm->{error}($msg); - unlink cachedir_with_hdlist($urpm, $medium, 's'); + unlink cachedir_with_synthesis($urpm, $medium); $options->{callback} and $options->{callback}('failed', $medium->{name}); }; - if (!_hdlist_dir($medium)) { + if (!_synthesis_dir($medium)) { my $err; - _probe_with_try_list($urpm, $medium, $options->{probe_with}, sub { + _probe_with_try_list($urpm, $medium, sub { my ($url) = @_; my $f = "$urpm->{cachedir}/partial/" . basename($url); $options->{force} and unlink $f; if (urpm::download::sync($urpm, $medium, [ $url ], quiet => $options->{quiet}, callback => $options->{callback}) && file_size($f) >= 20) { - $urpm->{log}(N("found probed hdlist (or synthesis) as %s", $url)); + $urpm->{log}(N("found probed synthesis as %s", $url)); 1; } else { chomp($err = $@); 0; } }) or do { - $error->(N("no hdlist file found for medium \"%s\"", $medium->{name})); + $error->(N("no synthesis file found for medium \"%s\"", $medium->{name})); $urpm->{error}(N("...retrieving failed: %s", $err)); return; }; } else { if ($options->{force}) { - unlink cachedir_with_hdlist($urpm, $medium, 's'); + unlink cachedir_with_synthesis($urpm, $medium); } else { #- for rsync, try to sync (copy if needed) local copy after restored the previous one. - my $previous_hdlist = statedir_hdlist_or_synthesis($urpm, $medium, 's'); - if (-e $previous_hdlist && urpm::protocol_from_url($medium->{url}) eq 'rsync') { + my $previous_synthesis = statedir_synthesis($urpm, $medium); + if (-e $previous_synthesis && urpm::protocol_from_url($medium->{url}) eq 'rsync') { copy_and_own( - $previous_hdlist, - cachedir_with_hdlist($urpm, $medium, 's'), + $previous_synthesis, + cachedir_with_synthesis($urpm, $medium), ) or $error->(N("...copying failed")), return; } } - if (get_hdlist_or_synthesis_and_check_md5sum__remote($urpm, $medium, $retrieved_md5sum, $options->{callback}, $options->{quiet})) { + if (get_synthesis_and_check_md5sum__remote($urpm, $medium, $retrieved_md5sum, $options->{callback}, $options->{quiet})) { $options->{callback} and $options->{callback}('done', $medium->{name}); $medium->{md5sum} = $retrieved_md5sum if $retrieved_md5sum; if (!$options->{force}) { - _read_existing_synthesis_and_hdlist_if_same_time_and_msize($urpm, $medium) + _read_existing_synthesis_if_same_time_and_msize($urpm, $medium) and return 'unmodified'; } } else { - $error->(N("unable to access hdlist file of \"%s\", medium ignored", $medium->{name})); + $error->(N("unable to access synthesis file of \"%s\", medium ignored", $medium->{name})); $medium->{ignore} = 1; return; } @@ -1551,38 +1317,13 @@ sub _read_cachedir_pubkey { unlink "$urpm->{cachedir}/partial/pubkey"; } -sub _write_rpm_list { - my ($urpm, $medium) = @_; - - @{$medium->{rpm_files} || []} or return; - - $medium->{list} ||= "list.$medium->{name}"; - - #- write list file. - $urpm->{log}(N("writing list file for medium \"%s\"", $medium->{name})); - my $listfh = urpm::sys::open_safe($urpm, '>', cachedir_list($urpm, $medium)) or return; - print $listfh basename($_), "\n" foreach @{$medium->{rpm_files}}; - 1; -} - #- options: callback, force, nomd5sum, probe_with, quiet #- (from _update_medium__parse_if_unmodified__local and _update_medium__parse_if_unmodified__remote) sub _update_medium_first_pass { - my ($urpm, $medium, $clean_cache, %options) = @_; - - #- we should create the associated synthesis file if it does not already exist... - file_size(statedir_synthesis($urpm, $medium)) >= 20 - or $medium->{must_build_synthesis} = 1; - - my @unresolved_before = grep { ! defined $urpm->{provides}{$_} } keys %{$urpm->{provides} || {}}; + my ($urpm, $medium, %options) = @_; unless ($medium->{modified}) { - #- the medium is not modified, but to compute dependencies, - #- we still need to read it and all synthesis will be written if - #- an unresolved provides is found. - #- to speed up the process, we only read the synthesis at the beginning. - _parse_hdlist_or_synthesis__when_not_modified($urpm, $medium); - compute_need_second_pass($urpm, $medium, \@unresolved_before); + _parse_synthesis_or_ignore($urpm, $medium); return 'unmodified'; } @@ -1599,7 +1340,7 @@ sub _update_medium_first_pass { { my $rc = file_from_local_url($medium->{url}) - ? _update_medium__parse_if_unmodified__local($urpm, $medium, $clean_cache, \%options) + ? _update_medium__parse_if_unmodified__local($urpm, $medium, \%options) : _update_medium__parse_if_unmodified__remote($urpm, $medium, \%options); if (!$rc || $rc eq 'unmodified') { @@ -1607,89 +1348,46 @@ sub _update_medium_first_pass { } } - #- build list file according to hdlist. - if (!$medium->{headers} && !$medium->{virtual} && file_size(cachedir_with_hdlist($urpm, $medium, 's')) < 20) { - $urpm->{error}(N("no hdlist file found for medium \"%s\"", $medium->{name})); + if (!$medium->{virtual} && file_size(cachedir_with_synthesis($urpm, $medium)) < 20) { + $urpm->{error}(N("no synthesis file found for medium \"%s\"", $medium->{name})); return; } if (!$medium->{virtual}) { - if ($medium->{headers}) { - _write_rpm_list($urpm, $medium) or return; - - if (-e statedir_list($urpm, $medium)) { - $urpm->{info}(N("updated medium \"%s\"", $medium->{name})); - } - unlink statedir_hdlist($urpm, $medium); - unlink statedir_synthesis($urpm, $medium); - unlink statedir_list($urpm, $medium); - urpm::util::move(cachedir_list($urpm, $medium), statedir_list($urpm, $medium)); - } else { - #- read first pass hdlist or synthesis, try to open as synthesis, if file - #- is larger than 1MB, this is probably an hdlist else a synthesis. - #- anyway, if one tries fails, try another mode. $options{callback} and $options{callback}('parse', $medium->{name}); - _parse_hdlist_or_synthesis($urpm, $medium, cachedir_with_hdlist($urpm, $medium, 's'), 's'); - - if (is_valid_medium($medium)) { + if (_parse_synthesis($urpm, $medium, cachedir_with_synthesis($urpm, $medium))) { $options{callback} && $options{callback}('done', $medium->{name}); } else { - $urpm->{error}(N("unable to parse hdlist file of \"%s\"", $medium->{name})); + $urpm->{error}(N("unable to parse synthesis file of \"%s\"", $medium->{name})); $options{callback} and $options{callback}('failed', $medium->{name}); delete $medium->{md5sum}; #- we have to read back the current synthesis file unmodified. - if (!_parse_synthesis($urpm, $medium, statedir_synthesis($urpm, $medium))) { - $urpm->{error}(N("problem reading synthesis file of medium \"%s\"", $medium->{name})); - $medium->{ignore} = 1; - } + _parse_synthesis_or_ignore($urpm, $medium); + return; } - if (-e statedir_hdlist_or_synthesis($urpm, $medium, 's')) { + if (-e statedir_synthesis($urpm, $medium)) { $urpm->{info}(N("updated medium \"%s\"", $medium->{name})); } - unlink statedir_list($urpm, $medium); - unlink statedir_hdlist($urpm, $medium); unlink statedir_synthesis($urpm, $medium); #- use newly created file. - urpm::util::move(cachedir_with_hdlist($urpm, $medium, 's'), - statedir_hdlist_or_synthesis($urpm, $medium, 's')); - - if ($medium->{list}) { - delete $medium->{list}; - $urpm->{modified} = 1; - } - } + urpm::util::move(cachedir_with_synthesis($urpm, $medium), + statedir_synthesis($urpm, $medium)); #- make sure to rebuild base files and clear medium modified state. $medium->{modified} = 0; $medium->{really_modified} = 1; - $urpm->{md5sum_modified} = 1; - - #- and create synthesis file associated. - $medium->{must_build_synthesis} = !_synthesis_or_not($medium, 's'); + $urpm->{md5sum_modified} = 1; } - compute_need_second_pass($urpm, $medium, \@unresolved_before); 1; } -sub compute_need_second_pass { - my ($urpm, $medium, $unresolved_before) = @_; - - my @unresolved_after = grep { ! defined $urpm->{provides}{$_} } keys %{$urpm->{provides} || {}}; - if (@$unresolved_before != @unresolved_after) { - $medium->{need_second_pass} = 1; - $urpm->{debug} and $urpm->{debug}(sprintf qq(medium "%s" has unresolved dependencies: %s), - $medium->{name}, - join(' ', difference2(\@unresolved_after, $unresolved_before))); - } -} - sub _update_medium_first_pass_failed { my ($urpm, $medium) = @_; @@ -1699,45 +1397,6 @@ sub _update_medium_first_pass_failed { unlink(glob("$urpm->{cachedir}/partial/*")); } -#- take care of modified medium only, or all if all have to be recomputed. -sub _update_medium_second_pass { - my ($urpm, $medium, $callback) = @_; - - $callback and $callback->('parse', $medium->{name}); - - #- a modified medium is an invalid medium, we have to read back the previous hdlist - #- or synthesis which has not been modified by first pass above. - - if ($medium->{headers} && !$medium->{modified}) { - $urpm->{log}(N("reading headers from medium \"%s\"", $medium->{name})); - ($medium->{start}, $medium->{end}) = $urpm->parse_headers(dir => "$urpm->{cachedir}/headers", - headers => $medium->{headers}, - ); - } elsif (_parse_hdlist($urpm, $medium, any_hdlist($urpm, $medium))) { - $medium->{must_build_synthesis} = 1; - } else { - _parse_synthesis($urpm, $medium, any_synthesis($urpm, $medium)); - } - - $callback && $callback->('done', $medium->{name}); -} - -sub _build_hdlist_synthesis { - my ($urpm, $medium) = @_; - - if ($medium->{headers} && !$medium->{modified}) { - _build_hdlist_using_rpm_headers($urpm, $medium); - #- synthesis needs to be created, since the medium has been built from rpm files. - _build_synthesis($urpm, $medium); - } elsif ($medium->{synthesis}) { - } else { - #- check if the synthesis file can be built. - if ($medium->{must_build_synthesis} && !$medium->{modified} && !$medium->{virtual}) { - _build_synthesis($urpm, $medium); - } - } -} - sub _update_media__handle_some_flags { my ($urpm, $forcekey, $all) = @_; @@ -1765,8 +1424,8 @@ sub _update_media__handle_some_flags { #- noclean : keep old files in the header cache directory #- nomd5sum : don't verify MD5SUM of retrieved files #- nopubkey : don't use rpm pubkeys -#- probe_with : probe synthesis or hdlist (or none) -#- quiet : download hdlists quietly +#- probe_with : probe synthesis or rpms +#- quiet : download synthesis quietly #- wait_lock : block until lock can be acquired sub update_media { my ($urpm, %options) = @_; @@ -1777,15 +1436,14 @@ sub update_media { #- examine each medium to see if one of them needs to be updated. #- if this is the case and if not forced, try to use a pre-calculated - #- hdlist file, else build it from rpm files. + #- synthesis file, else build it from rpm files. clean($urpm); _update_media__handle_some_flags($urpm, $options{forcekey}, $options{all}); - my $clean_cache = !$options{noclean}; my %updates_result; foreach my $medium (grep { !$_->{ignore} } @{$urpm->{media}}) { - my $rc = _update_medium_first_pass($urpm, $medium, \$clean_cache, %options); + my $rc = _update_medium_first_pass($urpm, $medium, %options); $updates_result{$rc || 'error'}++; $rc or _update_medium_first_pass_failed($urpm, $medium); } @@ -1798,26 +1456,7 @@ sub update_media { return $updates_result{error} == 0; } - #- some unresolved provides may force to rebuild all synthesis, - #- a second pass will be necessary. - my $need_second_pass = - (grep { $_->{need_second_pass} } @{$urpm->{media}}) - #- second pass not useful if not a single media allowed to build a synthesis - && (grep { !$_->{virtual} } @{$urpm->{media}}) - #- second pass not useful if only synthesis available - && (grep { !$_->{synthesis} } @{$urpm->{media}}); - if ($need_second_pass) { - $urpm->{log}(N("performing second pass to compute dependencies\n")); - $urpm->unresolved_provides_clean; - } - foreach my $medium (grep { !$_->{ignore} } @{$urpm->{media}}) { - if ($need_second_pass) { - #- second pass consists in reading again synthesis or hdlists. - _update_medium_second_pass($urpm, $medium, $options{callback}); - } - _build_hdlist_synthesis($urpm, $medium); - if ($medium->{really_modified}) { _get_pubkey_and_descriptions($urpm, $medium, $options{nopubkey}); _read_cachedir_pubkey($urpm, $medium, $options{wait_lock}); -- cgit v1.2.1