@@ -28,8 +28,12 @@ public class JsyncEngine {
2828 private boolean skipPermissions ;
2929 private int maxFilesMaybeModifiedLimit ;
3030 private List <String > excludes ;
31+ private List <String > ignores ;
3132 // when running a sync
3233 private Checksum negotiatedChecksum ;
34+ private List <VirtualPath > excludePaths ;
35+ private List <VirtualPath > ignoreSourcePaths ;
36+ private List <VirtualPath > ignoreTargetPaths ;
3337
3438 public JsyncEngine () {
3539 this .eventHandler = new DefaultJsyncEventHandler ();
@@ -40,7 +44,6 @@ public JsyncEngine() {
4044 this .skipPermissions = false ;
4145 this .preferredChecksums = new ArrayList <>(asList (Checksum .CK , Checksum .MD5 ));
4246 this .maxFilesMaybeModifiedLimit = 256 ;
43- this .excludes = null ;
4447 }
4548
4649 public JsyncEventHandler getEventHandler () {
@@ -134,6 +137,23 @@ public JsyncEngine addExclude(String exclude) {
134137 return this ;
135138 }
136139
140+ public List <String > getIgnores () {
141+ return ignores ;
142+ }
143+
144+ public JsyncEngine setIgnores (List <String > ignores ) {
145+ this .ignores = ignores ;
146+ return this ;
147+ }
148+
149+ public JsyncEngine addIgnore (String ignore ) {
150+ if (this .ignores == null ) {
151+ this .ignores = new ArrayList <>();
152+ }
153+ this .ignores .add (ignore );
154+ return this ;
155+ }
156+
137157 public JsyncResult sync (Path sourcePath , Path targetPath , JsyncMode mode ) throws IOException {
138158 // local -> local
139159 final LocalVirtualFileSystem localVfs = LocalVirtualFileSystem .open ();
@@ -213,6 +233,30 @@ public JsyncResult sync(VirtualFileSystem sourceVfs, String sourcePath, VirtualF
213233 // find the best common checksum
214234 this .negotiatedChecksum = this .negotiateChecksum (sourceVfs , targetVfs );
215235
236+ // build exclude and ignore paths
237+ if (this .excludes != null ) {
238+ this .excludePaths = this .excludes .stream ()
239+ .map (VirtualPath ::parse )
240+ .map (sourcePathAbsFinal ::resolve )
241+ .collect (toList ());
242+ } else {
243+ this .excludePaths = Collections .emptyList ();
244+ }
245+
246+ if (this .ignores != null ) {
247+ this .ignoreSourcePaths = this .ignores .stream ()
248+ .map (VirtualPath ::parse )
249+ .map (sourcePathAbsFinal ::resolve )
250+ .collect (toList ());
251+ this .ignoreTargetPaths = this .ignores .stream ()
252+ .map (VirtualPath ::parse )
253+ .map (targetPathAbsFinal ::resolve )
254+ .collect (toList ());
255+ } else {
256+ this .ignoreSourcePaths = Collections .emptyList ();
257+ this .ignoreTargetPaths = Collections .emptyList ();
258+ }
259+
216260
217261 final long now = System .currentTimeMillis ();
218262
@@ -239,7 +283,7 @@ public JsyncResult sync(VirtualFileSystem sourceVfs, String sourcePath, VirtualF
239283 // as we process files, only a subset may require more advanced methods of detecting whether they were modified
240284 // since that process could be "expensive", we keep a list of files on source/target that we will defer processing
241285 // until we have a chance to do some bulk processing of checksums, etc.
242- this .syncDirectory (0 , result , excludePaths , deferredFiles , sourceVfs , sourcePathAbsFinal , targetVfs , targetPathAbsFinal );
286+ this .syncDirectory (0 , result , deferredFiles , sourceVfs , sourcePathAbsFinal , targetVfs , targetPathAbsFinal );
243287 } else {
244288 // we are only syncing a file, we may need to do some more expensive checks to determine if it needs to be updated
245289 this .syncFile (result , deferredFiles , sourceVfs , sourcePathAbsFinal , targetVfs , targetPathAbsFinal );
@@ -322,7 +366,7 @@ protected void syncDeferredFiles(JsyncResult result, List<VirtualPathPair> defer
322366 deferredFiles .clear ();
323367 }
324368
325- protected void syncDirectory (int level , JsyncResult result , List <VirtualPath > excludePaths , List < VirtualPathPair > deferredFiles , VirtualFileSystem sourceVfs , VirtualPath sourcePath , VirtualFileSystem targetVfs , VirtualPath targetPath ) throws IOException {
369+ protected void syncDirectory (int level , JsyncResult result , List <VirtualPathPair > deferredFiles , VirtualFileSystem sourceVfs , VirtualPath sourcePath , VirtualFileSystem targetVfs , VirtualPath targetPath ) throws IOException {
326370
327371 // source needs to be a directory
328372 if (!sourcePath .isDirectory ()) {
@@ -365,15 +409,23 @@ protected void syncDirectory(int level, JsyncResult result, List<VirtualPath> ex
365409 List <VirtualPath > sourceChildPaths = sourceVfs .ls (sourcePath ).stream ()
366410 // apply filter to source files if they are on the exclude list
367411 .filter (v -> {
368- //log.info("Checking for exlcude of path {} with excludes {}", v, excludePaths);
369- for (VirtualPath excludePath : excludePaths ) {
370- if (v .startsWith (excludePath )) {
412+ for (VirtualPath p : this .excludePaths ) {
413+ if (v .startsWith (p )) {
371414 this .eventHandler .willExcludePath (v );
372415 return false ;
373416 }
374417 }
375418 return true ;
376419 })
420+ .filter (v -> {
421+ for (VirtualPath p : this .ignoreSourcePaths ) {
422+ if (v .startsWith (p )) {
423+ this .eventHandler .willIgnorePath (v );
424+ return false ;
425+ }
426+ }
427+ return true ;
428+ })
377429 // apply filter to excluding non-regular files (such as symlinks)
378430 .filter (v -> {
379431 switch (v .getStat ().getType ()) {
@@ -389,7 +441,16 @@ protected void syncDirectory(int level, JsyncResult result, List<VirtualPath> ex
389441 })
390442 .collect (toList ());
391443
392- final List <VirtualPath > targetChildPaths = targetVfs .ls (targetPath );
444+ final List <VirtualPath > targetChildPaths = targetVfs .ls (targetPath ).stream ()
445+ .filter (v -> {
446+ for (VirtualPath p : this .ignoreTargetPaths ) {
447+ if (v .startsWith (p )) {
448+ return false ;
449+ }
450+ }
451+ return true ;
452+ })
453+ .collect (toList ());
393454
394455 // its better to work with all dirs first, then files, so we sort the files before we process them
395456 this .sortPaths (sourceChildPaths );
@@ -411,7 +472,7 @@ protected void syncDirectory(int level, JsyncResult result, List<VirtualPath> ex
411472 }
412473
413474 if (sourceChildPath .isDirectory ()) {
414- this .syncDirectory (level +1 , result , excludePaths , deferredFiles , sourceVfs , sourceChildPath , targetVfs , targetChildPath );
475+ this .syncDirectory (level +1 , result , deferredFiles , sourceVfs , sourceChildPath , targetVfs , targetChildPath );
415476 } else {
416477 // NOTE: it's possible syncFile will "defer" processing if a checksum is required
417478 this .syncFile (result , deferredFiles , sourceVfs , sourceChildPath , targetVfs , targetChildPath );
0 commit comments