From ef6af8e5bc2000e9bba33915e5d14a523c893e36 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Fri, 7 Jun 2019 22:37:41 +0200 Subject: [PATCH] implement skip_size (Issue #213) (#517) * Implement skip_size feature request (@luukvbaal) --- README.md | 5 +++++ src/config.d | 4 ++++ src/sync.d | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 74f5805b..a9fe949f 100644 --- a/README.md +++ b/README.md @@ -522,6 +522,11 @@ Example: `skip_symlinks = "true"` Setting this to `"true"` will skip all symlinks while syncing. +### skip_size +Example: `skip_size = "500" + +Setting this to anything other than 0 (default), will skip files greater than its value in MB. This only applies to new files e.g. earlier synchronized files now exceeding `skip_size` will stay synchronized. + ### monitor_interval Example: `monitor_interval = "300"` diff --git a/src/config.d b/src/config.d index 06f6d4da..a01e640c 100644 --- a/src/config.d +++ b/src/config.d @@ -49,6 +49,7 @@ final class Config boolValues["sync_root_files"] = false; longValues["verbose"] = log.verbose; // might be initialized by the first getopt call! longValues["monitor_interval"] = 45, + longValues["skip_size"] = 0, longValues["min_notify_changes"] = 5; longValues["monitor_log_frequency"] = 5; // Number of n sync runs before performing a full local scan of sync_dir @@ -255,6 +256,9 @@ final class Config "skip-file", "Skip any files that match this pattern from syncing", &stringValues["skip_file"], + "skip-size", + "Skip new files larger than this size (in MB)", + &longValues["skip_size"], "skip-symlinks", "Skip syncing of symlinks", &boolValues["skip_symlinks"], diff --git a/src/sync.d b/src/sync.d index 5c1c2726..6b27efd9 100644 --- a/src/sync.d +++ b/src/sync.d @@ -200,6 +200,8 @@ final class SyncEngine private string accountType; // free space remaining at init() private long remainingFreeSpace; + // file size limit for a new file + private long newSizeLimit; // is file malware flag private bool malwareDetected = false; // download filesystem issue flag @@ -220,6 +222,8 @@ final class SyncEngine this.selectiveSync = selectiveSync; // session = UploadSession(onedrive, cfg.uploadStateFilePath); this.dryRun = cfg.getValueBool("dry_run"); + this.newSizeLimit = cfg.getValueLong("skip_size") * 2^^20; + this.newSizeLimit = (this.newSizeLimit == 0) ? long.max : this.newSizeLimit; } void reset() @@ -834,7 +838,7 @@ final class SyncEngine unwanted = selectiveSync.isFileNameExcluded(item.name); if (unwanted) log.vlog("Skipping item - excluded by skip_file config: ", item.name); } - + // check the item type if (!unwanted) { if (isItemFile(driveItem)) { @@ -957,6 +961,13 @@ final class SyncEngine applyChangedItem(oldItem, oldPath, item, path); } else { log.vdebug("OneDrive change is a new local item"); + // Check if file should be skipped based on size limit + if (isItemFile(driveItem)) { + if (onedrive.getFileDetails(item.driveId, item.id)["size"].integer >= this.newSizeLimit) { + log.vlog("Skipping item - excluded by skip_size config: ", item.name, " (", onedrive.getFileDetails(item.driveId, item.id)["size"].integer/2^^20, " MB)"); + return; + } + } applyNewItem(item, path); } @@ -1929,6 +1940,11 @@ final class SyncEngine if (e.httpStatusCode == 404) { // The file was not found on OneDrive, need to upload it + // Check if file should be skipped based on skip_size config + if (thisFileSize >= this.newSizeLimit) { + writeln("Skipping item - excluded by skip_size config: ", path, " (", thisFileSize/2^^20," MB)"); + return; + } write("Uploading new file ", path, " ..."); JSONValue response;