From 14cd47b56f9aa2bee0c15fbd45cda7915a98ff12 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 29 Jan 2020 16:37:50 +1100 Subject: [PATCH] Implement #699 - Perform skip_dir explicit match only (#768) * Implement #699 - Perform skip_dir explicit match only --- config | 3 ++- docs/USAGE.md | 8 +++++++- onedrive.1.in | 18 ++++++++++++++++++ src/config.d | 6 ++++++ src/main.d | 7 +++++++ src/selective.d | 19 +++++++++++++++---- 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/config b/config index c9586bcd..d96751ee 100644 --- a/config +++ b/config @@ -32,4 +32,5 @@ # sync_root_files = "false" # classify_as_big_delete = "1000" # user_agent = "" -# remove_source_files = "false" \ No newline at end of file +# remove_source_files = "false" +# skip_dir_strict_match = "false" \ No newline at end of file diff --git a/docs/USAGE.md b/docs/USAGE.md index e6de2c93..d8e2fbc2 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -639,6 +639,8 @@ Options: Check for the presence of .nosync in the syncdir root. If found, do not perform sync. --check-for-nosync Check for the presence of .nosync in each directory. If found, skip directory from sync. + --classify-as-big-delete + Number of children in a path that is locally removed which will be classified as a 'big data delete' --confdir ARG Set the directory used to store the configuration files --create-directory ARG @@ -695,12 +697,16 @@ Options: Print the access token, useful for debugging --remove-directory ARG Remove a directory on OneDrive - no sync will be performed. + --remove-source-files + Remove source file after successful transfer to OneDrive when using --upload-only --resync Forget the last saved state, perform a full sync --single-directory ARG Specify a single local directory within the OneDrive root to sync. - --skip-dir + --skip-dir ARG Skip any directories that match this pattern from syncing + --skip-dir-strict-match + When matching skip_dir directories, only match explicit matches --skip-dot-files Skip dot files and folders from syncing --skip-file ARG diff --git a/onedrive.1.in b/onedrive.1.in index 26825e39..52e0a32a 100644 --- a/onedrive.1.in +++ b/onedrive.1.in @@ -33,6 +33,11 @@ Check for the presence of .nosync in each directory. If found, skip directory fr .br Configuration file key: \fBcheck_nosync\fP (default: \fBfalse\fP) .TP +\fB\-\-classify\-as\-big\-delete\fP +Number of children in a path that is locally removed which will be classified as a 'big data delete' +.br +Configuration file key: \fBclassify_as_big_delete\fP (default: \fB1000\fP) +.TP \fB\-\-confdir\fP ARG Set the directory used to store the configuration files .TP @@ -141,9 +146,22 @@ Forget the last saved state, perform a full sync \fB\-\-remove\-directory\fP ARG Remove a directory on OneDrive \- no sync will be performed. .TP +\fB\-\-remove\-source\-files\fP +Remove source file after successful transfer to OneDrive when using \-\-upload-only +.br +Configuration file key: \fBremove_source_files\fP (default: \fBfalse\fP) +.TP \fB\-\-single\-directory\fP ARG Specify a single local directory within the OneDrive root to sync. .TP +\fB\-\-skip\-dir\fP ARG +Skip any directories that match this pattern from syncing +.TP +\fB\-\-skip\-dir\-strict\-match\fP +When matching skip_dir directories, only match explicit matches +.br +Configuration file key: \fBskip_dir_strict_match\fP (default: \fBfalse\fP) +.TP \fB\-\-skip\-dot\-files\fP Skip dot files and folders from syncing .br diff --git a/src/config.d b/src/config.d index ea7e3c34..83f85ef4 100644 --- a/src/config.d +++ b/src/config.d @@ -66,6 +66,8 @@ final class Config longValues["classify_as_big_delete"] = 1000; // Delete source after successful transfer boolValues["remove_source_files"] = false; + // Strict matching for skip_dir + boolValues["skip_dir_strict_match"] = false; // Determine the users home directory. // Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts @@ -169,6 +171,7 @@ final class Config boolValues["synchronize"] = false; boolValues["force"] = false; boolValues["remove_source_files"] = false; + boolValues["skip_dir_strict_match"] = false; // Application Startup option validation try { @@ -290,6 +293,9 @@ final class Config "skip-size", "Skip new files larger than this size (in MB)", &longValues["skip_size"], + "skip-dir-strict-match", + "When matching skip_dir directories, only match explicit matches", + &boolValues["skip_dir_strict_match"], "skip-symlinks", "Skip syncing of symlinks", &boolValues["skip_symlinks"], diff --git a/src/main.d b/src/main.d index b540b09d..1758fd75 100644 --- a/src/main.d +++ b/src/main.d @@ -506,9 +506,16 @@ int main(string[] args) selectiveSync.load(cfg.syncListFilePath); // Configure skip_dir & skip_file from config entries + // skip_dir items log.vdebug("Configuring skip_dir ..."); log.vdebug("skip_dir: ", cfg.getValueString("skip_dir")); selectiveSync.setDirMask(cfg.getValueString("skip_dir")); + // Was --skip-dir-strict-match configured? + if (cfg.getValueBool("skip_dir_strict_match")) { + selectiveSync.setSkipDirStrictMatch(); + } + + // skip_file items log.vdebug("Configuring skip_file ..."); // Validate skip_file to ensure that this does not contain an invalid configuration // Do not use a skip_file entry of .* as this will prevent correct searching of local changes to process. diff --git a/src/selective.d b/src/selective.d index 9385a0c2..fb0b035a 100644 --- a/src/selective.d +++ b/src/selective.d @@ -11,6 +11,7 @@ final class SelectiveSync private string[] paths; private Regex!char mask; private Regex!char dirmask; + private bool skipDirStrictMatch = false; void load(string filepath) { @@ -22,6 +23,13 @@ final class SelectiveSync .array; } } + + // Configure skipDirStrictMatch if function is called + // By default, skipDirStrictMatch = false; + void setSkipDirStrictMatch() + { + skipDirStrictMatch = true; + } void setFileMask(const(char)[] mask) { @@ -44,10 +52,13 @@ final class SelectiveSync if (!name.matchFirst(dirmask).empty) { return true; } else { - // check just the file name - string filename = baseName(name); - if(!filename.matchFirst(dirmask).empty) { - return true; + // Do we check the base name as well? + if (!skipDirStrictMatch) { + // check just the basename in the path + string filename = baseName(name); + if(!filename.matchFirst(dirmask).empty) { + return true; + } } } // no match