Repository: fsnotify/fsnotify
Pull request #461 (2022-07-21 03:09:42)

bump up GitHub Actions
#### What does this pull request do?

- bump actions/setup-go from v2 to v3
- bump actions/checkout from v2 to v3
- bump vmactions/freebsd-vm from v0.1.5 to v0.2.0

#### Where should the reviewer start?


#### How should this be manually tested?

See the results of GitHub Actions

arp242: I think the CI failed due to #454; I see now that the CI didn't run on that one for some reason (didn't notice when I merged it). The problem is probably a "nested" lock.
arp242: Can you rebase?
shogo82148: OK. I did.

Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 80f3a06..b595c7e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -20,12 +20,12 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: setup Go
-        uses: actions/setup-go@v2
+        uses: actions/setup-go@v3
         with:
           go-version: '1.18'
 
       - name: checkout
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       - name: build-${{ matrix.goos }}-${{ matrix.goarch }}
         run: |
diff --git a/inotify.go b/inotify.go
index e6abddf..9e020ed 100644
--- a/inotify.go
+++ b/inotify.go
@@ -317,12 +317,12 @@ func (e *Event) ignoreLinux(mask uint32) bool {
 		return true
 	}
 
-	// If the event is not a DELETE or RENAME, the file must exist.
-	// Otherwise the event is ignored.
-	// *Note*: this was put in place because it was seen that a MODIFY
-	// event was sent after the DELETE. This ignores that MODIFY and
-	// assumes a DELETE will come or has come if the file doesn't exist.
-	if !(e.Op&Remove == Remove || e.Op&Rename == Rename) {
+	// If the event is Create or Write, the file must exist, or the
+	// event will be suppressed.
+	// *Note*: this was put in place because it was seen that a Write
+	// event was sent after the Remove. This ignores the Write and
+	// assumes a Remove will come or has come if the file doesn't exist.
+	if e.Op&Create == Create || e.Op&Write == Write {
 		_, statErr := os.Lstat(e.Name)
 		return os.IsNotExist(statErr)
 	}


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 28666d2..94cc2c3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -18,13 +18,12 @@ jobs:
     runs-on: ${{ matrix.os }}
     steps:
       - name: setup Go
-        uses: actions/setup-go@v2
+        uses: actions/setup-go@v3
         with:
-          stable: 'false'
           go-version: ${{ matrix.go }}
 
       - name: checkout
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       - name: test
         run: |
@@ -34,10 +33,10 @@ jobs:
     runs-on: macos-10.15
     name: test (freebsd, 1.18)
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: test (freebsd, 1.18)
         id: test
-        uses: vmactions/freebsd-vm@v0.1.5
+        uses: vmactions/freebsd-vm@v0.2.0
         with:
           usesh: true
           prepare: pkg install -y go
@@ -48,12 +47,12 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: setup Go
-        uses: actions/setup-go@v2
+        uses: actions/setup-go@v3
         with:
-          go-version: '1.17'
+          go-version: '1.18'
 
       - name: checkout
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       - name: gofmt
         run: |
@@ -64,7 +63,7 @@ jobs:
           go vet ./...
 
       - name: golangci-lint
-        uses: golangci/golangci-lint-action@v2
+        uses: golangci/golangci-lint-action@v3
         continue-on-error: true
         with:
           version: latest
diff --git a/inotify_test.go b/inotify_test.go
index 728f5c2..361f198 100644
--- a/inotify_test.go
+++ b/inotify_test.go
@@ -499,3 +499,52 @@ func TestInotifyWatchList(t *testing.T) {
 		}
 	}
 }
+
+func TestInotifyDeleteOpenedFile(t *testing.T) {
+	testDir := tempMkdir(t)
+	defer os.RemoveAll(testDir)
+
+	testFile := filepath.Join(testDir, "testfile")
+
+	// create and open a file
+	fd, err := os.Create(testFile)
+	if err != nil {
+		t.Fatalf("Create failed: %v", err)
+	}
+	defer fd.Close()
+
+	w, err := NewWatcher()
+	if err != nil {
+		t.Fatalf("Failed to create watcher: %v", err)
+	}
+	defer w.Close()
+
+	err = w.Add(testFile)
+	if err != nil {
+		t.Fatalf("Failed to add watch for %s: %v", testFile, err)
+	}
+
+	checkEvent := func(exp Op) {
+		select {
+		case event := <-w.Events:
+			t.Logf("Event received: %s", event.Op)
+			if event.Op != exp {
+				t.Fatalf("Event expected: %s, got: %s", exp, event.Op)
+			}
+		case <-time.After(100 * time.Millisecond):
+			t.Fatalf("Expected %s event not received", exp)
+		}
+	}
+
+	// Remove the (opened) file, check Chmod event (notifying
+	// about file link count change) is received
+	err = os.Remove(testFile)
+	if err != nil {
+		t.Fatalf("Failed to remove file: %s", err)
+	}
+	checkEvent(Chmod)
+
+	// Close the file, check Remove event is received
+	fd.Close()
+	checkEvent(Remove)
+}