Skip to content

GH-8659: Fix the WatchServiceDirectoryScanner to detect new file afte… #8662

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

Merged
merged 5 commits into from
Jun 29, 2023

Conversation

pziobron
Copy link
Contributor

Fix the WatchServiceDirectoryScanner to detect new file after renaming the sub-folder of the watched folder (Java 7 WatchService)

…t new file after renaming the sub-folder of the watched folder (Java 7 WatchService)
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

All looks good, however I would like to suggest some change to the file.adoc.
Go to the [[watch-service-directory-scanner]] section and explain there in the end that we need to track also WatchEventType.MODIFY and WatchEventType.DELETE event types if sub-directories can be renamed.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

The test has failed, probably due to your change:

WatchServiceDirectoryScannerTests > testWatchServiceDirectoryScanner() FAILED
    java.lang.AssertionError at WatchServiceDirectoryScannerTests.java:220

Please, revise.

@pziobron
Copy link
Contributor Author

pziobron commented Jun 28, 2023

The fix seems to solve the problem on Windows - the files are detected properly in the sub-folder (of the watched folder) after renaming it.
I've tried to write a test for this scenario but it is hard to emulate it in Java (creating empty folder in File Explorer and renaming it). I am not sure if that's even possible.
I will experiment with that a bit :)

I will update documentation tomorrow...

@pziobron
Copy link
Contributor Author

I've tried to replicate the issue in Java in order to write the Integration test which covers that issue.
Unfortunately, I haven't managed to do that.
I've been using:

  1. File.mkdir()
  2. File.renameTo(...)/Files.move(...)
  3. File.createTempFile(...)

with no success - the file in sub-directory is detected properly.

The issue can be replicated in Windows with the File Explorer or with the Command Line by using the following commands:

  1. md test1
  2. move test1 test2
  3. copy someFile test2

Theoretically, the Runtime.getRuntime().exec(...) could be used for the integration test but it would work obviously only for Windows (or for all Os'es when mapping md -> mkdir, copy -> cp etc....).
Nevertheless, I am not sure if that is a good idea (this could be tricky) ?

I've updated the documentation as You requested.

@artembilan artembilan merged commit 0798c8d into spring-projects:main Jun 29, 2023
@artembilan
Copy link
Member

... and cherry-picked to 6.1.x, 6.0.x & 5.5.x.

@pziobron ,

thank you for contribution; looking forward for more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants