You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add check for 'globbing' and 'wildcard' rules, that the number of segments before the first wildcard character need to match before the actual rule can be applied
* Only calculate ruleSegments and pathSegments once
* Use same calculation method to count path segments for applicability globbing rule as this is more consistent
if (exactMatchRuleSegmentsToPathSegments(ruleSegments, pathSegments)) {
339
349
// EXACT PATH MATCH
340
350
if (debugLogging) {addLogEntry("Exact path match with 'sync_list' rule entry", ["debug"]);}
341
351
@@ -359,19 +369,18 @@ class ClientSideFiltering {
359
369
} else {
360
370
// NOT an EXACT MATCH, so check the very first path segment
361
371
// - This is so that paths in 'sync_list' as specified as /some path/another path/ actually get included|excluded correctly
362
-
if (matchFirstSegmentToPathFirstSegment(syncListRuleEntry, path)) {
372
+
if (matchFirstSegmentToPathFirstSegment(ruleSegments, pathSegments)) {
363
373
// PARENT ROOT MATCH
364
374
if (debugLogging) {addLogEntry("Parent root path match with 'sync_list' rule entry", ["debug"]);}
365
375
366
376
// Does the 'rest' of the input path match?
367
377
// We only need to do this step if the input path has more and 1 segment (the parent folder)
368
-
auto inputSegments = path.strip.split("/").filter!(s =>!s.empty).array;
369
-
if (count(inputSegments) >1) {
378
+
if (count(pathSegments) >1) {
370
379
// More segments to check, so do a parental path match
371
-
if (matchRuleSegmentsToPathSegments(syncListRuleEntry, path)) {
380
+
if (matchRuleSegmentsToPathSegments(ruleSegments, pathSegments)) {
372
381
// PARENTAL PATH MATCH
373
382
if (debugLogging) {addLogEntry("Parental path match with 'sync_list' rule entry", ["debug"]);}
374
-
383
+
// What sort of rule was this?
375
384
if (!thisIsAnExcludeRule) {
376
385
// Include Rule
377
386
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: parental path match", ["debug"]);}
@@ -481,63 +490,78 @@ class ClientSideFiltering {
481
490
}
482
491
483
492
// Does the 'sync_list' rule contain a wildcard (*) or globbing (**) reference anywhere in the rule?
493
+
// EXCLUSION
494
+
// !/Programming/Projects/Android/**/build/*
495
+
// INCLUSION
496
+
// /Programming/Projects/Android/**/build/*
484
497
if (canFind(syncListRuleEntry, wildcard)) {
485
498
// reset the applicable flag
486
499
wildcardRuleMatched = false;
487
-
488
-
// sync_list rule contains some sort of wildcard sequence
489
-
if (thisIsAnExcludeRule) {
490
-
if (debugLogging) {addLogEntry("wildcard (* or **) exclusion rule: !"~ syncListRuleEntry, ["debug"]);}
491
-
} else {
492
-
if (debugLogging) {addLogEntry("wildcard (* or **) inclusion rule: "~ syncListRuleEntry, ["debug"]);}
493
-
}
494
500
495
-
//Is this a globbing rule (**) or just a single wildcard (*) entries
496
-
if (canFind(syncListRuleEntry, globbing)) {
497
-
// globbing (**) rule processing
498
-
if (matchPathAgainstRule(path, syncListRuleEntry)) {
499
-
//set the applicable flag
500
-
wildcardRuleMatched = true;
501
-
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: globbing pattern match", ["debug"]);}
502
-
}
501
+
//Does this 'wildcard' rule even apply to this path?
502
+
auto wildcardDepth = firstWildcardDepth(syncListRuleEntry);
503
+
auto pathSegments = count(path.strip.split("/").filter!(s =>!s.empty).array);
504
+
505
+
//are there enough path segments for this wildcard rule to apply?
506
+
if (pathSegments < wildcardDepth) {
507
+
// there are not enough path segments up to the first wildcard character for this rule to even be applicable
508
+
if (debugLogging) {addLogEntry("- This sync list wildcard rule should not be evaluated as the wildcard appears beyond the current input path", ["debug"]);}
503
509
} else {
504
-
// wildcard (*) rule processing
505
-
// create regex from 'syncListRuleEntry'
506
-
auto allowedMask = regex(createRegexCompatiblePath(syncListRuleEntry));
507
-
if (matchAll(path, allowedMask)) {
508
-
// set the applicable flag
509
-
wildcardRuleMatched = true;
510
-
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard pattern match", ["debug"]);}
510
+
// path segments are enough for this wildcard rule to potentially apply
511
+
// sync_list rule contains some sort of wildcard sequence
512
+
if (thisIsAnExcludeRule) {
513
+
if (debugLogging) {addLogEntry("wildcard (* or **) exclusion rule: !"~ syncListRuleEntry, ["debug"]);}
511
514
} else {
512
-
// matchAll no match ... try another way just to be sure
515
+
if (debugLogging) {addLogEntry("wildcard (* or **) inclusion rule: "~ syncListRuleEntry, ["debug"]);}
516
+
}
517
+
518
+
// Is this a globbing rule (**) or just a single wildcard (*) entries
519
+
if (canFind(syncListRuleEntry, globbing)) {
520
+
// globbing (**) rule processing
513
521
if (matchPathAgainstRule(path, syncListRuleEntry)) {
514
522
// set the applicable flag
515
523
wildcardRuleMatched = true;
516
-
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard pattern match using segment matching", ["debug"]);}
524
+
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: globbing pattern match using segment matching", ["debug"]);}
517
525
}
518
-
}
519
-
}
520
-
521
-
// Was the rule matched?
522
-
if (wildcardRuleMatched) {
523
-
// Is this an exclude rule?
524
-
if (thisIsAnExcludeRule) {
525
-
// Yes exclude rule
526
-
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard|globbing rule matched and must be excluded", ["debug"]);}
527
-
excludeWildcardMatched = true;
528
-
exclude = true;
529
-
finalResult = true;
530
526
} else {
531
-
// include rule
532
-
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard|globbing pattern matched and must be included", ["debug"]);}
533
-
finalResult = false;
534
-
excludeWildcardMatched = false;
527
+
// wildcard (*) rule processing
528
+
// create regex from 'syncListRuleEntry'
529
+
auto allowedMask = regex(createRegexCompatiblePath(syncListRuleEntry));
530
+
if (matchAll(path, allowedMask)) {
531
+
// set the applicable flag
532
+
wildcardRuleMatched = true;
533
+
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard pattern match", ["debug"]);}
534
+
} else {
535
+
// matchAll no match ... try another way just to be sure
536
+
if (matchPathAgainstRule(path, syncListRuleEntry)) {
537
+
// set the applicable flag
538
+
wildcardRuleMatched = true;
539
+
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard pattern match using segment matching", ["debug"]);}
540
+
}
541
+
}
542
+
}
543
+
544
+
// Was the rule matched?
545
+
if (wildcardRuleMatched) {
546
+
// Is this an exclude rule?
547
+
if (thisIsAnExcludeRule) {
548
+
// Yes exclude rule
549
+
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard|globbing rule matched and must be excluded", ["debug"]);}
550
+
excludeWildcardMatched = true;
551
+
exclude = true;
552
+
finalResult = true;
553
+
} else {
554
+
// include rule
555
+
if (debugLogging) {addLogEntry("Evaluation against 'sync_list' rule result: wildcard|globbing pattern matched and must be included", ["debug"]);}
556
+
finalResult = false;
557
+
excludeWildcardMatched = false;
558
+
}
535
559
}
536
560
}
537
561
}
538
562
}
539
563
540
-
564
+
// debug logging post 'sync_list' rule evaluations
0 commit comments