Skip to content

Commit

Permalink
pbuild: refactor keep_all_assets implementation
Browse files Browse the repository at this point in the history
We now do the asset pruning in the AssetMgr so that we do
not have do duplicate the pruning code for all asset types.
  • Loading branch information
mlschroe committed Jan 12, 2022
1 parent 5830008 commit efeece0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
20 changes: 13 additions & 7 deletions PBuild/AssetMgr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ sub add_assetshandler {
#
sub get_assetid {
my ($file, $asset) = @_;
return $asset->{'assetid'} if $asset->{'assetid'};
my $digest = $asset->{'digest'};
if ($digest) {
return Digest::MD5::md5_hex("$digest $file");
Expand All @@ -85,7 +86,8 @@ sub calc_mutable_id {
close $fd;
return $ctx->hexdigest();
}
return 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0'; # download on demand
# not available yet, use "download on demand" placeholder
return 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0';
}

#
Expand All @@ -102,10 +104,8 @@ sub update_srcmd5 {
my $asset = $asset_files->{$file};
die unless $asset->{'assetid'};
# use first part of digest if we have one
my $digest = $asset->{'digest'};
$digest =~ s/^.*:// if $digest;
if ($digest && length($digest) >= 32) {
$files{$file} = substr($digest, 0, 32);
if ($asset->{'digest'} && $asset->{'digest'} =~ /:([a-f0-9]{32})/) {
$files{$file} = $1;
} elsif ($asset->{'immutable'}) {
$files{$file} = substr($asset->{'assetid'}, 0, 32);
} else {
Expand All @@ -121,9 +121,15 @@ sub update_srcmd5 {
#
sub merge_assets {
my ($assetmgr, $p, $assets) = @_;
my $files = $p->{'files'};
for my $asset (@{$assets || []}) {
$asset->{'assetid'} ||= get_assetid($asset->{'file'}, $asset);
$p->{'asset_files'}->{$asset->{'file'}} = $asset;
my $file = $asset->{'file'};
if (!$assetmgr->{'keep_all_assets'}) {
# ignore asset if present in source list
next if $files->{$file} || $files->{"$file/"};
}
$asset->{'assetid'} ||= get_assetid($file, $asset);
$p->{'asset_files'}->{$file} = $asset;
}
}

Expand Down
2 changes: 0 additions & 2 deletions PBuild/RemoteAssets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ sub recipe_parse {
}
next unless $s->{'url'} =~ /(?:^|\/)([^\.\/][^\/]+)$/s;
my $file = $1;
next if $p->{'files'}->{$file} && !$p->{'keep_all_assets'};
undef $url unless $url =~ /^https?:\/\/.*\/([^\.\/][^\/]+)$/s;
my $digest = $s->{'digest'};
next unless $digest || $url;
Expand Down Expand Up @@ -217,7 +216,6 @@ sub fedpkg_parse {
warn("unparsable line in 'sources' file: $_\n");
next;
}
next if $p->{'files'}->{$asset->{'file'}} && !$p->{'keep_all_assets'};
push @assets, $asset if $asset->{'file'} =~ /^[^\.\/][^\/]*$/s;
}
close $fd;
Expand Down
2 changes: 1 addition & 1 deletion download_assets
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ for my $dir (@dirs) {
'dir' => $dir,
'files' => $files,
};
$p->{'keep_all_assets'} = 1 if $opts->{'clean'};

my $assetmgr = PBuild::AssetMgr::create($assetdir);
$assetmgr->{'keep_all_assets'} = 1 if $opts->{'clean'};
$assetmgr->add_assetshandler($_) for @{$opts->{'assets'} || []};
$assetmgr->add_assetshandler($fedpkg) if !$opts->{'assets'} && $files->{'sources'};
$assetmgr->merge_assets($p, $source_assets);
Expand Down

0 comments on commit efeece0

Please sign in to comment.