From 3d5957986ab61c5960c1497cadc5f17e5cf8f037 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Fri, 9 Apr 2021 08:18:00 +1000 Subject: [PATCH] Fix 'sync_list' handling of inclusions when name is included in another folders name (#1390) * Fix 'sync_list' handling of inclusions when name is included in another folders name to avoid creating empty parental root folders. When a 'sync_list' entry ends with '/*' the common path matching causes a sub path match to occur. Before directly hitting as an exact match, perform an additional check of the path to sync against the sync_list entry without the '/*' being present. --- src/selective.d | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/selective.d b/src/selective.d index 6e418264..8dc444a3 100644 --- a/src/selective.d +++ b/src/selective.d @@ -277,16 +277,45 @@ private bool isPathExcluded(string path, string[] allowedPaths) // Is path is an exact match of the allowed path? if (comm.length == path.length) { - // the given path is contained in an allowed path - if (!exclude) { - log.vdebug("Evaluation against 'sync_list' result: direct match"); - finalResult = false; - // direct match, break and go sync - break; + // we have a potential exact match + // strip any potential '/*' from the allowed path, to avoid a potential lesser common match + string strippedAllowedPath = strip(allowedPath[offset..$], "/*"); + + if (path == strippedAllowedPath) { + // we have an exact path match + log.vdebug("exact path match"); + if (!exclude) { + log.vdebug("Evaluation against 'sync_list' result: direct match"); + finalResult = false; + // direct match, break and go sync + break; + } else { + log.vdebug("Evaluation against 'sync_list' result: direct match but to be excluded"); + finalResult = true; + // do not set excludeMatched = true here, otherwise parental path also gets excluded + } } else { - log.vdebug("Evaluation against 'sync_list' result: direct match but to be excluded"); - finalResult = true; - // do not set excludeMatched = true here, otherwise parental path also gets excluded + // no exact path match, but something common does match + log.vdebug("something 'common' matches the input path"); + auto splitAllowedPaths = pathSplitter(strippedAllowedPath); + string pathToEvaluate = ""; + foreach(base; splitAllowedPaths) { + pathToEvaluate ~= base; + if (path == pathToEvaluate) { + // The input path matches what we want to evaluate against as a direct match + if (!exclude) { + log.vdebug("Evaluation against 'sync_list' result: direct match for parental path item"); + finalResult = false; + // direct match, break and go sync + break; + } else { + log.vdebug("Evaluation against 'sync_list' result: direct match for parental path item but to be excluded"); + finalResult = true; + // do not set excludeMatched = true here, otherwise parental path also gets excluded + } + } + pathToEvaluate ~= dirSeparator; + } } }