Exemplo n.º 1
0
func (chk FileMatches) Status() (int, string, error) {
	if chk.re.Match(chkutil.FileToBytes(chk.path)) {
		return errutil.Success()
	}
	msg := "File does not match regexp:"
	msg += "\n\tFile: " + chk.path
	msg += "\n\tRegexp: " + chk.re.String()
	return 1, msg, nil
}
Exemplo n.º 2
0
func (chk Checksum) Status() (int, string, error) {
	// getFileChecksum is self-explanatory
	fileChecksum := func(algorithm string, path string) string {
		if path == "" {
			log.Fatal("getFileChecksum got a blank path")
		} else if _, err := os.Stat(chk.path); err != nil {
			log.WithFields(log.Fields{
				"path": chk.path,
			}).Fatal("fileChecksum got an invalid path")
		}
		// we already validated the aglorithm
		chksum, _ := fsstatus.Checksum(algorithm, chkutil.FileToBytes(path))
		return chksum
	}
	actualChksum := fileChecksum(chk.algorithm, chk.path)
	if actualChksum == chk.expectedChksum {
		return errutil.Success()
	}
	msg := "Checksums do not match for file: " + chk.path
	return errutil.GenericError(msg, chk.expectedChksum, []string{actualChksum})
}
Exemplo n.º 3
0
// ChecklistFromFile reads the file at the path and parses its utf8 encoded json
// data, turning it into a checklist struct.
func ChecklistFromFile(path string) (chklst Checklist, err error) {
	log.Debug("Creating checklist from " + path)
	return ChecklistFromBytes(chkutil.FileToBytes(path))
}