From efeece00948252d141ac4584dbf6d5eaf1ee8b0c Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Wed, 12 Jan 2022 13:54:10 +0100 Subject: [PATCH] pbuild: refactor keep_all_assets implementation We now do the asset pruning in the AssetMgr so that we do not have do duplicate the pruning code for all asset types. --- PBuild/AssetMgr.pm | 20 +++++++++++++------- PBuild/RemoteAssets.pm | 2 -- download_assets | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/PBuild/AssetMgr.pm b/PBuild/AssetMgr.pm index 5302f9694..a02a11945 100644 --- a/PBuild/AssetMgr.pm +++ b/PBuild/AssetMgr.pm @@ -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"); @@ -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'; } # @@ -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 { @@ -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; } } diff --git a/PBuild/RemoteAssets.pm b/PBuild/RemoteAssets.pm index f78b2f1e0..a16a7bd47 100644 --- a/PBuild/RemoteAssets.pm +++ b/PBuild/RemoteAssets.pm @@ -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; @@ -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; diff --git a/download_assets b/download_assets index 867055584..43a77dd93 100755 --- a/download_assets +++ b/download_assets @@ -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);