This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new c52a787 Simplify adding files to DefaultFileMonitor (#57)
c52a787 is described below
commit c52a787f49dafc1a8bd1e8312370c71410c25a71
Author: Boris Petrov <[email protected]>
AuthorDate: Sun Apr 14 22:15:52 2019 +0300
Simplify adding files to DefaultFileMonitor (#57)
Also fix a test which should work only in recursive mode and add another one
---
.../commons/vfs2/impl/DefaultFileMonitor.java | 21 ---------------------
.../vfs2/impl/test/DefaultFileMonitorTests.java | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 21 deletions(-)
diff --git
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
index daed3ac..e302a75 100644
---
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
+++
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
@@ -157,27 +157,6 @@ public class DefaultFileMonitor implements Runnable,
FileMonitor {
*/
@Override
public void addFile(final FileObject file) {
- doAddFile(file);
- try {
- // add all direct children too
- if (file.getType().hasChildren()) {
- // Traverse the children
- final FileObject[] children = file.getChildren();
- for (final FileObject element : children) {
- doAddFile(element);
- }
- }
- } catch (final FileSystemException fse) {
- LOG.error(fse.getLocalizedMessage(), fse);
- }
- }
-
- /**
- * Adds a file to be monitored.
- *
- * @param file The FileObject to add.
- */
- private void doAddFile(final FileObject file) {
synchronized (this.monitorMap) {
if (this.monitorMap.get(file.getName()) == null) {
this.monitorMap.put(file.getName(), new FileMonitorAgent(this,
file));
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
index fe55b5b..5055292 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileMonitorTests.java
@@ -149,6 +149,7 @@ public class DefaultFileMonitorTests extends
AbstractVfsTestCase {
final FileObject fileObj =
fsManager.resolveFile(testDir.toURI().toURL().toString());
final DefaultFileMonitor monitor = new DefaultFileMonitor(new
TestFileListener());
monitor.setDelay(2000);
+ monitor.setRecursive(true);
monitor.addFile(fileObj);
monitor.start();
try {
@@ -169,6 +170,25 @@ public class DefaultFileMonitorTests extends
AbstractVfsTestCase {
}
}
+ public void testChildFileDeletedWithoutRecursiveChecking() throws
Exception {
+ writeToFile(testFile);
+ final FileObject fileObj =
fsManager.resolveFile(testDir.toURI().toURL().toString());
+ final DefaultFileMonitor monitor = new DefaultFileMonitor(new
TestFileListener());
+ monitor.setDelay(2000);
+ monitor.setRecursive(false);
+ monitor.addFile(fileObj);
+ monitor.start();
+ try {
+ changeStatus = 0;
+ Thread.sleep(300);
+ testFile.delete();
+ Thread.sleep(3000);
+ assertTrue("Event should not have occurred", changeStatus == 0);
+ } finally {
+ monitor.stop();
+ }
+ }
+
public void testFileMonitorRestarted() throws Exception {
final FileObject fileObj =
fsManager.resolveFile(testFile.toURI().toString());
final DefaultFileMonitor monitor = new DefaultFileMonitor(new
TestFileListener());