From c0d2874acee4bf86822a2295f1d76e6a01c44f6c Mon Sep 17 00:00:00 2001 From: abraunegg Date: Tue, 10 Jul 2018 13:08:17 +1000 Subject: [PATCH] Fix: skip_file configuration doesn't handle spaces or specified directory paths (Issue #52) (#57) * Update skip_file handling by using updated wild2regex to check files & paths of items to skip ro resolve issue #52 --- src/selective.d | 20 +++++++++++++++++++- src/util.d | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/selective.d b/src/selective.d index 80621498..829c3267 100644 --- a/src/selective.d +++ b/src/selective.d @@ -39,7 +39,7 @@ final class SelectiveSync // config sync_list file handling bool isPathExcluded(string path) { - return .isPathExcluded(path, paths); + return .isPathExcluded(path, paths) || .isPathMatched(path, mask); } } @@ -67,6 +67,24 @@ private bool isPathExcluded(string path, string[] allowedPaths) return true; } +// test if the given path is matched by the regex expression. +// recursively test up the tree. +private bool isPathMatched(string path, Regex!char mask) { + path = buildNormalizedPath(path); + auto paths = pathSplitter(path); + + string prefix = ""; + foreach(base; paths) { + prefix ~= base; + if (!path.matchFirst(mask).empty) { + // the given path matches something which we should skip + return true; + } + prefix ~= dirSeparator; + } + return false; +} + unittest { assert(isPathExcluded("Documents2", ["Documents"])); diff --git a/src/util.d b/src/util.d index 1259d98d..73d73c1e 100644 --- a/src/util.d +++ b/src/util.d @@ -99,7 +99,13 @@ Regex!char wild2regex(const(char)[] pattern) break; case '+': str ~= "\\+"; + break; + case ' ': + str ~= "\\s+"; break; + case '/': + str ~= "\\/"; + break; default: str ~= c; break;