implement skip_size (Issue #213) (#517)

* Implement skip_size feature request (@luukvbaal)
This commit is contained in:
luukvbaal 2019-06-07 22:37:41 +02:00 committed by abraunegg
parent c617185c14
commit ef6af8e5bc
3 changed files with 26 additions and 1 deletions

View file

@ -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"`

View file

@ -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"],

View file

@ -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;