From f45391f620d5d2c9a8dfc22395951e06859bcb6c Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Fri, 5 Aug 2022 21:52:45 +0200 Subject: [PATCH] windows: run TestWatchRename/rename_overwriting_existing_file (#490) This Skip() was added in 2013 (c825c6d) with "Windows cannot overwrite file on rename", but it seems to work fine. os.Rename() is also documented as "If newpath already exists and is not a directory, Rename replaces it", so if it *doesn't* work it's a bug in os.Rename(). Maybe os.Rename() behaved different nine years ago. --- inotify.go | 11 ++++++----- integration_test.go | 9 +-------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/inotify.go b/inotify.go index 454e81e..9f33b18 100644 --- a/inotify.go +++ b/inotify.go @@ -241,11 +241,12 @@ func (w *Watcher) readEvents() { // We don't know how many events we just read into the buffer // While the offset points to at least one whole event... for offset <= uint32(n-unix.SizeofInotifyEvent) { - // Point "raw" to the event in the buffer - raw := (*unix.InotifyEvent)(unsafe.Pointer(&buf[offset])) - - mask := uint32(raw.Mask) - nameLen := uint32(raw.Len) + var ( + // Point "raw" to the event in the buffer + raw = (*unix.InotifyEvent)(unsafe.Pointer(&buf[offset])) + mask = uint32(raw.Mask) + nameLen = uint32(raw.Len) + ) if mask&unix.IN_Q_OVERFLOW != 0 { select { diff --git a/integration_test.go b/integration_test.go index 7f833ce..8768fbf 100644 --- a/integration_test.go +++ b/integration_test.go @@ -142,11 +142,6 @@ func TestWatchRename(t *testing.T) { `}, {"rename overwriting existing file", func(t *testing.T, w *Watcher, tmp string) { - switch runtime.GOOS { - case "windows": - t.Skipf("os.Rename over existing file does not create an event on %q", runtime.GOOS) - } - touch(t, tmp, "renamed") addWatch(t, w, tmp) @@ -158,11 +153,9 @@ func TestWatchRename(t *testing.T) { remove /renamed create /renamed - # No remove event for Windows and Linux. + # No remove event for inotify; inotify just sends MOVE_SELF. linux: create /renamed - windows: - create /renamed `}, {"rename watched directory", func(t *testing.T, w *Watcher, tmp string) { -- 2.50.1