erikzenker / inotify-cpp

A C++ interface for linux inotify
MIT License
136 stars 37 forks source link

not to care about event->name for a file #65

Closed rufuszhou closed 4 years ago

rufuszhou commented 4 years ago

to avoid appending "/" to the file name when watching a file.

erikzenker commented 4 years ago

Can you give me a more detailed description of the issue which is fixed by your PR. Or maybe you can provide a test case.

rufuszhou commented 4 years ago

It is a problem only when watching a file. A "/" is often appended to the file path, like below:

# ./inotify_example /tmp/a.txt

Event modify  on "/tmp/a.txt/" at 276237699902451 was triggered.
Event open  on "/tmp/a.txt" at 276237699960573 was triggered, but was not expected
Event modify  on "/tmp/a.txt/" at 276237700096391 was triggered.
Event close_write  on "/tmp/a.txt" at 276237700100407 was triggered, but was not expected

And sometimes, I saw a unprintable character appended after "/". But sorry, I don't know how to reproduce it now.

I'm working on a OpenSUSE Leap 15.1.

erikzenker commented 4 years ago

Okay, let me try to reproduce it and maybe write a test case for it.

erikzenker commented 4 years ago

I can confirm that there is an issue. I tried to fix it with #66 but some unit tests failed. I am on it.

rufuszhou commented 4 years ago

About your code changes in #66. event->name can be the name of a file, and it is also possible to be of a new folder. So I think one if (fs::is_directory(path)) check is not enough.

erikzenker commented 4 years ago

You are right, I updated the pr. Should be fine now.

erikzenker commented 4 years ago

Fixed with #66 thank you for the contribution!