<commit_before>package importer

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"

	"github.com/DexterLB/mvm/library"
)

// FileImporter takes filenames and constructs video file data
func (c *Context) FileImporter(filenames <-chan string, files chan<- *library.VideoFile) {
	for filename := range filenames {
		relativePath, err := relative(c.Config.FileRoot, filename)
		if err != nil {
			c.Errors <- fmt.Errorf("Invalid filename: %s", err)
		}

		file, err := c.Library.GetFileByPath(relativePath)
		if err != nil {
			c.Errors <- fmt.Errorf("Library error while looking up file: %s", err)
		}

		file.Size, err = filesize(filename)
		if err != nil {
			file.Status.For("file").Errorf("unable to get file size: %s", err)
		}

		file.Status.For("file").Succeed()
		files <- file
	}<commit_msg>correctly use the Stop channel<commit_after>package importer

import (
	"fmt"
	"os"
	"path/filepath"
	"strings"

	"github.com/DexterLB/mvm/library"
)

// FileImporter takes filenames and constructs video file data
func (c *Context) FileImporter(filenames <-chan string, files chan<- *library.VideoFile) {
	for {
		select {
		case filename, ok := <-filenames:
			if !ok {
				return
			}
			relativePath, err := relative(c.Config.FileRoot, filename)
			if err != nil {
				c.Errors <- fmt.Errorf("Invalid filename: %s", err)
			}

			file, err := c.Library.GetFileByPath(relativePath)
			if err != nil {
				c.Errors <- fmt.Errorf("Library error while looking up file: %s", err)
			}

			file.Size, err = filesize(filename)
			if err != nil {
				file.Status.For("file").Errorf("unable to get file size: %s", err)
				continue
			}

			file.Status.For("file").Succeed()
			files <- file
		case <-c.Stop:
			return
		}
	}
{'fraction_non_alphanumeric': 0.1451048951048951, 'fraction_numerical': 0.0, 'mean_word_length': 3.4025641025641025, 'pattern_counts': {'":': 0, '<': 15, '<?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': '7103669', 'n_tokens_mistral': 685, 'n_tokens_neox': 593, 'n_words': 157}