in main/cmds.go [81:111]
func migrateToMostRecentSequence(ctx *log.Context, h HandlerEnvironment, seqNum int) {
// The status folder is used instead of the settings because the settings file is written
// by the agent before install is called. As a result, the extension cannot determine if this
// is a new install or an upgrade.
//
// If this is an upgrade there will be a status file. The agent will re-write the last status
// file to indicate that the upgrade happened successfully. The extension uses the last status
// sequence number to determine the last settings file that was executed.
//
// The agent helpfully copies mrseq every time an extension is upgraded thereby preserving the
// most recent executed sequence. If extensions use mrseq they benefit from this mechanism, and
// do not have invent another method. The CustomScript extension should have been using this
// from the beginning, but it was not.
//
computedSeqNum, err := FindSeqNumStatus(h.HandlerEnvironment.StatusFolder)
if err != nil {
// If there was an error, the sequence number is zero.
ctx.Log("event", "migrate to mrseq", "error", err)
return
}
fout, err := os.Create(mostRecentSequence)
if err != nil {
ctx.Log("event", "migrate to mrseq", "error", err)
return
}
defer fout.Close()
ctx.Log("event", "migrate to mrseq", "message", fmt.Sprintf("migrated mrseq to %v", computedSeqNum))
fout.WriteString(fmt.Sprintf("%v", computedSeqNum))
}