nano and echo behave different at inotify

130 views Asked by At

I did a small test sw in go and inotify. It detects file modifications.

If I do the textfile modification with nano, I get two modification detections, If I do it wit echo I get only one modification detection. I think this is caused by nano editor.

echo 1 >> /sw/config.yml

nano /sw/config.yml

Does anybody has a explanation ?

Code

package main

import (
    "fmt"
    "log"

    "github.com/fsnotify/fsnotify"
)

func inotwatcher(watcher *fsnotify.Watcher) {

    for {
        select {
        case event := <-watcher.Events:
            // monitor only for write events
            if event.Op&fsnotify.Write == fsnotify.Write {
                fmt.Println("Modified file:", event.Name)
            }
        case err := <-watcher.Errors:
            log.Println("Error:", err)
        }
    }
}

func main() {
    // setup inotify watcher
    watcher, _ := fsnotify.NewWatcher()
    defer watcher.Close()
    //done := make(chan bool)

    go inotwatcher(watcher)
    watcher.Add("/busa/config.yml")
    for {
    }

}

0

There are 0 answers