45 lines
698 B
Go
45 lines
698 B
Go
package watcher
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/fsnotify/fsnotify"
|
|
)
|
|
|
|
func simulateInitialCreates(dirName string, eventChan chan<- fsnotify.Event) error {
|
|
dir, err := os.ReadDir(dirName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, file := range dir {
|
|
eventChan <- fsnotify.Event{
|
|
Name: filepath.Join(dirName, file.Name()),
|
|
Op: fsnotify.Create,
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func sliceToMap[T comparable](sl []T) map[T]interface{} {
|
|
m := make(map[T]interface{})
|
|
|
|
for _, k := range sl {
|
|
m[k] = nil
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func hasSlicePrefix(s string, sl []string) bool {
|
|
for _, prefix := range sl {
|
|
if strings.HasPrefix(s, prefix) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|