diff --git a/daemon/daemon.go b/daemon/daemon.go index d292d1ae..9517ad45 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -3,9 +3,9 @@ package daemon import ( "bufio" "fmt" + "github.com/no-src/gofs/util" "github.com/no-src/log" "os" - "runtime" "time" ) @@ -37,7 +37,7 @@ func startSubprocess() (*os.Process, error) { attr := &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}} // try to check stdin // if compile with [-ldflags="-H windowsgui"] on Windows system, stdin will get error - if isWindows() { + if util.IsWindows() { _, stdInErr := os.Stdin.Stat() if stdInErr != nil { attr = &os.ProcAttr{Files: []*os.File{nil, nil, nil}} @@ -111,10 +111,6 @@ func writePidFile(ppid, pid, subPid int) error { return err } -func isWindows() bool { - return runtime.GOOS == "windows" -} - // KillPPid kill parent process func KillPPid() { ppid := os.Getppid() diff --git a/monitor/fsnotify_monitor.go b/monitor/fsnotify_monitor.go index 623b9f87..6902919b 100644 --- a/monitor/fsnotify_monitor.go +++ b/monitor/fsnotify_monitor.go @@ -6,6 +6,7 @@ import ( "github.com/no-src/gofs/core" "github.com/no-src/gofs/retry" "github.com/no-src/gofs/sync" + "github.com/no-src/gofs/util" "github.com/no-src/log" "io/fs" "path/filepath" @@ -139,8 +140,9 @@ func (m *fsNotifyMonitor) processEvents() error { log.Error(err, "Create event execute monitor error => [%s]", event.Name) } } - if err == nil && !isDir { - // rename a file, will not trigger Write event + if err == nil && (!isDir || (isDir && !util.IsWindows())) { + // rename a file, will not trigger the Write event + // rename a dir, will not trigger the Write event on Linux, but it will trigger the Write event for parent dir on Windows // send a Write event manually go func() { log.Debug("prepare to send a Write event after Create event [%s]", event.Name) diff --git a/util/os.go b/util/os.go new file mode 100644 index 00000000..3c82e0d7 --- /dev/null +++ b/util/os.go @@ -0,0 +1,7 @@ +package util + +import "runtime" + +func IsWindows() bool { + return runtime.GOOS == "windows" +}