<commit_before>package mdb

import (
	"encoding/json"
	"log"
	"os"
	"sort"
	"syscall"
	"time"
)

func startMdbDaemon(mdbFileName string, logger *log.Logger) chan *Mdb {
	mdbChannel := make(chan *Mdb)
	go watchDaemon(mdbFileName, mdbChannel, logger)
	return mdbChannel
}

func watchDaemon(mdbFileName string, mdbChannel chan *Mdb, logger *log.Logger) {
	var lastStat syscall.Stat_t
	var lastMdb *Mdb
	for ; ; time.Sleep(time.Second) {
		var stat syscall.Stat_t
		if err := syscall.Stat(mdbFileName, &stat); err != nil {
			logger.Printf("Error stating file: %s\t%s\n", mdbFileName, err)
			continue
		}
		if stat != lastStat {
			file, err := os.Open(mdbFileName)
			if err != nil {
				logger.Printf("Error opening file\t%s\n", err)
				continue
			}
			decoder := json.NewDecoder(file)
			var mdb Mdb
			if err = decoder.Decode(&mdb.Machines); err != nil {
				logger.Printf("Error decoding\t%s\n", err)
				continue
			}
			sort.Sort(&mdb)
			if lastMdb == nil || !compare(lastMdb, &mdb) {
				mdbChannel <- &mdb
				lastMdb = &mdb
			}
			lastStat = stat
		}
	}
}

func compare(oldMdb, newMdb *Mdb) bool {
	if len(oldMdb.Machines) != len(newMdb.Machines) {
		return false
	}
	for index, oldMachine := range oldMdb.Machines {
		if oldMachine != newMdb.Machines[index] {
			return false
		}
	}
	return true
}

func (mdb *Mdb) Less(left, right int) bool {
	if mdb.Machines[left].Hostname < mdb.Machines[right].Hostname {
		return true
	}
	return false
}

func (mdb *Mdb) Swap(left, right int) {
	tmp := mdb.Machines[left]
	mdb.Machines[left] = mdb.Machines[right]
	mdb.Machines[right] = tmp
}
<commit_msg>Ignore Atime changes for mdb file.<commit_after>package mdb

import (
	"encoding/json"
	"log"
	"os"
	"sort"
	"syscall"
	"time"
)

func startMdbDaemon(mdbFileName string, logger *log.Logger) chan *Mdb {
	mdbChannel := make(chan *Mdb)
	go watchDaemon(mdbFileName, mdbChannel, logger)
	return mdbChannel
}

func watchDaemon(mdbFileName string, mdbChannel chan *Mdb, logger *log.Logger) {
	var lastStat syscall.Stat_t
	var lastMdb *Mdb
	for ; ; time.Sleep(time.Second) {
		var stat syscall.Stat_t
		if err := syscall.Stat(mdbFileName, &stat); err != nil {
			logger.Printf("Error stating file: %s\t%s\n", mdbFileName, err)
			continue
		}
		stat.Atim = lastStat.Atim
		if stat != lastStat {
			file, err := os.Open(mdbFileName)
			if err != nil {
				logger.Printf("Error opening file\t%s\n", err)
				continue
			}
			decoder := json.NewDecoder(file)
			var mdb Mdb
			if err = decoder.Decode(&mdb.Machines); err != nil {
				logger.Printf("Error decoding\t%s\n", err)
				continue
			}
			sort.Sort(&mdb)
			if lastMdb == nil || !compare(lastMdb, &mdb) {
				mdbChannel <- &mdb
				lastMdb = &mdb
			}
			lastStat = stat
		}
	}
}

func compare(oldMdb, newMdb *Mdb) bool {
	if len(oldMdb.Machines) != len(newMdb.Machines) {
		return false
	}
	for index, oldMachine := range oldMdb.Machines {
		if oldMachine != newMdb.Machines[index] {
			return false
		}
	}
	return true
}

func (mdb *Mdb) Less(left, right int) bool {
	if mdb.Machines[left].Hostname < mdb.Machines[right].Hostname {
		return true
	}
	return false
}

func (mdb *Mdb) Swap(left, right int) {
	tmp := mdb.Machines[left]
	mdb.Machines[left] = mdb.Machines[right]
	mdb.Machines[right] = tmp
}

{'fraction_non_alphanumeric': 0.13623810984964713, 'fraction_numerical': 0.0, 'mean_word_length': 3.5786516853932584, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '760139', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1281, 'n_words': 297}