<commit_before>package main

import (
	"context"

	"log"
	"path/filepath"

	"github.com/AsynkronIT/protoactor-go/actor"
	"github.com/ansrivas/fwatcher/messages"
	"github.com/fsnotify/fsnotify"
)

func isFileTypeAllowed(ext string, allowedExt []string) bool {
	for _, e := range allowedExt {
		if ext == e {
			return true
		}
	}
	return false
}

func watchDirectory(ctx context.Context, dirToWatch string, allowedExt []string, pid *actor.PID) {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	err = watcher.Add(dirToWatch)
	if err != nil {
		log.Fatal(err)
	}

	for {
		select {
		case event := <-watcher.Events:

			log.Println(event.Op)
			if event.Op == fsnotify.Create {
				log.Println("File created...")
				fileext := filepath.Ext(event.Name)
				if isFileTypeAllowed(fileext, allowedExt) {
					pid.Tell(&messages.FileModified{Filepath: event.Name})
				} else {
					log.Printf("Skipping this as, file type %v not allowed", fileext)
				}
			}

		case err := <-watcher.Errors:
			log.Println("error:", err)

		}
	}
}<commit_msg>cleanup after context cancel<commit_after>package main

import (
	"context"

	"log"
	"path/filepath"

	"github.com/AsynkronIT/protoactor-go/actor"
	"github.com/ansrivas/fwatcher/messages"
	"github.com/fsnotify/fsnotify"
)

func isFileTypeAllowed(ext string, allowedExt []string) bool {
	for _, e := range allowedExt {
		if ext == e {
			return true
		}
	}
	return false
}

func watchDirectory(ctx context.Context, dirToWatch string, allowedExt []string, pid *actor.PID) {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	err = watcher.Add(dirToWatch)
	if err != nil {
		log.Fatal(err)
	}

	for {
		select {
		case event := <-watcher.Events:

			log.Println(event.Op)
			if event.Op == fsnotify.Create {
				log.Println("File created...")
				fileext := filepath.Ext(event.Name)
				if isFileTypeAllowed(fileext, allowedExt) {
					pid.Tell(&messages.FileModified{Filepath: event.Name})
				} else {
					log.Printf("Skipping this as, file type %v not allowed", fileext)
				}
			}

		case err := <-watcher.Errors:
			log.Println("error:", err)

		case <-ctx.Done():
			return
		}
	}
}
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0, 'mean_word_length': 3.4186507936507935, 'pattern_counts': {'":': 0, '<': 8, '<?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': '5160106', 'n_tokens_mistral': 917, 'n_tokens_neox': 809, 'n_words': 172}