my $base_spec;
my @spec;
my @sources;
-my $sources;
+my $sources_file;
my %patchset;
sub print_source($$$);
push @spec, $_;
} elsif (/^NoSource\s*:\s*(\d+)\s*$/i) {
$no_source{ "source" . $1 } = 1;
- } elsif (my ($patchset_pattern, $patchset_start, $patchset_end) = /^%patchset_source.+-f\s+(\S+)\s+(\S+)\s+(\S+)/i) {
+ } elsif (my ($patchset) = /^%patchset_source\s+(.+)$/) {
+ use Getopt::Long qw(GetOptionsFromString);
+ my ($f, $s);
+ my ($ret, $args) = GetOptionsFromString($patchset, 's=s' => \$s, 'f=s' => \$f);
%patchset = (
- pattern => $patchset_pattern,
- start => $patchset_start,
- end => $patchset_end
+ pattern => $f,
+ filelist => $s,
+ start => $args->[0],
+ end => $args->[1],
);
}
}
shift @spec;
} # }}}
-sub process_patchset($) {
- my $macros = shift;
- return unless %patchset or $sources;
+# read in 'sources' file
+sub read_sources_file {
+ my $filename = $_[0] || $sources_file;
+ return () unless $filename and -e $filename;
- # parse sources file
my %files;
- open(my $fh, '<', $sources) or die $!;
+
+ open(my $fh, '<', $filename) or die $!;
while (<$fh>) {
chomp;
next unless my ($hash, $filename) = /^([a-f0-9]{32})\s+\*?(.+)$/;
$files{$filename} = $hash;
}
+ return \%files;
+}
+
+sub process_patchset($) {
+ my $macros = shift;
+ my $checksums;
+
+ return unless %patchset;
+
+ # print all files from sources file
+ if ($patchset{filelist}) {
+ my $prefix = expand($patchset{pattern}, $macros);
+ my $filelist = expand($patchset{filelist}, $macros);
+ $checksums = read_sources_file($filelist);
+ while (my($file, $hash) = each %$checksums) {
+ my $url = $prefix . $file;
+ print_source "patchset $file", $hash, $url;
+ }
+ return;
+ }
+
+ # parse sources file sequences
+ $checksums = read_sources_file() or return;
# print out patchset entries which source md5 is present in source file
my $start = expand($patchset{start}, $macros);
for (my $i = $start; $i <= $end; $i++) {
my $url = sprintf($pattern, $i);
my ($basename) = $url =~ m{/([^/]+$)};
- my $hash = $files{$basename} or next;
+ my $hash = $checksums->{$basename} or next;
print_source "patchset $i", $hash, $url;
}
}
{
my ($no, $md5, $s) = @_;
- if ($s =~ /^([a-z0-9A-Z;:\=\?&\@\+\~\.,\-\/_]|\%[0-9])+(#\/[a-zA-Z0-9\._-]+)?$/) {
+ if ($s =~ /^([a-z0-9A-Z;:\=\?&\@\+\~\.,\-\/\#_]|\%[0-9])+(#\/[a-zA-Z0-9\._-]+)?$/) {
if ($s =~ /^(ftp|http|https):\/\//) {
if ($s =~ /\/$/) {
error("source $no ($s) is directory");
}
}
close(F);
+
+ # find extra sources from detached checksum file
+ my $checksums = read_sources_file();
+ my @mapped = map { $_->[0] } @sources;
+ delete @sourcemap{@mapped};
+ while (my($source, $url) = each %sourcemap) {
+ my ($basename) = $url =~ m{/([^/]+$)};
+ next unless defined $basename;
+ my $hash = $checksums->{$basename} or next;
+ push @sources, [$source, $hash, $url];
+ }
} # }}}
next_spec(shift);
-$sources = shift if @ARGV;
-undef $sources if $sources and not -e $sources;
+$sources_file = shift if @ARGV;
preparse_spec($spec);
add_md5_to_print($spec);
cont( \@spec, { "nil" => "" } );