Improve Comments on common/Log

This Patch Has Been Applied
Sarah@auth.lopeos.org submitted a patch request Feb 16, 2025 00:25
  • Title: Improve Comments on common/log
  • Author: Sarah Jamie Lewis <sarah@openprivacy.ca>

common/log.go

@@ -21,6 +21,9 @@ type LogEntry struct {
  

              type Log []LogEntry

              

            +// senary keeps issues and change requests on-disk and maintains a log of actions over these artifacts i.e. created, approved or deleted.

            +// logs can in theory be "collapsed" by permanently deleting create and approved entries if a deleted entry also exists

            +// we don't do this here, but may want to build a standalone command to do this in the future.

              func WriteToLog(filename string, hash string, t LogType) error {

              	file, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)

              	if err != nil {

            
@@ -31,6 +34,7 @@ func WriteToLog(filename string, hash string, t LogType) error {
  	return err

              }

              

            +// iterate over each log entry and callback to the provided function

              func LogIer(filename string, callback func(LogEntry)) error {

              	file, err := os.Open(filename)

              	if err != nil {

            
@@ -39,11 +43,15 @@ func LogIer(filename string, callback func(LogEntry)) error {
  	defer file.Close()

              

              	scanner := bufio.NewScanner(file)

            -	// optionally, resize scanner's capacity for lines over 64K, see next example

              	for scanner.Scan() {

              		logline := scanner.Text()

              		logEntry := LogEntry{}

            -		fmt.Sscanf(logline, "%s %d", &logEntry.Hash, &logEntry.Type)

            +		n, err := fmt.Sscanf(logline, "%s %d", &logEntry.Hash, &logEntry.Type)

            +

            +		// corrupted or malformed log entry, we can't recover from this so abort...

            +		if n != 2 || err != nil {

            +			return err

            +		}

              		callback(logEntry)

              	}