From: Ian Jackson Date: Sun, 3 Aug 2014 19:28:51 +0000 (+0100) Subject: Use curl to download things rather than dget; do our own processing of the files X-Git-Tag: debian/0.22~22 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=ac221d67c7227d43ad69f8a9a291411d15cefd41;hp=27770bb8b01de8961513430402d3efa68873b5e6 Use curl to download things rather than dget; do our own processing of the files --- diff --git a/debian/changelog b/debian/changelog index b63b8291..963eaa60 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ dgit (0.22~experimental1) experimental; urgency=low to pass -dubuntu. Closes:#751781. * Use mirror.ftp-master.debian.org DNS alias rather than coccia. Closes:#752602. + * Check hashes of files ourselves rather than running dget to + re-retreive the .dsc. Minor improvements: * Include canonicalised suite name in signed tag message. diff --git a/dgit b/dgit index d587527c..461e5e65 100755 --- a/dgit +++ b/dgit @@ -57,6 +57,7 @@ our $suite_re = '[-+.0-9a-z]+'; our (@git) = qw(git); our (@dget) = qw(dget); +our (@curl) = qw(curl -f); our (@dput) = qw(dput); our (@debsign) = qw(debsign); our (@gpg) = qw(gpg); @@ -69,7 +70,8 @@ our (@dpkggenchanges) = qw(dpkg-genchanges); our (@mergechanges) = qw(mergechanges -f); our (@changesopts) = (''); -our %opts_opt_map = ('dget' => \@dget, +our %opts_opt_map = ('dget' => \@dget, # accept for compatibility + 'curl' => \@curl, 'dput' => \@dput, 'debsign' => \@debsign, 'gpg' => \@gpg, @@ -972,20 +974,33 @@ sub clogp_authline ($) { sub generate_commit_from_dsc () { prep_ud(); changedir $ud; - my @files; - foreach my $f (dsc_files()) { + + foreach my $fi (dsc_files_info()) { + my $f = $fi->{Filename}; die "$f ?" if $f =~ m#/|^\.|\.dsc$|\.tmp$#; - push @files, $f; + link "../../../$f", $f or $!==&ENOENT or die "$f $!"; + + complete_file_from_dsc('.', $fi); + + if (is_orig_file($f)) { + link $f, "../../../../$f" + or $!==&EEXIST + or die "$f $!"; + } } - runcmd @dget, qw(--), $dscurl; - foreach my $f (grep { is_orig_file($_) } @files) { - link $f, "../../../../$f" - or $!==&EEXIST - or die "$f $!"; - } + + my $dscfn = "$package.dsc"; + + open D, ">", $dscfn or die "$dscfn: $!"; + print D $dscdata or die "$dscfn: $!"; + close D or die "$dscfn: $!"; + my @cmd = qw(dpkg-source); + push @cmd, qw(-x --), $dscfn; + runcmd @cmd; + my ($tree,$dir) = mktree_in_ud_from_only_subdir(); runcmd qw(sh -ec), 'dpkg-parsechangelog >../changelog.tmp'; my $clogp = parsecontrol('../changelog.tmp',"commit's changelog"); @@ -1046,30 +1061,47 @@ END return $outputhash; } +sub complete_file_from_dsc ($$) { + our ($dstdir, $fi) = @_; + # Ensures that we have, in $dir, the file $fi, with the correct + # contents. (Downloading it from alongside $dscurl if necessary.) + + my $f = $fi->{Filename}; + my $tf = "$dstdir/$f"; + my $downloaded = 0; + + if (stat $tf) { + progress "using existing $f"; + } else { + die "$tf $!" unless $!==&ENOENT; + + my $furl = $dscurl; + $furl =~ s{/[^/]+$}{}; + $furl .= "/$f"; + die "$f ?" unless $f =~ m/^${package}_/; + die "$f ?" if $f =~ m#/#; + runcmd_ordryrun_local @curl,qw(-o),$tf,'--',"$furl"; + next if !act_local(); + $downloaded = 1; + } + + open F, "<", "$tf" or die "$tf: $!"; + $fi->{Digester}->reset(); + $fi->{Digester}->addfile(*F); + F->error and die $!; + my $got = $fi->{Digester}->hexdigest(); + $got eq $fi->{Hash} or + fail "file $f has hash $got but .dsc". + " demands hash $fi->{Hash} ". + ($downloaded ? "(got wrong file from archive!)" + : "(perhaps you should delete this file?)"); +} + sub ensure_we_have_orig () { foreach my $fi (dsc_files_info()) { my $f = $fi->{Filename}; next unless is_orig_file($f); - if (open F, "<", "../$f") { - $fi->{Digester}->reset(); - $fi->{Digester}->addfile(*F); - F->error and die $!; - my $got = $fi->{Digester}->hexdigest(); - $got eq $fi->{Hash} or - fail "existing file $f has hash $got but .dsc". - " demands hash $fi->{Hash}". - " (perhaps you should delete this file?)"; - progress "using existing $f"; - next; - } else { - die "$f $!" unless $!==&ENOENT; - } - my $origurl = $dscurl; - $origurl =~ s{/[^/]+$}{}; - $origurl .= "/$f"; - die "$f ?" unless $f =~ m/^${package}_/; - die "$f ?" if $f =~ m#/#; - runcmd_ordryrun_local shell_cmd 'cd ..', @dget,'--',$origurl; + complete_file_from_dsc('..', $fi); } } @@ -2164,8 +2196,6 @@ if ($ENV{$fakeeditorenv}) { quilt_fixup_editor(); } -delete $ENV{'DGET_UNPACK'}; - parseopts(); print STDERR "DRY RUN ONLY\n" if $dryrun_level > 1; print STDERR "DAMP RUN - WILL MAKE LOCAL (UNSIGNED) CHANGES\n" diff --git a/dgit.1 b/dgit.1 index 6449ea34..de54068d 100644 --- a/dgit.1 +++ b/dgit.1 @@ -274,9 +274,9 @@ Passed to dpkg-genchanges (eventually). Specifies a single additional option to pass, eventually, to dpkg-genchanges. .TP -.RI \fB--dget=\fR program |\fB--dput=\fR program |... +.RI \fB--curl=\fR program |\fB--dput=\fR program |... Specifies alternative programs to use instead of -.BR dget , +.BR curl , .BR dput , .BR debsign , .BR dpkg-source , @@ -312,9 +312,9 @@ git to access dgit-repos, only git's idea of what ssh to use (eg, .BR GIT_SSH ) is relevant. .TP -.RI \fB--dget:\fR option |\fB--dput:\fR option |... +.RI \fB--curl:\fR option |\fB--dput:\fR option |... Specifies a single additional option to pass to -.BR dget , +.BR curl , .BR dput , .BR debsign , .BR dpkg-source , @@ -663,7 +663,7 @@ interprets it the same way as git does. See also the --ssh= and --ssh: options. .TP -.BR gpg ", " dpkg- "..., " debsign ", " git ", " dget ", " dput ", " LWP::UserAgent +.BR gpg ", " dpkg- "..., " debsign ", " git ", " curl ", " dput ", " LWP::UserAgent and other subprograms and modules used by dgit are affected by various environment variables. Consult the documentaton for those programs for details. @@ -728,7 +728,7 @@ well-defined interface, let alone a secure one.) fetches may result in subsequent actions being different. Doing a non-dry-run dgit fetch first will help. .SH SEE ALSO -\fBdget\fP(1), +\fBcurl\fP(1), \fBdput\fP(1), \fBdebsign\fP(1), \fBgit-config\fP(1),