fix for dev file watching missing some file updates due to platform oddities (#1946)

This commit is contained in:
Scott Opell 2022-10-09 05:27:24 -04:00 committed by GitHub
commit eae90df323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -574,7 +574,19 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc
case err := <-watcher.Errors:
LogDarkYellow(err.Error())
case item := <-watcher.Events:
// Check for file writes
isEligibleFile := func(fileName string) bool {
// Iterate all file patterns
ext := filepath.Ext(fileName)
if ext != "" {
ext = ext[1:]
if _, exists := extensionsThatTriggerARebuild[ext]; exists {
return true
}
}
return false
}
// Handle write operations
if item.Op&fsnotify.Write == fsnotify.Write {
// Ignore directories
itemName := item.Name
@ -582,15 +594,10 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc
continue
}
// Iterate all file patterns
ext := filepath.Ext(itemName)
if ext != "" {
ext = ext[1:]
if _, exists := extensionsThatTriggerARebuild[ext]; exists {
rebuild = true
timer.Reset(interval)
continue
}
if isEligibleFile(itemName) {
rebuild = true
timer.Reset(interval)
continue
}
for _, reloadDir := range dirsThatTriggerAReload {
@ -606,7 +613,8 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc
timer.Reset(interval)
}
// Check for new directories
// Handle new fs entries that are created
if item.Op&fsnotify.Create == fsnotify.Create {
// If this is a folder, add it to our watch list
if fs.DirExists(item.Name) {
@ -618,6 +626,14 @@ func doWatcherLoop(buildOptions *build.Options, debugBinaryProcess *process.Proc
}
LogGreen("Added new directory to watcher: %s", item.Name)
}
} else if isEligibleFile(item.Name) {
// Handle creation of new file.
// Note: On some platforms an update to a file is represented as
// REMOVE -> CREATE instead of WRITE, so this is not only new files
// but also updates to existing files
rebuild = true
timer.Reset(interval)
continue
}
}
case <-timer.C: