Package: duck
Version: 0.14.4
Severity: wishlist
Tags: patch
Hi,
While trying to add a duck importer to UDD, I needed a way to dump URLs
and overrides out of duck. This patch implements such a dump option.
UDD uses a vendorized version of duck, so this isn't a blocker for the
importer.
Note that my perl is rusty and the patch is partially AI-generated.
So please review with care.
Also note that this only dumps the collected URLs, and does not check
the status of those URLs. So it does not fix #949855.
Lucas
diff -bur duck-0.14.4/src/duck /home/lucas/d/debian/udd/vendor/duck/src/duck
--- duck-0.14.4/src/duck 2023-11-12 16:48:51.000000000 +0100
+++ /home/lucas/d/debian/udd/vendor/duck/src/duck 2025-06-03 20:49:53.038574024 +0200
@@ -37,6 +37,7 @@
# require lib;
use Parallel::ForkManager;
+use JSON;
sub HELP_MESSAGE();
sub setColor($;$);
@@ -49,6 +50,7 @@
sub cleanup();
sub get_duck_overrides();
sub is_overridden($;$);
+sub dump_urls($);
our $color_r = "\x1b[31m";
our $color_g = "\x1b[32m";
our $color_y = "\x1b[33m";
@@ -89,6 +91,7 @@
my $urlFixDisableOptions;
my $tempdir;
my @global_options = ("n", "v", "q");
+my $dumpMode = 0;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
@@ -109,7 +112,8 @@
"enable-urlfix=s" => \$urlFixEnableOptions,
"color=s" => \$enforceColor,
"colour=s" => \$enforceColor,
- "tasks=i" => \$parallel_tasks
+ "tasks=i" => \$parallel_tasks,
+ "dump" => \$dumpMode
);
die("Number of parallel tasks must be >0") unless (int($parallel_tasks) > 0);
@@ -251,6 +255,12 @@
$n->run(\%opt, \@entries);
}
+# Handle dump mode
+if ($dumpMode) {
+ dump_urls(\@entries);
+ exit 0;
+}
+
# inject all options to check modules
$DUCK->setOptions("no-https", $try_https);
$DUCK->setOptions("no-check-certificate", $no_check_cert);
@@ -749,6 +759,8 @@
--tasks=[number]\t\tSpecify the number of checks allowed to run in parallel. Default value is 24.
\t\t\t\tThis value must be an integer value >0.
+ --dump-urls=<file>\t\tDump all found URLs and overrides to a JSON file instead of checking them.
+
--version\t\t\tdisplay copyright and version information
Available module options:
@@ -798,3 +810,36 @@
return $out;
}
+
+sub dump_urls($) {
+ my ($entries_ref) = @_;
+ my @entries = @{$entries_ref};
+
+ my $json = JSON->new->pretty;
+ my $dump_data = {
+ version => "1.0",
+ timestamp => time(),
+ overrides => \@overrides,
+ entries => []
+ };
+
+ foreach my $entry (@entries) {
+ my $type = @$entry[0];
+ my $checkmethod = @$entry[1];
+ my $url = @$entry[2];
+ my $origline = @$entry[3];
+ my $extra = @$entry[4];
+
+ chomp $origline unless !$origline;
+
+ push @{$dump_data->{entries}}, {
+ type => $type,
+ checkmethod => $checkmethod,
+ url => $url,
+ origline => $origline,
+ extra => $extra
+ };
+ }
+
+ print $json->encode($dump_data);
+}