Changeset 96399


Ignore:
Timestamp:
Aug 8, 2012, 9:14:16 PM (8 years ago)
Author:
cal@…
Message:

base: Keep supporting old statefile layout, followup to r96136, #29223

Dropping support for old statefiles and just re-starting the build had
some undesired effects, e.g., when installing from binary archives
generated with the older statefile format or when trying to make a
pkg/mpkg from a previously installed package with the old statefile
format.

This change re-introduces support for reading old statefiles to fix
these problems. It also adds a version number to the statefile and warns
for unknown statefile versions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/port1.0/portutil.tcl

    r96136 r96399  
    16921692        }
    16931693        if {![tbool ports_ignore_different]} {
     1694            # start by assuming the statefile is current
     1695            set portfile_changed no
     1696
     1697            # open the statefile, determine the statefile version
    16941698            set readfd [open $statefile r]
    1695             gets $readfd checksum_statefile
    1696             if {$checksum_portfile != $checksum_statefile} {
    1697                 ui_debug "Checksum recorded in statefile \"$checksum_statefile\" differs from Portfile checksum \"$checksum_portfile\""
     1699            set statefile_version 1
     1700            if {[get_statefile_value "version" $readfd result] != 0} {
     1701                set statefile_version $result
     1702            }
     1703
     1704            # check for outdated statefiles depending on what version the
     1705            # statefile is; we explicitly support older statefiles here, because
     1706            # all previously built archives would be invalidated (e.g., when
     1707            # using mpkg) if we didn't
     1708            switch $statefile_version {
     1709                1 {
     1710                    # statefile version 1
     1711                    # this statefile doesn't have a checksum, fall back to
     1712                    # comparing the Portfile modification date with the
     1713                    # statefile modification date
     1714                    if {[file mtime $statefile] < [file mtime ${portpath}/Portfile]} {
     1715                        ui_debug "Statefile has version 1 and is older than Portfile"
     1716                        set portfile_changed yes
     1717                    }
     1718                }
     1719                2 {
     1720                    # statefile version 2
     1721                    # this statefile has a sha256 checksum of the Portfile in
     1722                    # the "checksum" key
     1723                    set checksum_statefile ""
     1724                    if {[get_statefile_value "checksum" $readfd checksum_statefile] == 0} {
     1725                        ui_warn "Statefile has version 2 but didn't contain a checksum"
     1726                        set portfile_changed yes
     1727                    } else {
     1728                        if {$checksum_portfile != $checksum_statefile} {
     1729                            ui_debug "Checksum recorded in statefile '$checksum_statefile' \
     1730                                differs from Portfile checksum '$checksum_portfile'"
     1731                            set portfile_changed yes
     1732                        }
     1733                    }
     1734                }
     1735                default {
     1736                    ui_warn "Unsupported statefile version '$statefile_version'"
     1737                    ui_warn "Please run 'port selfupdate' to update to the latest version of MacPorts"
     1738                }
     1739            }
     1740            if {[tbool portfile_changed]} {
    16981741                if {![tbool ports_dryrun]} {
    16991742                    ui_notice "Portfile changed since last build; discarding previous state."
     
    17271770    }
    17281771    if {[tbool fresh_build]} {
    1729         puts $fd $checksum_portfile
     1772        write_statefile "version" 2 $fd
     1773        write_statefile "checksum" $checksum_portfile $fd
    17301774    }
    17311775    return $fd
     1776}
     1777
     1778# get_statefile_value
     1779# Check for a given $class in the statefile $fd and write the first match to
     1780# $result, if any. Returns 1 if a line matched, 0 otherwise
     1781proc get_statefile_value {class fd result} {
     1782    upvar $result upresult
     1783    seek $fd 0
     1784    while {[gets $fd line] >= 0} {
     1785        if {[regexp "$class: (.*)" $line match value]} {
     1786            set upresult $value
     1787            return 1
     1788        }
     1789    }
     1790    return 0
    17321791}
    17331792
Note: See TracChangeset for help on using the changeset viewer.