diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-09-23 11:46:18 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-09-23 11:46:18 +0000 |
commit | 8747855c9d65d3055e223da4a30488ef99570771 (patch) | |
tree | 8e1f8eb3cd28aaefe5a4fa125d4438848d69dd9e /urpm | |
parent | b743f830a3e7bf919434306aaa37f1337ce81864 (diff) | |
download | urpmi-8747855c9d65d3055e223da4a30488ef99570771.tar urpmi-8747855c9d65d3055e223da4a30488ef99570771.tar.gz urpmi-8747855c9d65d3055e223da4a30488ef99570771.tar.bz2 urpmi-8747855c9d65d3055e223da4a30488ef99570771.tar.xz urpmi-8747855c9d65d3055e223da4a30488ef99570771.zip |
- sync_*(): return the downloaded file
- sync_rel: handle "preclean", and do cleanup things after failed download
- simplify some mess using the returned value
Diffstat (limited to 'urpm')
-rw-r--r-- | urpm/download.pm | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/urpm/download.pm b/urpm/download.pm index fe6097dd..dee10c53 100644 --- a/urpm/download.pm +++ b/urpm/download.pm @@ -823,32 +823,34 @@ sub sync_rel { my $files_text = join(' ', ($medium->{allow_metalink} ? ($medium->{mirrorlist}, $medium->{'with-dir'}) : url_obscuring_password($medium->{url})), @$rel_files); $urpm->{debug} and $urpm->{debug}(N("retrieving %s", $files_text)); - eval { - _sync_webfetch_raw($urpm, $medium, $rel_files, \@files, _all_options($urpm, $medium, \%options)); + my $all_options = _all_options($urpm, $medium, \%options); + my @result_files = map { $all_options->{dir} . '/' . basename($_) } @$rel_files; + unlink @result_files if $all_options->{preclean}; + + if (eval { _sync_webfetch_raw($urpm, $medium, $rel_files, \@files, $all_options); 1 }) { $urpm->{log}(N("retrieved %s", $files_text)); - 1; - }; + \@result_files; + } else { + # don't leave partial download + unlink @result_files; + undef; + } } sub sync_url { my ($urpm, $url, %options) = @_; - sync_rel($urpm, { url => dirname($url) }, [basename($url)], %options); + my $files = sync_rel($urpm, { url => dirname($url) }, [basename($url)], %options) or return; + @$files; } sub sync_rel_to { my ($urpm, $medium, $rel_file, $dest_file, %options) = @_; - my $download_dir = $options{dir} || "$urpm->{cachedir}/partial"; - my $result_file = "$download_dir/" . basename($rel_file); - - if (sync_rel($urpm, $medium, [$rel_file], %options)) { - $result_file ne $dest_file or rename($result_file, $dest_file) or return; - 1; - } else { - unlink $result_file; - undef; - } + my $files = sync_rel($urpm, $medium, [$rel_file], %options) or return undef; + my $result_file = $files->[0]; + $result_file ne $dest_file or rename($result_file, $dest_file) or return; + $result_file; } #- deprecated, use sync_url() or sync_rel() instead @@ -868,11 +870,7 @@ sub sync { sub get_content { my ($urpm, $url) = @_; - my $download_dir = urpm::valid_cachedir($urpm) . '/partial/'; - my $file = $download_dir . basename($url); - - unlink $file; # prevent "partial file" errors - sync_url($urpm, $url, dir => $download_dir, quiet => 1) or return; + my $file = sync_url($urpm, $url, quiet => 1, preclean => 1) or return; my @l = cat_($file); unlink $file; |