Skip to content

Commit

Permalink
Merge pull request #14211 from mlschroe/master
Browse files Browse the repository at this point in the history
[backend] fix compress_entry call in create_layer_data
  • Loading branch information
mlschroe committed Apr 24, 2023
2 parents aa04625 + 5a4b2f5 commit 7759577
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
32 changes: 20 additions & 12 deletions src/backend/BSContar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,20 @@ sub normalize_container {
}
my $newcomp = 'gzip';
if (!$comp || $comp ne $newcomp || $recompress) {
my $outfile;
if ($tmpdir) {
$outfile = "$tmpdir/.compress_entry_${cnt}.$$";
$cnt++;
unlink($outfile);
}
if ($comp) {
print "recompressing $layer_ent->{'name'}... ";
} else {
print "compressing $layer_ent->{'name'}... ";
}
if ($tmpdir) {
my $outfile = "$tmpdir/.compress_entry_${cnt}.$$";
unlink($outfile);
$layer_ent = compress_entry($layer_ent, $comp, $newcomp, $outfile);
unlink($outfile);
$cnt++;
} else {
$layer_ent = compress_entry($layer_ent, $comp, $newcomp);
}
$layer_ent = compress_entry($layer_ent, $comp, $newcomp, $outfile);
print "done.\n";
unlink($outfile) if $outfile;
}
my $blobid = blobid_entry($layer_ent);
$newblobs{$blobid} ||= { %$layer_ent, 'name' => $blobid };
Expand Down Expand Up @@ -410,10 +409,13 @@ sub container_from_helm {
my $chartbasename = $chartfile;
$chartbasename =~ s/^.*\///;
my $chart_ent = { 'name' => $chartbasename, 'offset' => 0, 'size' => $s[7], 'mtime' => $mtime, 'file' => $fd };
my @layercomp;
if ($chartbasename =~ /($?:\.tar\.gz|\.tgz)$/) {
$chart_ent->{'mimetype'} = 'application/vnd.cncf.helm.chart.content.v1.tar+gzip';
push @layercomp, 'gzip';
} else {
$chart_ent->{'mimetype'} = 'application/vnd.cncf.helm.chart.content.v1.tar';
push @layercomp, '';
}
# create ent for the config
my $config_ent = { 'name' => 'config.json', 'size' => length($config_json), 'data' => $config_json, 'mtime' => $mtime };
Expand All @@ -425,16 +427,22 @@ sub container_from_helm {
'RepoTags' => $repotags || [],
};
my $manifest_ent = create_manifest_entry($manifest, $mtime);
return ([ $manifest_ent, $config_ent, $chart_ent ], $mtime);
my $tar = [ $manifest_ent, $config_ent, $chart_ent ];
return ($tar, $mtime, \@layercomp);
}

sub create_layer_data {
my ($layer_ent, $oci, $comp, $newcomp, $lcomp) = @_;
$comp ||= detect_entry_compression($layer_ent);
$newcomp ||= $oci && $comp eq 'zstd' ? 'zstd' : 'gzip';
$newcomp = $comp if $layer_ent->{'mimetype'}; # do not change the compression if the mime type is already set
if ($comp ne $newcomp) {
print "compressing $layer_ent->{'name'}... ";
$layer_ent = compress_layer_ent($layer_ent, $comp, $newcomp);
if ($comp) {
print "recompressing $layer_ent->{'name'}... ";
} else {
print "compressing $layer_ent->{'name'}... ";
}
$layer_ent = compress_entry($layer_ent, $comp, $newcomp);
print "done.\n";
undef $lcomp;
}
Expand Down
12 changes: 6 additions & 6 deletions src/backend/BSPublisher/Registry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ sub construct_container_tar {
push @tar, {'name' => $blobid, 'file' => $file, 'mtime' => $mtime, 'offset' => 0, 'size' => (-s $file), 'blobid' => $blobid};
}
push @tar, {'name' => 'manifest.json', 'data' => $manifest, 'mtime' => $mtime, 'size' => length($manifest)};
return (\@tar, $mtime);
return (\@tar, $mtime, $containerinfo->{'layer_compression'});
}

sub gen_timestampkey {
Expand Down Expand Up @@ -654,17 +654,17 @@ sub push_containers {
next;
}

my ($tar, $mtime);
my ($tar, $mtime, $layer_compression);
my $tarfd;
if ($containerinfo->{'uploadfile'}) {
open($tarfd, '<', $containerinfo->{'uploadfile'}) || die("$containerinfo->{'uploadfile'}: $!\n");
if (($containerinfo->{'type'} || '') eq 'helm') {
($tar, $mtime) = BSContar::container_from_helm($containerinfo->{'uploadfile'}, $containerinfo->{'config_json'}, $containerinfo->{'tags'});
($tar, $mtime, $layer_compression) = BSContar::container_from_helm($containerinfo->{'uploadfile'}, $containerinfo->{'config_json'}, $containerinfo->{'tags'});
} else {
($tar, $mtime) = BSContar::normalize_container($tarfd, 1);
($tar, $mtime, $layer_compression) = BSContar::normalize_container($tarfd, 1);
}
} else {
($tar, $mtime) = construct_container_tar($containerinfo);
($tar, $mtime, $layer_compression) = construct_container_tar($containerinfo);
}
my %tar = map {$_->{'name'} => $_} @$tar;

Expand Down Expand Up @@ -704,7 +704,7 @@ sub push_containers {
# put layer blobs into repo
my %layer_datas;
my @layer_data;
my @layer_comp = @{($containerinfo || {})->{'layer_compression'} || []};
my @layer_comp = @{$layer_compression || []};
for my $layer_file (@layers) {
my $lcomp = shift @layer_comp;
if ($layer_datas{$layer_file}) {
Expand Down

0 comments on commit 7759577

Please sign in to comment.