mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-08 16:56:39 +02:00
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:
parent
a2889098e9
commit
521cf33001
21
src/sync.d
21
src/sync.d
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue