@@ -47,6 +47,7 @@ public class DataFileWatcher implements FileFilter, FileListener
4747 final Pattern dirNamePattern ;
4848 final Pattern fileNamePattern ;
4949 final String latestPointerFileName ;
50+ final boolean findDirOnly ;
5051 final FileListener listener ;
5152 final Logger logger ;
5253 DirectoryWatcher watcher ;
@@ -69,7 +70,13 @@ public DataFileWatcher(String dataSrcName, String baseDir, String dirNamePattern
6970 {
7071 this .dataSrcName = Asserts .checkNotNullOrBlank (dataSrcName , "dataSrcName" );
7172 this .baseDir = Asserts .checkNotNullOrBlank (baseDir , "baseDir" );
72- this .fileNamePattern = Pattern .compile (Asserts .checkNotNullOrBlank (fileNamePattern , "fileNamePattern" ));
73+ if (fileNamePattern == null ) {
74+ this .fileNamePattern = null ;
75+ this .findDirOnly = true ;
76+ } else {
77+ this .fileNamePattern = Pattern .compile (Asserts .checkNotNullOrBlank (fileNamePattern , "fileNamePattern" ));
78+ this .findDirOnly = false ;
79+ }
7380 this .dirNamePattern = dirNamePattern != null ? Pattern .compile (dirNamePattern ) : null ;
7481 this .latestPointerFileName = latestPointerFileName ;
7582 this .listener = listener ;
@@ -150,7 +157,7 @@ File readPathOfLatestDataFile(File parentDir)
150157 return null ;
151158
152159 var latestDataFile = new File (latestDataFilePath );
153- if (latestDataFile .isDirectory ()) {
160+ if (latestDataFile .isDirectory () && ! findDirOnly ) {
154161 logger .info ("Latest data directory is {}" , latestDataFilePath );
155162 return findLatestDataFile (latestDataFile );
156163 }
@@ -187,7 +194,7 @@ File findLatestDataFile(File parentDir)
187194 }
188195
189196 // if it's a directory, look inside
190- if (latestFile .isDirectory ())
197+ if (latestFile .isDirectory () && ! findDirOnly )
191198 return findLatestDataFile (latestFile );
192199 else
193200 return latestFile ;
@@ -197,7 +204,7 @@ File findLatestDataFile(File parentDir)
197204 @ Override
198205 public boolean accept (File f )
199206 {
200- if (f .isFile () && fileNamePattern .matcher (f .getName ()).matches ())
207+ if (f .isFile () && ! findDirOnly && fileNamePattern .matcher (f .getName ()).matches ())
201208 return true ;
202209
203210 if (f .isDirectory () && dirNamePattern != null && dirNamePattern .matcher (f .getName ()).matches ())
0 commit comments