<commit_before>package reload

import (
	"io/fs"
	"os"
)

type FS struct {
	embed fs.FS
	dir   fs.FS
}

func NewFS(embed fs.ReadDirFS, dir string) FS {
	return FS{
		embed: embed,
		dir:   os.DirFS(dir),
	}
}

func (f FS) Open(name string) (fs.File, error) {
	if name == "embed.go" {
		return nil, fs.ErrNotExist
	}
	cfgFile := "./.buffalo.dev.yml"
	if _, err := os.Stat(cfgFile); err != nil {
		return f.embed.Open(name)
	}
	return f.dir.Open(name)
}<commit_msg>Improved hiding of embed.go<commit_after>package reload

import (
	"fmt"
	"io/fs"
	"os"
)

type FS struct {
	embed fs.FS
	dir   fs.FS
}

func NewFS(embed fs.ReadDirFS, dir string) FS {
	return FS{
		embed: embed,
		dir:   os.DirFS(dir),
	}
}

func (f FS) Open(name string) (fs.File, error) {
	if name == "embed.go" {
		return nil, fs.ErrNotExist
	}
	file, err := f.getFile(name)
	if name != "." {
		return file, err
	}
	return rootFile{file}, err
}

func (f FS) getFile(name string) (fs.File, error) {
	cfgFile := "./.buffalo.dev.yml"
	if _, err := os.Stat(cfgFile); err != nil {
		return f.embed.Open(name)
	}
	return f.dir.Open(name)
}

type rootFile struct {
	fs.File
}

func (f rootFile) ReadDir(n int) ([]fs.DirEntry, error) {
	dir, ok := f.File.(fs.ReadDirFile)
	if !ok {
		return nil, fmt.Errorf("failed at hiding embed.go file")
	}
	entries, err := dir.ReadDir(n)
	if err != nil {
		return entries, err
	}

	for i, entry := range entries {
		if entry.Name() == "embed.go" {
			entries = append(entries[:i], entries[i+1:]...)
		}
	}
	return entries, nil
}
{'fraction_non_alphanumeric': 0.1678688524590164, 'fraction_numerical': 0.0006557377049180328, 'mean_word_length': 3.180821917808219, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1489549', 'n_tokens_mistral': 665, 'n_tokens_neox': 631, 'n_words': 164}