<commit_before>package unnoticed

import (
	"path/filepath"
	"time"

	"github.com/fsnotify/fsnotify"
)

// Watch waits until fn is modified.
func Watch(fn string) {
	fn, err := filepath.Abs(fn)
	if err != nil {
		LogMsg(err)
	}
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		LogFatalf("couldn't get a watcher for %s", fn)
	}
	watcher.Add(fn)
	defer watcher.Close()
	for {
		select {
		case event := <-watcher.Events:
			// Wait a bit to make sure we don't process bursts of events.
			time.Sleep(5 * time.Second)
			LogMsgf("monitor event: %s", event)
			return
		case err := <-watcher.Errors:
			LogMsgf("monitor error: %s", err)
		}
	}
}<commit_msg>Check for file modifications with MD5 hashing<commit_after>package unnoticed

import (
	"crypto/md5"
	"fmt"
	"io"
	"os"
	"path/filepath"
	"time"
)

// Watch waits until fn is modified.
func Watch(fn string) {
	path, err := filepath.Abs(fn)
	if err != nil {
		LogMsg(err)
		path = fn
	}

	initHash, err := getHash(path)
	if err != nil {
		// This shouldn't happen, but if it does then wait a
		// bit before returning to avoid spamming my API.
		LogMsg(err)
		LogMsgf("Couldn't get initial hash value for %s", path)
		time.Sleep(time.Minute)
		return
	}
	fmt.Printf("%x\n", initHash)
	for {
		hash, err := getHash(path)
		if err != nil {
			LogMsg(err)
		} else if string(hash) != string(initHash) {
			LogMsgf("%s was modified", path)
			return
		}
		time.Sleep(time.Second * 10)
	}
}

// getHash computes the MD5 hash value for the file fn.
func getHash(fn string) ([]byte, error) {
	f, err := os.Open(fn)
	if err != nil {
		LogMsgf("reading %s failed", fn)
		return nil, err
	}
	defer f.Close()
	h := md5.New()
	if _, err := io.Copy(h, f); err != nil {
		LogMsgf("computing the hash for %s failed", fn)
		return nil, err
	} else {
		return h.Sum(nil), nil
	}
}
{'fraction_non_alphanumeric': 0.14583333333333334, 'fraction_numerical': 0.003837719298245614, 'mean_word_length': 3.234338747099768, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3552398', 'n_tokens_mistral': 756, 'n_tokens_neox': 695, 'n_words': 210}