Ticket #2198: base.add_sha1.diff

File base.add_sha1.diff, 7.0 KB (added by opendarwin.org@…, 20 years ago)

patch for sha1 addition, sha1cmd files coming next

  • base/src/pextlib1.0/Makefile

    cvs server: Diffing base
    cvs server: Diffing base/Mk
    cvs server: Diffing base/doc
    cvs server: Diffing base/doc/exampleport
    cvs server: Diffing base/src
    cvs server: Diffing base/src/cflib1.0
    cvs server: Diffing base/src/darwinports1.0
    cvs server: Diffing base/src/package1.0
    cvs server: Diffing base/src/pextlib1.0
    RCS file: /Volumes/src/cvs/od/projects/darwinports/base/src/pextlib1.0/Makefile,v
    retrieving revision 1.37
    diff -u -r1.37 Makefile
     
    11OBJS=           Pextlib.o strsed.o fgetln.o md5cmd.o setmode.o xinstall.o \
    2                 find.o strcasecmp.o vercomp.o filemap.o
     2                find.o strcasecmp.o vercomp.o filemap.o \
     3                sha1cmd.o
    34SHLIB_NAME=     Pextlib${SHLIB_SUFFIX}
    45INSTALLDIR= ${DESTDIR}${datadir}/darwinports/Tcl/pextlib1.0
    56
  • base/src/pextlib1.0/Pextlib.c

    RCS file: /Volumes/src/cvs/od/projects/darwinports/base/src/pextlib1.0/Pextlib.c,v
    retrieving revision 1.66
    diff -u -r1.66 Pextlib.c
     
    9494#include <tcl.h>
    9595
    9696#include "md5cmd.h"
     97#include "sha1cmd.h"
    9798#include "find.h"
    9899#include "filemap.h"
    99100#include "xinstall.h"
     
    716717        Tcl_CreateObjCommand(interp, "find", FindCmd, NULL, NULL);
    717718        Tcl_CreateObjCommand(interp, "filemap", FilemapCmd, NULL, NULL);
    718719        Tcl_CreateObjCommand(interp, "rpm-vercomp", RPMVercompCmd, NULL, NULL);
     720        Tcl_CreateObjCommand(interp, "sha1", SHA1Cmd, NULL, NULL);
    719721        if(Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
    720722                return TCL_ERROR;
    721723        return TCL_OK;
  • base/src/port1.0/portchecksum.tcl

    cvs server: Diffing base/src/pextlib1.0/tests
    cvs server: Diffing base/src/port
    cvs server: Diffing base/src/port1.0
    RCS file: /Volumes/src/cvs/od/projects/darwinports/base/src/port1.0/portchecksum.tcl,v
    retrieving revision 1.33
    diff -u -r1.33 portchecksum.tcl
     
    4545
    4646set_ui_prefix
    4747
    48 # dmd5
     48# get_checksum
    4949#
    50 # Returns the expected checksum for the given file.
    51 # If no checksum is found, returns -1.
     50# Returns the expected md5/sha1/etc. checksum for the given file.
     51# If no md5/sha1/etc. checksum is found, returns -1.
    5252#
    53 proc dmd5 {file} {
    54         foreach {name type sum} [option checksums] {
     53proc get_checksum {file want_sum port_checksums} {
     54        foreach {name type sum} $port_checksums {
    5555                if {[string equal $name $file]} {
    56                         return $sum
     56                        if {[string equal $type $want_sum]} {
     57                                return $sum
     58                        }
    5759                }
    5860        }
    5961
     
    7779proc checksum_main {args} {
    7880        global UI_PREFIX all_dist_files
    7981
     82        # we'll count how many successful checksums we get...
     83##      set chksum_success 0
     84
     85        # list of known checksum types:
     86        set checksum_types [list "md5" "sha1"]
     87
    8088        # If no files have been downloaded, there is nothing to checksum.
    8189        if {![info exists all_dist_files]} {
    8290                return 0
    8391        }
    8492
    8593        # Optimization for the two-argument case for checksums.
    86         if {[llength [option checksums]] == 2 && [llength $all_dist_files] == 1} {
    87                 option checksums [linsert [option checksums] 0 $all_dist_files]
     94        set port_checksums ""
     95        foreach {type sum} [option checksums] {
     96                ## see if $type is one of our known checksum types.  If it is,
     97                ## we assume we don't have our dist file name.  Check that
     98                ## we only expect 1 dist file as well...  If we have only
     99                ## one dist file and $type is a checksum_type, the add the
     100                ## $all_dist_files to the start of the checksum list.
     101                if {[lsearch -exact $checksum_types $type] != -1 && \
     102                        [llength $all_dist_files] == 1} {
     103                        set port_checksums [linsert $port_checksums 0 $all_dist_files $type $sum]
     104                }
     105        }
     106        ## if we didn't do the above filename insertions, we have an empty $port_checksums,
     107        ## so copy over the [option checksums] and use $port_checksums from here out
     108        if {[llength $port_checksums] == 0} {
     109                set port_checksums [option checksums]
    88110        }
    89111
    90112        set fail no
    91113
    92114        foreach distfile $all_dist_files {
    93115                ui_info "$UI_PREFIX [format [msgcat::mc "Checksumming %s"] $distfile]"
     116                set distfile_chksum_success 0
    94117
    95                 # Calculate the distfile's checksum.
    96                 set checksum [md5 file [file join [option distpath] $distfile]]
    97 
    98                 # Find the expected checksum.
    99                 set dchecksum [dmd5 $distfile]
    100 
    101                 # Check for missing checksum or a mismatch.
    102                 if {$dchecksum == -1} {
    103                         ui_error "[format [msgcat::mc "No checksum set for %s"] $distfile]"
    104                 } elseif {![string equal $checksum $dchecksum]} {
    105                         ui_error "[format [msgcat::mc "Checksum mismatch for %s"] $distfile]"
    106                 } else {
    107                         continue
     118                foreach chksum_type $checksum_types {
     119                        # Calculate the distfile's checksum.
     120                        set checksum [$chksum_type file [file join [option distpath] $distfile]]
     121       
     122                        # Find the expected checksum.
     123                        set dchecksum [get_checksum $distfile $chksum_type $port_checksums]
     124       
     125                        # Check for missing checksum or a mismatch.
     126                        if {$dchecksum == -1} {
     127                                ui_info "[format [msgcat::mc "No %s checksum set for %s"] $chksum_type $distfile]"
     128                        } elseif {![string equal $checksum $dchecksum]} {
     129                                ui_error "[format [msgcat::mc "%s checksum mismatch for '%s':"] $chksum_type $distfile]"
     130                                ui_error "[format [msgcat::mc "wanted '%s',"] $dchecksum]"
     131                                ui_error "[format [msgcat::mc "   got '%s'"] $checksum]"
     132                                # Raise the failure flag
     133                                set fail yes
     134                        } else {
     135                                set distfile_chksum_success [expr $distfile_chksum_success + 1]
     136                        }
     137       
     138                        if {[tbool fail]} {
     139                                return -code error "[format [msgcat::mc "Unable to verify %s checksum"] $chksum_type]"
     140                        }
     141                        ## else just fall to the next checksum...
     142       
     143                        if {$dchecksum != -1} {
     144                                # Post file checksum
     145                                ui_info "[format [msgcat::mc "Correct %s checksum: %s %s %s"] $chksum_type ${distfile} $chksum_type ${checksum}]"
     146                        }
    108147                }
    109148
    110                 # Post file checksum
    111                 ui_info "[format [msgcat::mc "Correct checksum: %s %s %s"] ${distfile} md5 ${checksum}]"
    112 
    113                 # Raise the failure flag
    114                 set fail yes
     149                if {$distfile_chksum_success == 0} {
     150                        ## oh bother, no successful checksum for this dist file, bailage
     151                        return -code error "[format [msgcat::mc "No checksums set for %s"] $distfile]"
     152                }
    115153        }
     154##      set chksum_success [expr $chksum_success + $distfile_chksum_success]
    116155
    117         if {[tbool fail]} {
    118                 return -code error "[msgcat::mc "Unable to verify file checksums"]"
    119         }
     156##      if {$chksum_success < 1 } {
     157##              return -code error "[msgcat::mc "Unable to verify file checksums"]"
     158##      }
    120159
    121160        return 0
    122161}