diff --git a/README.md b/README.md index ed062a0f..c81bc806 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ This will display all the pertinent runtime interpretation of the options and co Config path = /home/alex/.config/onedrive Config file found in config path = false Config option 'sync_dir' = /home/alex/OneDrive +Config option 'skip_dir' = Config option 'skip_file' = ~* Config option 'skip_dotfiles' = false Config option 'skip_symlinks' = false @@ -466,11 +467,23 @@ Proceed with caution here when changing the default sync dir from ~/OneDrive to The issue here is around how the client stores the sync_dir path in the database. If the config file is missing, or you don't use the `--syncdir` parameter - what will happen is the client will default back to `~/OneDrive` and 'think' that either all your data has been deleted - thus delete the content on OneDrive, or will start downloading all data from OneDrive into the default location. -### skip_file -Example: `skip_file = "~*|Desktop|Documents/OneNote*|Documents/IISExpress|Documents/SQL Server Management Studio|Documents/Visual Studio*|Documents/config.xlaunch|Documents/WindowsPowerShell"` +### skip_dir +Example: `skip_dir = "Desktop|Documents/IISExpress|Documents/SQL Server Management Studio|Documents/Visual Studio*|Documents/WindowsPowerShell"` Patterns are case insensitive. `*` and `?` [wildcards characters](https://technet.microsoft.com/en-us/library/bb490639.aspx) are supported. Use `|` to separate multiple patterns. +**Note:** after changing `skip_dir`, you must perform a full re-synchronization by adding `--resync` to your existing command line - for example: `onedrive --synchronize --resync` + +### skip_file +Example: `skip_file = "~*|Documents/OneNote*|Documents/config.xlaunch|myfile.ext"` + +Patterns are case insensitive. `*` and `?` [wildcards characters](https://technet.microsoft.com/en-us/library/bb490639.aspx) are supported. Use `|` to separate multiple patterns. + +Files can be skipped in the following fashion: +* Specify a wildcard, eg: '*.txt' (skip all txt files) +* Explicitly specify the filename and it's full path relative to your sync_dir, eg: 'path/to/file/filename.ext' +* Explicitly specify the filename only and skip every instance of this filename, eg: 'filename.ext' + **Note:** after changing `skip_file`, you must perform a full re-synchronization by adding `--resync` to your existing command line - for example: `onedrive --synchronize --resync` **Note:** Do not use a skip_file entry of `.*` as this will prevent correct searching of local changes to process. @@ -515,7 +528,7 @@ Year 2 ### Skipping directories from syncing There are several mechanisms available to 'skip' a directory from scanning: -* Utilise 'skip_file' +* Utilise 'skip_dir' * Utilise 'sync_list' One further method is to add a '.nosync' empty file to any folder. When this file is present, adding `--check-for-nosync` to your command line will now make the sync process skip any folder where the '.nosync' file is present. diff --git a/src/config.d b/src/config.d index 241de24b..5d07a86a 100644 --- a/src/config.d +++ b/src/config.d @@ -30,6 +30,8 @@ final class Config { // Default configuration directory setValue("sync_dir", "~/OneDrive"); + // Skip Directories - no directories are skipped by default + setValue("skip_dir", ""); // Configure to skip ONLY temp files (~*.doc etc) by default // Prior configuration was: .*|~* setValue("skip_file", "~*"); diff --git a/src/main.d b/src/main.d index d6bdf068..80692180 100644 --- a/src/main.d +++ b/src/main.d @@ -348,6 +348,7 @@ int main(string[] args) // Config Options writeln("Config option 'check_nosync' = ", cfg.getValue("check_nosync")); writeln("Config option 'sync_dir' = ", syncDir); + writeln("Config option 'skip_dir' = ", cfg.getValue("skip_dir")); writeln("Config option 'skip_file' = ", cfg.getValue("skip_file")); writeln("Config option 'skip_dotfiles' = ", cfg.getValue("skip_dotfiles")); writeln("Config option 'skip_symlinks' = ", cfg.getValue("skip_symlinks")); @@ -451,7 +452,14 @@ int main(string[] args) } } selectiveSync.load(cfg.syncListFilePath); - selectiveSync.setMask(cfg.getValue("skip_file")); + + // Configure skip_dir & skip_file from config entries + log.vdebug("Configuring skip_dir ..."); + log.vdebug("skip_dir: ", cfg.getValue("skip_dir")); + selectiveSync.setDirMask(cfg.getValue("skip_dir")); + log.vdebug("Configuring skip_file ..."); + log.vdebug("skip_file: ", cfg.getValue("skip_file")); + selectiveSync.setFileMask(cfg.getValue("skip_file")); // Initialize the sync engine log.logAndNotify("Initializing the Synchronization Engine ..."); @@ -464,7 +472,7 @@ int main(string[] args) } } catch (CurlException e) { if (!monitor) { - log.log("\nNo internet connection."); + log.log("\nNo Internet connection."); oneDrive.http.shutdown(); return EXIT_FAILURE; } diff --git a/src/monitor.d b/src/monitor.d index 0a520cbe..ed108031 100644 --- a/src/monitor.d +++ b/src/monitor.d @@ -77,7 +77,10 @@ final class Monitor // skip filtered items if (dirname != ".") { - if (selectiveSync.isNameExcluded(baseName(dirname))) { + if (selectiveSync.isDirNameExcluded(strip(dirname,"./"))) { + return; + } + if (selectiveSync.isFileNameExcluded(baseName(dirname))) { return; } if (selectiveSync.isPathExcluded(buildNormalizedPath(dirname))) { @@ -189,7 +192,10 @@ final class Monitor // skip filtered items path = getPath(event); - if (selectiveSync.isNameExcluded(baseName(path))) { + if (selectiveSync.isDirNameExcluded(strip(path,"./"))) { + goto skip; + } + if (selectiveSync.isFileNameExcluded(strip(path,"./"))) { goto skip; } if (selectiveSync.isPathExcluded(path)) { diff --git a/src/selective.d b/src/selective.d index 829c3267..08661983 100644 --- a/src/selective.d +++ b/src/selective.d @@ -10,6 +10,7 @@ final class SelectiveSync { private string[] paths; private Regex!char mask; + private Regex!char dirmask; void load(string filepath) { @@ -22,20 +23,46 @@ final class SelectiveSync } } - void setMask(const(char)[] mask) + void setFileMask(const(char)[] mask) { this.mask = wild2regex(mask); } - // config file skip_file parameter - bool isNameExcluded(string name) + void setDirMask(const(char)[] dirmask) { - // Does the file match skip_file config entry? - // Returns true if the file matches a skip_file config entry - // Returns false if no match - return !name.matchFirst(mask).empty; + this.dirmask = wild2regex(dirmask); } - + + // config file skip_dir parameter + bool isDirNameExcluded(string name) + { + // Does the directory name match skip_dir config entry? + // Returns true if the name matches a skip_dir config entry + // Returns false if no match + return !name.matchFirst(dirmask).empty; + } + + // config file skip_file parameter + bool isFileNameExcluded(string name) + { + // Does the file name match skip_file config entry? + // Returns true if the name matches a skip_file config entry + // Returns false if no match + + // Try full path match first + if (!name.matchFirst(mask).empty) { + return true; + } else { + // check just the file name + string filename = baseName(name); + if(!filename.matchFirst(mask).empty) { + return true; + } + } + // no match + return false; + } + // config sync_list file handling bool isPathExcluded(string path) { diff --git a/src/sync.d b/src/sync.d index b3bfe6ab..194f86aa 100644 --- a/src/sync.d +++ b/src/sync.d @@ -754,7 +754,7 @@ final class SyncEngine bool unwanted; unwanted |= skippedItems.find(item.parentId).length != 0; if (unwanted) log.vdebug("Flagging as unwanted: find(item.parentId).length != 0"); - unwanted |= selectiveSync.isNameExcluded(item.name); + unwanted |= selectiveSync.isFileNameExcluded(item.name); if (unwanted) log.vdebug("Flagging as unwanted: item name is excluded: ", item.name); // check the item type @@ -1141,7 +1141,8 @@ final class SyncEngine string path; // Is item.name or the path excluded - unwanted = selectiveSync.isNameExcluded(item.name); + unwanted = selectiveSync.isFileNameExcluded(item.name); + if (!unwanted) { path = itemdb.computePath(item.driveId, item.id); unwanted = selectiveSync.isPathExcluded(path); @@ -1483,12 +1484,20 @@ final class SyncEngine // filter out user configured items to skip if (path != ".") { - if (selectiveSync.isNameExcluded(baseName(path))) { - log.vlog("Skipping item - excluded by skip_file config: ", path); - return; + if (isDir(path)) { + if (selectiveSync.isDirNameExcluded(strip(path,"./"))) { + log.vlog("Skipping item - excluded by skip_dir config: ", path); + return; + } + } + if (isFile(path)) { + if (selectiveSync.isFileNameExcluded(strip(path,"./"))) { + log.vlog("Skipping item - excluded by skip_file config: ", path); + return; + } } if (selectiveSync.isPathExcluded(path)) { - log.vlog("Skipping item - path excluded: ", path); + log.vlog("Skipping item - path excluded by sync_list: ", path); return; } }