diff options
author | Thierry Vignaud <tv@mandriva.org> | 2008-09-30 17:17:54 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mandriva.org> | 2008-09-30 17:17:54 +0000 |
commit | 0f757f957dfb1350b6654cc91972464f7d9febdf (patch) | |
tree | e77175339232e388485c3daa90ceb15878cbc8d2 /mdkapplet_urpm.pm | |
parent | 03a1c78b23611b82853fe0b192f9f4a35c3b471f (diff) | |
download | mgaonline-0f757f957dfb1350b6654cc91972464f7d9febdf.tar mgaonline-0f757f957dfb1350b6654cc91972464f7d9febdf.tar.gz mgaonline-0f757f957dfb1350b6654cc91972464f7d9febdf.tar.bz2 mgaonline-0f757f957dfb1350b6654cc91972464f7d9febdf.tar.xz mgaonline-0f757f957dfb1350b6654cc91972464f7d9febdf.zip |
dd support for downloading distro list as user for 2008.1
Diffstat (limited to 'mdkapplet_urpm.pm')
-rw-r--r-- | mdkapplet_urpm.pm | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/mdkapplet_urpm.pm b/mdkapplet_urpm.pm new file mode 100644 index 00000000..980854af --- /dev/null +++ b/mdkapplet_urpm.pm @@ -0,0 +1,55 @@ +package mdkapplet_urpm; + +# taken from urpmi: + +use MDK::Common; +use urpm::download; + +sub userdir_prefix { + my ($_urpm) = @_; + '/tmp/.urpmi-'; +} +sub userdir { + my ($urpm) = @_; + $< or return; + + my $dir = ($urpm->{urpmi_root} || '') . userdir_prefix($urpm) . $<; + mkdir $dir, 0755; # try to create it + + -d $dir && ! -l $dir or $urpm->{fatal}(1, sprintf("fail to create directory %s", $dir)); + -o $dir && -w $dir or $urpm->{fatal}(1, sprintf("invalid owner for directory %s", $dir)); + + mkdir "$dir/partial"; + mkdir "$dir/rpms"; + + $dir; +} +sub ensure_valid_cachedir { + my ($urpm) = @_; + if (my $dir = userdir($urpm)) { + $urpm->{cachedir} = $dir; + } + -w "$urpm->{cachedir}/partial" or $urpm->{fatal}(1, "Can not download packages into %s", "$urpm->{cachedir}/partial"); +} +sub valid_cachedir { + my ($urpm) = @_; + userdir($urpm) || $urpm->{cachedir}; +} + +sub get_content { + my ($urpm, $url) = @_; + + my $download_dir = valid_cachedir($urpm) . '/partial/'; + my $file = $download_dir . basename($url); + + unlink $file; # prevent "partial file" errors + urpm::download::sync($urpm, undef, [ $url ], quiet => 1, dir => $download_dir) or return; + #sync_url($urpm, $url, dir => $download_dir, quiet => 1) or return; + + my @l = cat_($file); + unlink $file; + + wantarray() ? @l : join('', @l); +} + +1; |