Skip to content

Commit

Permalink
Merge pull request #752 from adrianschroeter/download_assets_clean
Browse files Browse the repository at this point in the history
add download_assets --clean option
  • Loading branch information
mlschroe committed Jan 7, 2022
2 parents a0da7a7 + 59f7406 commit 5a7a35b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion PBuild/RemoteAssets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sub recipe_parse {
}
next unless $s->{'url'} =~ /(?:^|\/)([^\.\/][^\/]+)$/s;
my $file = $1;
next if $p->{'files'}->{$file};
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 @@ -88,6 +88,7 @@ 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
15 changes: 15 additions & 0 deletions download_assets
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ my %known_options = (
'assetdir' => ':',
'assets' => '::',
'noassetdir' => '',
'clean' => '',
'unpack' => '',

'create-cpio' => '',
Expand Down Expand Up @@ -102,6 +103,8 @@ for my $dir (@dirs) {
'dir' => $dir,
'files' => $files,
};
$p->{'keep_all_assets'} = 1 if $opts->{'clean'};

my $assetmgr = PBuild::AssetMgr::create($assetdir);
$assetmgr->add_assetshandler($_) for @{$opts->{'assets'} || []};
$assetmgr->add_assetshandler($fedpkg) if !$opts->{'assets'} && $files->{'sources'};
Expand All @@ -123,6 +126,18 @@ for my $dir (@dirs) {
$p->{'name'} ||= $d->{'name'} if $d->{'name'};
$assetmgr->find_assets($p);
}
if ($opts->{'clean'}) {
my $af = $p->{'asset_files'} || {};
for (values %$af) {
if ($_->{'isdir'}) {
PBuild::Util::rm_rf("$dir/$_->{'file'}") if -d "$dir/$_->{'file'}";
unlink "$dir/$_->{'file'}.obscpio" if -e "$dir/$_->{'file'}.obscpio";
} else {
unlink "$dir/$_->{'file'}" if -e "$dir/$_->{'file'}";
}
}
next;
}
if ($opts->{'unpack'} && $opts->{'noassetdir'}) {
my $af = $p->{'asset_files'} || {};
for (values %$af) {
Expand Down

0 comments on commit 5a7a35b

Please sign in to comment.