func()

in lib/ec2macosinit/instancehistory.go [47:78]


func (c *InitConfig) GetInstanceHistory() (err error) {
	// Read instance history directory
	dirs, err := os.ReadDir(c.HistoryPath)
	if err != nil {
		return fmt.Errorf("ec2macosinit: unable to read instance history directory: %w", err)
	}
	// For each directory, check for a history file and call readHistoryFile()
	for _, dir := range dirs {
		if dir.IsDir() {
			historyFile := filepath.Join(c.HistoryPath, dir.Name(), c.HistoryFilename)
			if info, err := os.Stat(historyFile); err == nil {
				// Check to make sure info is a file and not a directory.
				if !info.Mode().IsRegular() {
					continue
				}
				// If there is an error getting the history file or if the history file is empty do not append to Instance History
				if info.Size() == 0 {
					c.Log.Warnf("The history file exists at %s but is empty. Skipping this file...", historyFile)
					continue
				}
				history, err := readHistoryFile(historyFile)
				if err != nil {
					return fmt.Errorf("ec2macosinit: error while reading history file at %s: %w", historyFile, err)
				}
				// Append the returned History struct to the InstanceHistory slice
				c.InstanceHistory = append(c.InstanceHistory, history)
			}
		}
	}

	return nil
}