From caec1cb8cb7d58dd2cd9fe2b2177a0afc0579d36 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Thu, 9 May 2019 21:18:49 +1000 Subject: [PATCH] Implement --sync-root-files when using a sync_list file (Issue #491) (#492) * Implement --sync-root-files to sync all files in the OneDrive root when using a sync_list file that would normally exclude these files from being synced --- config | 1 + src/config.d | 4 ++++ src/main.d | 2 ++ src/sync.d | 23 +++++++++++++++++++---- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/config b/config index 17bc1299..239a2e92 100644 --- a/config +++ b/config @@ -28,3 +28,4 @@ # min_notify_changes = "5" # monitor_log_frequency = "5" # monitor_fullscan_frequency = "10" +# sync_root_files = "false" diff --git a/src/config.d b/src/config.d index 2e430310..06f6d4da 100644 --- a/src/config.d +++ b/src/config.d @@ -46,6 +46,7 @@ final class Config boolValues["debug_https"] = false; boolValues["skip_dotfiles"] = false; boolValues["dry_run"] = false; + boolValues["sync_root_files"] = false; longValues["verbose"] = log.verbose; // might be initialized by the first getopt call! longValues["monitor_interval"] = 45, longValues["min_notify_changes"] = 5; @@ -266,6 +267,9 @@ final class Config "synchronize", "Perform a synchronization", &boolValues["synchronize"], + "sync-root-files", + "Sync all files in sync_dir root when using sync_list.", + &boolValues["sync_root_files"], "upload-only", "Only upload to OneDrive, do not sync changes from OneDrive locally", &boolValues["upload_only"], diff --git a/src/main.d b/src/main.d index 701c4e64..23d4dcee 100644 --- a/src/main.d +++ b/src/main.d @@ -179,6 +179,7 @@ int main(string[] args) // Is sync_list configured? if (exists(userSyncList)){ + writeln("Config option 'sync_root_files' = ", cfg.getValueBool("sync_root_files")); writeln("Selective sync configured = true"); writeln("sync_list contents:"); // Output the sync_list contents @@ -189,6 +190,7 @@ int main(string[] args) writeln(line); } } else { + writeln("Config option 'sync_root_files' = ", cfg.getValueBool("sync_root_files")); writeln("Selective sync configured = false"); } diff --git a/src/sync.d b/src/sync.d index 788cfe7f..52f4de82 100644 --- a/src/sync.d +++ b/src/sync.d @@ -858,8 +858,19 @@ final class SyncEngine // compute the item path to see if the path is excluded path = itemdb.computePath(item.driveId, item.parentId) ~ "/" ~ item.name; path = buildNormalizedPath(path); - unwanted = selectiveSync.isPathExcluded(path); - if (unwanted) log.vdebug("OneDrive change path is to be excluded by user configuration: ", path); + if (selectiveSync.isPathExcluded(path)) { + // selective sync advised to skip, however is this a file and are we configured to upload / download files in the root? + if ((isItemFile(driveItem)) && (cfg.getValueBool("sync_root_files")) && (rootName(path) == "") ) { + // This is a file + // We are configured to sync all files in the root + // This is a file in the logical root + unwanted = false; + } else { + // path is unwanted + unwanted = true; + log.vdebug("OneDrive change path is to be excluded by user configuration: ", path); + } + } } else { log.vdebug("Flagging as unwanted: item.driveId (", item.driveId,"), item.parentId (", item.parentId,") not in local database"); unwanted = true; @@ -1638,8 +1649,12 @@ final class SyncEngine } } if (selectiveSync.isPathExcluded(path)) { - log.vlog("Skipping item - path excluded by sync_list: ", path); - return; + if ((isFile(path)) && (cfg.getValueBool("sync_root_files")) && (rootName(strip(path,"./")) == "")) { + log.vdebug("Not skipping path due to sync_root_files inclusion: ", path); + } else { + log.vlog("Skipping item - path excluded by sync_list: ", path); + return; + } } }