Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DA-992: Pair windows' delete + create event to generate a rename event #1

Merged
merged 21 commits into from
Jul 14, 2021

Conversation

parzed
Copy link

@parzed parzed commented Jan 17, 2020

Jira: DA-992

For each rename action on a file, two syscall event is generated:
1- FILE_ACTION_RENAMED_OLD_NAME and
2- FILE_ACTION_RENAMED_NEW_NAME.

Here I assumed that the first one is followed by the second one.
Then one fsnorify RENAME event is generated.
RENAME event has the file's oldName set up.

the OldName attribute is added to the Event struct of fsnotify.
The system call of FILE_ACTION_RENAMED_OLD_NAME holds the file's old name. Upon receiving this syscall event, watcher.rename is set up with the file's old name which serves as a state variable. No fsnotify event is created.

The system call of FILE_ACTION_RENAMED_NEW_NAME holds the file's new name. A RENAME fsnotify event is created with file's old name, watcher.rename, as OldName attribute .

Cases:
receive FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has a value, perfect case, a RENAME event is generated.

receive any syscall rather than FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has a value, first a RENAME event is created with empty name and the OldName is watcher.rename value, then the syscall event is handled.

receive FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has no value, a RENAME event is generated with an empty oldName.

Tests:
in imtegration_test.go

TestFsnotifyMultipleRenames():
generates 1000 rename action and checks if the RENAME attribute is set up correctly and all of the events are received.

TestFsnotifyRenameEventAttributes():
Checks if the OldName attribute is set up correctly for a rename event

@parzed parzed requested review from hu13 and ianyh January 17, 2020 21:47
@hu13
Copy link

hu13 commented Jan 20, 2020

receive any syscall rather than FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has a value, first a RENAME event is created with empty name and the OldName is watcher.rename value, then the syscall event is handled.

receive FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has no value, a RENAME event is generated with an empty oldName.

In these imperfect cases, how would drive handle it?
how can these cases happen? on what frequency?

@parzed
Copy link
Author

parzed commented Jan 21, 2020

receive any syscall rather than FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has a value, first a RENAME event is created with empty name and the OldName is watcher.rename value, then the syscall event is handled.

receive FILE_ACTION_RENAMED_NEW_NAME and watcher.rename has no value, a RENAME event is generated with an empty oldName.

In these imperfect cases, how would drive handle it?
This is up to the server I think.
The Mac watcher (the one that has buffer), if it has a rename event of 'old name' or 'new name' and can not find its match in the buffer it creates an event based on the case. it creates a DELETE event for the old name case and CREATE event for the new name case. I think differentiating a faulty rename case from actual CREATE and DELETE is not a bad idea.
Anyways, in such a cases server can consider these approach or discarding the events.

how can these cases happen? on what frequency?
I have not seen any statistics for that and did not encounter the case in the tests. I can do a search to see in what cases it can happen. I considered them in case of system failures.

Copy link

@ianyh ianyh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just stylistic comments I already had, but holding off on the rest of the review as we discussed.

fsnotify.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
@ianyh ianyh changed the title Da 992/window rename event Window rename event Apr 8, 2020
@ianyh ianyh self-requested a review April 8, 2020 19:16
@ianyh ianyh changed the title Window rename event DA-992: Window rename event Apr 9, 2020
Copy link

@hu13 hu13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some stylist comments.
I still want to discuss the main logic interactively since I don't fully understand some of it.

fsnotify.go Outdated Show resolved Hide resolved
fsnotify_test.go Outdated Show resolved Hide resolved
integration_test.go Show resolved Hide resolved
integration_test.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
fsnotify_test.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
integration_test.go Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
@@ -468,47 +476,57 @@ func (w *Watcher) readEvents() {

name := syscall.UTF16ToString(buf)
fullname := filepath.Join(watch.path, name)

var mask uint64
switch raw.Action {
case syscall.FILE_ACTION_REMOVED:
mask = sysFSDELETESELF
case syscall.FILE_ACTION_MODIFIED:
mask = sysFSMODIFY
case syscall.FILE_ACTION_RENAMED_OLD_NAME:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like in this case you don't set mask.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I guess this is just relying on the variable initializing by default to 0 so the ands do the right thing.

windows.go Outdated Show resolved Hide resolved
windows.go Outdated Show resolved Hide resolved
windows.go Outdated
if watch.rename != "" {
if w.sendEvent("", watch.names[name]&mask, watch.rename) {
if watch.names[name]&sysFSONESHOT != 0 {
delete(watch.names, name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to return in this case? Otherwise we send two events.

@hu13 hu13 changed the title DA-992: Window rename event DA-992: Pair windows' delete + create event to generate a rename event Jun 9, 2021
hu13 and others added 3 commits June 9, 2021 16:01
* Let's begin

* Add getpath

* Init test workflow

* 1.40.0 exits?

* Linter fix

* asdf

* 100

Co-authored-by: hu13 <hangkun@preveil.com>
@hu13 hu13 requested a review from ianyh June 9, 2021 20:12
@hu13 hu13 merged commit 580c3c9 into preveil Jul 14, 2021
hu13 added a commit that referenced this pull request Jan 18, 2022
#1)

* made the changes related to recursive directory check

* made changes in window.go for buffer size

* added the oldname attribute

* old name added to rename event, one event is generated for rename

* added oldname in printing rename events

* tests for checking  the oldName attr for rename added

* create fsnotify event added

* input to create event changed

* create fsnotify event function modified

* ID added

* logs added

* added create fsnotify event in inotify

* logs added

* prints added

* reviews

* reviews addressed

* Hangkun/da 992/window rename event (#2)

* Let's begin

* Add getpath

* Init test workflow

* 1.40.0 exits?

* Linter fix

* asdf

* 100

Co-authored-by: hu13 <hangkun@preveil.com>

* Clean up unused

* Badge

Co-authored-by: Hangkun Ung <hangkun.ung@gmail.com>
Co-authored-by: hu13 <hangkun@preveil.com>
ianyh pushed a commit that referenced this pull request Jan 19, 2022
* introduce GitHub Actions

* Add lint+vet+old versions to GitHub Action

* Remove Travis CI and references

* Drop support/testing for Go 1.11 and earlier (fsnotify#381)

* Update x/sys to latest (fsnotify#379)

* add //go:build lines + add 1.17.0-rc2 to test matrix (fsnotify#377)

* Update test matrix for go 1.17 stable release (fsnotify#385)

* Add AddRaw to not follow symlinks + Fix link folloing on Windows (fsnotify#289)

* v1.5.0 preparation (fsnotify#380)

* revise pull request template

* Revert "Add AddRaw to not follow symlinks + Fix link folloing on Windows (fsnotify#289)"

This reverts commit e2e9517.

* prepare 1.5.1, retract 1.5.0

* Removed dead link

* Update issue templates (fsnotify#410)

* Update issue templates

* remove old issue template

* Test on Go 1.18 and two most recent versions (fsnotify#411)

* Test on Go 1.18 and two most recent versions

* on push

* ci

* update readme

* revise contributing

* maintainers wanted

* Final Notice: Maintainers Wanted

* fix go vet warnings: call to (*T).Fatalf from a non-test goroutine (fsnotify#416)

* made the changes related to recursive directory check

* made changes in window.go for buffer size

* DA-992: Pair windows' delete + create event to generate a rename event (#1)

* made the changes related to recursive directory check

* made changes in window.go for buffer size

* added the oldname attribute

* old name added to rename event, one event is generated for rename

* added oldname in printing rename events

* tests for checking  the oldName attr for rename added

* create fsnotify event added

* input to create event changed

* create fsnotify event function modified

* ID added

* logs added

* added create fsnotify event in inotify

* logs added

* prints added

* reviews

* reviews addressed

* Hangkun/da 992/window rename event (#2)

* Let's begin

* Add getpath

* Init test workflow

* 1.40.0 exits?

* Linter fix

* asdf

* 100

Co-authored-by: hu13 <hangkun@preveil.com>

* Clean up unused

* Badge

Co-authored-by: Hangkun Ung <hangkun.ung@gmail.com>
Co-authored-by: hu13 <hangkun@preveil.com>

* Rebase upstream fixes

* Rename bundle only works on windows

* Update CI golang

Co-authored-by: Ichinose Shogo <shogo82148@gmail.com>
Co-authored-by: Oliver Bristow <evilumbrella+github@gmail.com>
Co-authored-by: Nahum Shalman <nahamu@gmail.com>
Co-authored-by: Nathan Youngman <4566+nathany@users.noreply.github.com>
Co-authored-by: Loïc Vernet <vernet.loic@gmail.com>
Co-authored-by: Nathan Youngman <git@nathany.com>
Co-authored-by: paris <pariya.b@gmail.com>
Co-authored-by: hu13 <hangkun@preveil.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants