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
This commit is contained in:
abraunegg 2019-05-09 21:18:49 +10:00 committed by GitHub
parent bac5d6f1a9
commit caec1cb8cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 4 deletions

1
config
View file

@ -28,3 +28,4 @@
# min_notify_changes = "5" # min_notify_changes = "5"
# monitor_log_frequency = "5" # monitor_log_frequency = "5"
# monitor_fullscan_frequency = "10" # monitor_fullscan_frequency = "10"
# sync_root_files = "false"

View file

@ -46,6 +46,7 @@ final class Config
boolValues["debug_https"] = false; boolValues["debug_https"] = false;
boolValues["skip_dotfiles"] = false; boolValues["skip_dotfiles"] = false;
boolValues["dry_run"] = false; boolValues["dry_run"] = false;
boolValues["sync_root_files"] = false;
longValues["verbose"] = log.verbose; // might be initialized by the first getopt call! longValues["verbose"] = log.verbose; // might be initialized by the first getopt call!
longValues["monitor_interval"] = 45, longValues["monitor_interval"] = 45,
longValues["min_notify_changes"] = 5; longValues["min_notify_changes"] = 5;
@ -266,6 +267,9 @@ final class Config
"synchronize", "synchronize",
"Perform a synchronization", "Perform a synchronization",
&boolValues["synchronize"], &boolValues["synchronize"],
"sync-root-files",
"Sync all files in sync_dir root when using sync_list.",
&boolValues["sync_root_files"],
"upload-only", "upload-only",
"Only upload to OneDrive, do not sync changes from OneDrive locally", "Only upload to OneDrive, do not sync changes from OneDrive locally",
&boolValues["upload_only"], &boolValues["upload_only"],

View file

@ -179,6 +179,7 @@ int main(string[] args)
// Is sync_list configured? // Is sync_list configured?
if (exists(userSyncList)){ if (exists(userSyncList)){
writeln("Config option 'sync_root_files' = ", cfg.getValueBool("sync_root_files"));
writeln("Selective sync configured = true"); writeln("Selective sync configured = true");
writeln("sync_list contents:"); writeln("sync_list contents:");
// Output the sync_list contents // Output the sync_list contents
@ -189,6 +190,7 @@ int main(string[] args)
writeln(line); writeln(line);
} }
} else { } else {
writeln("Config option 'sync_root_files' = ", cfg.getValueBool("sync_root_files"));
writeln("Selective sync configured = false"); writeln("Selective sync configured = false");
} }

View file

@ -858,8 +858,19 @@ final class SyncEngine
// compute the item path to see if the path is excluded // compute the item path to see if the path is excluded
path = itemdb.computePath(item.driveId, item.parentId) ~ "/" ~ item.name; path = itemdb.computePath(item.driveId, item.parentId) ~ "/" ~ item.name;
path = buildNormalizedPath(path); path = buildNormalizedPath(path);
unwanted = selectiveSync.isPathExcluded(path); if (selectiveSync.isPathExcluded(path)) {
if (unwanted) log.vdebug("OneDrive change path is to be excluded by user configuration: ", 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 { } else {
log.vdebug("Flagging as unwanted: item.driveId (", item.driveId,"), item.parentId (", item.parentId,") not in local database"); log.vdebug("Flagging as unwanted: item.driveId (", item.driveId,"), item.parentId (", item.parentId,") not in local database");
unwanted = true; unwanted = true;
@ -1638,8 +1649,12 @@ final class SyncEngine
} }
} }
if (selectiveSync.isPathExcluded(path)) { if (selectiveSync.isPathExcluded(path)) {
log.vlog("Skipping item - path excluded by sync_list: ", path); if ((isFile(path)) && (cfg.getValueBool("sync_root_files")) && (rootName(strip(path,"./")) == "")) {
return; log.vdebug("Not skipping path due to sync_root_files inclusion: ", path);
} else {
log.vlog("Skipping item - path excluded by sync_list: ", path);
return;
}
} }
} }