Skip to content

Commit

Permalink
fix: support symlinks, fixes #858
Browse files Browse the repository at this point in the history
  • Loading branch information
rominf committed Aug 30, 2024
1 parent 1bb307f commit 3aa8f09
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/templ/generatecmd/watcher/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package watcher

import (
"context"
"io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -36,18 +37,24 @@ func Recursive(
// WalkFiles walks the file tree rooted at path, sending a Create event for each
// file it encounters.
func WalkFiles(ctx context.Context, path string, out chan fsnotify.Event) (err error) {
return filepath.WalkDir(path, func(path string, info os.DirEntry, err error) error {
rootPath := path
fileSystem := os.DirFS(rootPath)
return fs.WalkDir(fileSystem, ".", func(path string, info os.DirEntry, err error) error {
if err != nil {
return nil
}
if info.IsDir() && shouldSkipDir(path) {
absPath, err := filepath.Abs(filepath.Join(rootPath, path))
if err != nil {
return nil
}
if info.IsDir() && shouldSkipDir(absPath) {
return filepath.SkipDir
}
if !shouldIncludeFile(path) {
if !shouldIncludeFile(absPath) {
return nil
}
out <- fsnotify.Event{
Name: path,
Name: absPath,
Op: fsnotify.Create,
}
return nil
Expand Down

0 comments on commit 3aa8f09

Please sign in to comment.