[#5789] updated the hooks watcher to account for the case when hooksDir is a symlink
This commit is contained in:
parent
1025fb2406
commit
c3557d4e94
|
@ -343,13 +343,23 @@ func (p *plugin) normalizeServeExceptions(e *core.RequestEvent) error {
|
||||||
//
|
//
|
||||||
// This method does nothing if the hooks directory is missing.
|
// This method does nothing if the hooks directory is missing.
|
||||||
func (p *plugin) watchHooks() error {
|
func (p *plugin) watchHooks() error {
|
||||||
if _, err := os.Stat(p.config.HooksDir); err != nil {
|
watchDir := p.config.HooksDir
|
||||||
|
|
||||||
|
hooksDirInfo, err := os.Lstat(p.config.HooksDir)
|
||||||
|
if err != nil {
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return nil // no hooks dir to watch
|
return nil // no hooks dir to watch
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hooksDirInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||||
|
watchDir, err = filepath.EvalSymlinks(p.config.HooksDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -408,9 +418,9 @@ func (p *plugin) watchHooks() error {
|
||||||
// add directories to watch
|
// add directories to watch
|
||||||
//
|
//
|
||||||
// @todo replace once recursive watcher is added (https://github.com/fsnotify/fsnotify/issues/18)
|
// @todo replace once recursive watcher is added (https://github.com/fsnotify/fsnotify/issues/18)
|
||||||
dirsErr := filepath.Walk(p.config.HooksDir, func(path string, info fs.FileInfo, err error) error {
|
dirsErr := filepath.WalkDir(watchDir, func(path string, entry fs.DirEntry, err error) error {
|
||||||
// ignore hidden directories and node_modules
|
// ignore hidden directories, node_modules, symlinks, sockets, etc.
|
||||||
if !info.IsDir() || info.Name() == "node_modules" || strings.HasPrefix(info.Name(), ".") {
|
if !entry.IsDir() || entry.Name() == "node_modules" || strings.HasPrefix(entry.Name(), ".") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue