Fix creation of parent empty directories when parent is excluded by sync_list (#2245)

* When a parental path is to be excluded, and it is an exact match to be excluded, but further 'included' by a wildcard path match, the parental path exclude needs to take precedence, so that empty local directories are not created when they are mean to be excluded
This commit is contained in:
abraunegg 2022-12-06 06:08:55 +11:00 committed by GitHub
parent 1d8e0204bf
commit 817656ba90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -221,6 +221,7 @@ private bool isPathExcluded(string path, string[] allowedPaths)
{
// function variables
bool exclude = false;
bool exludeDirectMatch = false; // will get updated to true, if there is a pattern match to sync_list entry
bool excludeMatched = false; // will get updated to true, if there is a pattern match to sync_list entry
bool finalResult = true; // will get updated to false, if pattern match to sync_list entry
int offset;
@ -232,8 +233,9 @@ private bool isPathExcluded(string path, string[] allowedPaths)
if (allowedPaths.empty) return false;
path = buildNormalizedPath(path);
log.vdebug("Evaluation against 'sync_list' for this path: ", path);
log.vdebug("[S]exclude = ", exclude);
log.vdebug("[S]excludeMatched = ", excludeMatched);
log.vdebug("[S]exclude = ", exclude);
log.vdebug("[S]exludeDirectMatch = ", exludeDirectMatch);
log.vdebug("[S]excludeMatched = ", excludeMatched);
// unless path is an exact match, entire sync_list entries need to be processed to ensure
// negative matches are also correctly detected
@ -298,9 +300,12 @@ private bool isPathExcluded(string path, string[] allowedPaths)
// direct match, break and go sync
break;
} else {
log.vdebug("Evaluation against 'sync_list' result: direct match but to be excluded");
finalResult = true;
log.vdebug("Evaluation against 'sync_list' result: direct match - path to be excluded");
// do not set excludeMatched = true here, otherwise parental path also gets excluded
// flag exludeDirectMatch so that a 'wildcard match' will not override this exclude
exludeDirectMatch = true;
// final result
finalResult = true;
}
} else {
// no exact path match, but something common does match
@ -357,7 +362,7 @@ private bool isPathExcluded(string path, string[] allowedPaths)
if (matchAll(path, allowedMask)) {
// regex wildcard evaluation matches
// if we have a prior pattern match for an exclude, excludeMatched = true
if (!exclude && !excludeMatched) {
if (!exclude && !excludeMatched && !exludeDirectMatch) {
// nothing triggered an exclusion before evaluation against wildcard match attempt
log.vdebug("Evaluation against 'sync_list' result: wildcard pattern match");
finalResult = false;
@ -370,11 +375,12 @@ private bool isPathExcluded(string path, string[] allowedPaths)
}
}
// Interim results
log.vdebug("[F]exclude = ", exclude);
log.vdebug("[F]excludeMatched = ", excludeMatched);
log.vdebug("[F]exclude = ", exclude);
log.vdebug("[F]exludeDirectMatch = ", exludeDirectMatch);
log.vdebug("[F]excludeMatched = ", excludeMatched);
// If exclude or excludeMatched is true, then finalResult has to be true
if ((exclude) || (excludeMatched)) {
if ((exclude) || (excludeMatched) || (exludeDirectMatch)) {
finalResult = true;
}