public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH] try all available compressors for Packages
@ 2021-07-14 14:49 Stoiko Ivanov
  2021-07-14 15:29 ` Thomas Lamprecht
  2021-07-14 15:37 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Stoiko Ivanov @ 2021-07-14 14:49 UTC (permalink / raw)
  To: pve-devel

Some repositories (e.g. debian-security) only offer .xz compressed
Packages, others (e.g. promox repositories) only .gz compressed ones.

Make the compressors an array and try them in order until successful

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
Note: best viewed with `-w`
Was not too sure about the comment on it being hacky - but it seems ok to me
this way (I think this is what apt does as well?)

 DAB.pm | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/DAB.pm b/DAB.pm
index 26db7ad..c540237 100644
--- a/DAB.pm
+++ b/DAB.pm
@@ -618,17 +618,16 @@ sub initialize {
     my $logfd = $self->{logfd} = IO::File->new (">$self->{logfile}") ||
 	die "unable to open log file";
 
-    # FIXME: seems a bit like a hacky way??
-    my $COMPRESSOR = {
-	ext => 'gz',
-	decomp => 'gzip -d',
-    };
-    if ($self->{config}->{suite} eq 'bullseye') {
-	$COMPRESSOR = {
+    my $COMPRESSORS = [
+	{
 	    ext => 'xz',
 	    decomp => 'xz -d',
-	};
-    }
+	},
+	{
+	    ext => 'gz',
+	    decomp => 'gzip -d',
+	},
+    ];
 
     foreach my $ss (@{$self->{sources}}) {
 	my $src = $ss->{mirror} || $ss->{source};
@@ -645,12 +644,21 @@ sub initialize {
 	    warn "Release info ignored\n";
 	};
 
-	foreach my $comp (@{$ss->{comp}}) {
-	    $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
-	    $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
-	    my $pkgsrc = "$src/$path";
-	    $self->download ($pkgsrc, $target);
-	    $self->run_command ("$COMPRESSOR->{decomp} '$target'");
+	foreach my $compressor (@$COMPRESSORS) {
+	    foreach my $comp (@{$ss->{comp}}) {
+		$path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
+		$target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
+		my $pkgsrc = "$src/$path";
+		eval {
+		    $self->download ($pkgsrc, $target);
+		    $self->run_command ("$compressor->{decomp} '$target'");
+		};
+		if (my $err = $@) {
+		    print $logfd "could not download Packages.$compressor->{ext}\n";
+		} else {
+		    last;
+		}
+	    }
 	}
     }
 }
-- 
2.30.2





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH] try all available compressors for Packages
  2021-07-14 14:49 [pve-devel] [PATCH] try all available compressors for Packages Stoiko Ivanov
@ 2021-07-14 15:29 ` Thomas Lamprecht
  2021-07-14 15:37 ` [pve-devel] applied: " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2021-07-14 15:29 UTC (permalink / raw)
  To: Proxmox VE development discussion, Stoiko Ivanov

On 14.07.21 16:49, Stoiko Ivanov wrote:
> Some repositories (e.g. debian-security) only offer .xz compressed
> Packages, others (e.g. promox repositories) only .gz compressed ones.
> 
> Make the compressors an array and try them in order until successful
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> Note: best viewed with `-w`
> Was not too sure about the comment on it being hacky - but it seems ok to me
> this way (I think this is what apt does as well?)

yes, not hacky and is just fine.

But actually I'd also provide a xz compressed variant in our repos, they can safe
about 25% to 30% in space and thus also bandwidth (albeit the Packages file is
naturally really small compared to the updates, but its still polled daily), and
that with really not much effort.

> 
>  DAB.pm | 38 +++++++++++++++++++++++---------------
>  1 file changed, 23 insertions(+), 15 deletions(-)
> 
> diff --git a/DAB.pm b/DAB.pm
> index 26db7ad..c540237 100644
> --- a/DAB.pm
> +++ b/DAB.pm
> @@ -618,17 +618,16 @@ sub initialize {
>      my $logfd = $self->{logfd} = IO::File->new (">$self->{logfile}") ||
>  	die "unable to open log file";
>  
> -    # FIXME: seems a bit like a hacky way??
> -    my $COMPRESSOR = {
> -	ext => 'gz',
> -	decomp => 'gzip -d',
> -    };
> -    if ($self->{config}->{suite} eq 'bullseye') {
> -	$COMPRESSOR = {
> +    my $COMPRESSORS = [
> +	{
>  	    ext => 'xz',
>  	    decomp => 'xz -d',
> -	};
> -    }
> +	},
> +	{
> +	    ext => 'gz',
> +	    decomp => 'gzip -d',
> +	},
> +    ];
>  
>      foreach my $ss (@{$self->{sources}}) {
>  	my $src = $ss->{mirror} || $ss->{source};
> @@ -645,12 +644,21 @@ sub initialize {
>  	    warn "Release info ignored\n";
>  	};
>  
> -	foreach my $comp (@{$ss->{comp}}) {
> -	    $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
> -	    $target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
> -	    my $pkgsrc = "$src/$path";
> -	    $self->download ($pkgsrc, $target);
> -	    $self->run_command ("$COMPRESSOR->{decomp} '$target'");
> +	foreach my $compressor (@$COMPRESSORS) {
> +	    foreach my $comp (@{$ss->{comp}}) {
> +		$path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
> +		$target = "$infodir/" . __url_to_filename ("$ss->{source}/$path");
> +		my $pkgsrc = "$src/$path";
> +		eval {
> +		    $self->download ($pkgsrc, $target);
> +		    $self->run_command ("$compressor->{decomp} '$target'");
> +		};
> +		if (my $err = $@) {
> +		    print $logfd "could not download Packages.$compressor->{ext}\n";
> +		} else {
> +		    last;
> +		}
> +	    }
>  	}
>      }
>  }
> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied: [PATCH] try all available compressors for Packages
  2021-07-14 14:49 [pve-devel] [PATCH] try all available compressors for Packages Stoiko Ivanov
  2021-07-14 15:29 ` Thomas Lamprecht
@ 2021-07-14 15:37 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2021-07-14 15:37 UTC (permalink / raw)
  To: Proxmox VE development discussion, Stoiko Ivanov

On 14.07.21 16:49, Stoiko Ivanov wrote:
> Some repositories (e.g. debian-security) only offer .xz compressed
> Packages, others (e.g. promox repositories) only .gz compressed ones.
> 
> Make the compressors an array and try them in order until successful
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> Note: best viewed with `-w`
> Was not too sure about the comment on it being hacky - but it seems ok to me
> this way (I think this is what apt does as well?)
> 
>  DAB.pm | 38 +++++++++++++++++++++++---------------
>  1 file changed, 23 insertions(+), 15 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-14 15:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 14:49 [pve-devel] [PATCH] try all available compressors for Packages Stoiko Ivanov
2021-07-14 15:29 ` Thomas Lamprecht
2021-07-14 15:37 ` [pve-devel] applied: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal