fsnotify icon indicating copy to clipboard operation
fsnotify copied to clipboard

Notifications when nothing happened after the computer starts or wakes from sleep mode

Open Muddz opened this issue 4 years ago • 3 comments

On a Windows 10 machine I have a Go program which uses fsnotify to watch for changes for a .txt file. When i open the .txt file in notepad without changing anything and closing without saving, fsnotify notifies about a file change. This happens only one time after the Computer has started or returned from sleep-mode

This is how I listen for file change events:

for {
	select {
	case _, ok := <-fw.Events:
		if ok {
			log.Println("File changed")
		}

	case err, _ := <-fw.Errors:
		log.Println("FileWatcher error:", err)
	}
}

Fsnotify registered a change for .txt at : 20:25

The windows properties for .txt shows last changes at: 19:12

Muddz avatar Feb 05 '20 19:02 Muddz

Maybe you should have a try fsutil behavior set disablelastaccess 1.

Have you ever seen the file last access time?

cobolbaby avatar Feb 08 '20 17:02 cobolbaby

@cobolbaby I found a pattern in this issue.

It seems to only happend 1 time after the computer starts or when the computer has been in sleep mode. Do you get me?

Also I have not access to fsutil Yes in the previous thread .txt had last access time at 20:25

Muddz avatar Feb 09 '20 21:02 Muddz

Both FILE_NOTIFY_CHANGE_LAST_ACCESS and FILE_NOTIFY_CHANGE_LAST_WRITE will emit FILE_ACTION_MODIFIED event. I think there should be an option to disable last access time triggering Write op event.

reusee avatar Apr 02 '21 09:04 reusee

I think #520 probably fixed this; I think some program changed file attributes on wakeup, which would show up as Write events because that's how the Windows API sends them or some reason.

Let me know if it's not fixed with that PR and we can look further.

arp242 avatar Oct 15 '22 19:10 arp242