-
-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
windows: ignore file attribute changes
Windows allows filtering file events to include changes to file attributes. However, when reporting the actual event, attribute changes are included as `FILE_ACTION_MODIFIED` so it's impossible to distinguish from file writes. This means the library's `op::Chmod` is never actually populated on Windows and so attribute changes aren't really usable. Since the API does not support specifying an event type filter as a caller, attribute changes on Windows are ignored rather than being misreported.
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// +build windows | ||
|
||
package fsnotify | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestAttributeChangesIgnored(t *testing.T) { | ||
watcher := newWatcher(t) | ||
defer watcher.Close() | ||
|
||
testDir := tempMkdir(t) | ||
defer os.RemoveAll(testDir) | ||
|
||
// Create a file before watching directory | ||
testFileAlreadyExists := filepath.Join(testDir, "TestFsnotifyEventsExisting.testfile") | ||
{ | ||
var f *os.File | ||
f, err := os.OpenFile(testFileAlreadyExists, os.O_WRONLY|os.O_CREATE, 0666) | ||
if err != nil { | ||
t.Fatalf("creating test file failed: %s", err) | ||
} | ||
f.Sync() | ||
f.Close() | ||
} | ||
|
||
addWatch(t, watcher, testDir) | ||
|
||
// Receive errors on the error channel on a separate goroutine | ||
go func() { | ||
for err := range watcher.Errors { | ||
t.Errorf("error received: %s", err) | ||
} | ||
}() | ||
|
||
var eventReceived counter | ||
go func() { | ||
for event := range watcher.Events { | ||
if event.Name == filepath.Clean(testFileAlreadyExists) { | ||
t.Logf("event received: %s", event) | ||
eventReceived.increment() | ||
} else { | ||
t.Logf("unexpected event received: %s", event) | ||
} | ||
} | ||
}() | ||
|
||
// make the file read-only, which is an attribute change | ||
err := os.Chmod(testFileAlreadyExists, 0400) | ||
if err != nil { | ||
t.Fatalf("Failed to mark file as read-only: %v", err) | ||
} | ||
|
||
// We expect this event to be received almost immediately, but let's wait 500 ms to be sure | ||
time.Sleep(500 * time.Millisecond) | ||
watcher.Close() | ||
|
||
eReceived := eventReceived.value() | ||
if eReceived != 0 { | ||
t.Fatalf("should not have received any events, received %d after 500 ms", eReceived) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters