Add 'quota' check for valid value (#466)

* If the 'quota' details are not provided when querying the OneDrive account details, we cannot set 'remainingFreeSpace' Add a flag that if this is 0 or negative, ignore validating if there is enough free space to upload a file and just upload blindly
This commit is contained in:
abraunegg 2019-04-13 08:59:03 +10:00 committed by GitHub
parent a2889098e9
commit 521cf33001
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -207,6 +207,8 @@ final class SyncEngine
private bool initDone = false;
// sync engine dryRun flag
private bool dryRun = false;
// quota details available
private bool quotaAvailable = true;
this(Config cfg, OneDriveApi onedrive, ItemDatabase itemdb, SelectiveSync selectiveSync)
{
@ -264,12 +266,23 @@ final class SyncEngine
}
}
// Debug OneDrive Account details response
log.vdebug("OneDrive Account Details: ", oneDriveDetails);
// Successfully got details from OneDrive without a server side error such as HTTP/1.1 504 Gateway Timeout
accountType = oneDriveDetails["driveType"].str;
defaultDriveId = oneDriveDetails["id"].str;
defaultRootId = onedrive.getDefaultRoot["id"].str;
remainingFreeSpace = oneDriveDetails["quota"]["remaining"].integer;
// In some cases OneDrive Business configurations 'restrict' quota details thus is empty / blank / negative value / zero
if (remainingFreeSpace <= 0) {
// quota details not available
log.error("ERROR: OneDrive quota information is being restricted. Please fix by speaking to your OneDrive / Office 365 Administrator.");
log.error("ERROR: Flagging to disable upload space checks - this MAY have undesirable results if a file cannot be uploaded due to out of space.");
quotaAvailable = false;
}
// Display accountType, defaultDriveId, defaultRootId & remainingFreeSpace for verbose logging purposes
log.vlog("Account Type: ", accountType);
log.vlog("Default Drive ID: ", defaultDriveId);
@ -1572,9 +1585,13 @@ final class SyncEngine
}
} else {
// This item is a file
// Can we upload this file - is there enough free space? - https://github.com/skilion/onedrive/issues/73
auto fileSize = getSize(path);
if ((remainingFreeSpace - fileSize) > 0){
// Can we upload this file - is there enough free space? - https://github.com/skilion/onedrive/issues/73
// However if the OneDrive account does not provide the quota details, we have no idea how much free space is available
if ((!quotaAvailable) || ((remainingFreeSpace - fileSize) > 0)){
if (!quotaAvailable) {
log.vlog("Ignoring OneDrive account quota details to upload file - this may fail if not enough space on OneDrive ..");
}
Item item;
if (!itemdb.selectByPath(path, defaultDriveId, item)) {
uploadNewFile(path);