Skip to content

Commit

Permalink
Update FR abraunegg#2359
Browse files Browse the repository at this point in the history
Update --display-quota output to:

Deleted:   8.19 GB (8793627814 bytes)
Remaining: 25580.69 GB (27467060611614 bytes)
State:     normal
Total:     25600.00 GB (27487790694400 bytes)
Used:      11.12 GB (11936454972 bytes)
  • Loading branch information
abraunegg committed Oct 26, 2023
1 parent 8979bf7 commit 16595ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ class SyncEngine {
// What do we display here for space remaining
if (appConfig.remainingFreeSpace > 0) {
// Display the actual value
log.vlog("Remaining Free Space: ", (appConfig.remainingFreeSpace/1024) , " KB");
log.vlog("Remaining Free Space: ", byteToGibiByte(appConfig.remainingFreeSpace) , " GB (", appConfig.remainingFreeSpace, " bytes)");
} else {
// zero or non-zero value or restricted
if (!appConfig.quotaRestricted){
Expand Down Expand Up @@ -7023,6 +7023,8 @@ class SyncEngine {
// Query OneDrive for the quota details
void queryOneDriveForQuotaDetails() {
// This function is similar to getRemainingFreeSpace() but is different in data being analysed and output method



JSONValue currentDriveQuota;
string driveId;
Expand Down Expand Up @@ -7065,35 +7067,33 @@ class SyncEngine {

// Update values
if ("deleted" in currentDriveQuota["quota"]) {
deletedValue = to!string(currentDriveQuota["quota"]["deleted"].integer);
deletedValue = byteToGibiByte(currentDriveQuota["quota"]["deleted"].integer);
}

if ("remaining" in currentDriveQuota["quota"]) {
remainingValue = to!string(currentDriveQuota["quota"]["remaining"].integer);
remainingValue = byteToGibiByte(currentDriveQuota["quota"]["remaining"].integer);
}

if ("state" in currentDriveQuota["quota"]) {
stateValue = currentDriveQuota["quota"]["state"].str;
}

if ("total" in currentDriveQuota["quota"]) {
totalValue = to!string(currentDriveQuota["quota"]["total"].integer);
totalValue = byteToGibiByte(currentDriveQuota["quota"]["total"].integer);
}

if ("used" in currentDriveQuota["quota"]) {
usedValue = to!string(currentDriveQuota["quota"]["used"].integer);
usedValue = byteToGibiByte(currentDriveQuota["quota"]["used"].integer);
}

writeln("Microsoft OneDrive quota information as reported for this Drive ID: ", driveId);
writeln();
writeln("Deleted: ", deletedValue);
writeln("Remaining: ", remainingValue);
writeln("Deleted: ", deletedValue, " GB (", currentDriveQuota["quota"]["deleted"].integer, " bytes)");
writeln("Remaining: ", remainingValue, " GB (", currentDriveQuota["quota"]["remaining"].integer, " bytes)");
writeln("State: ", stateValue);
writeln("Total: ", totalValue);
writeln("Used: ", usedValue);
writeln("Total: ", totalValue, " GB (", currentDriveQuota["quota"]["total"].integer, " bytes)");
writeln("Used: ", usedValue, " GB (", currentDriveQuota["quota"]["used"].integer, " bytes)");
writeln();
writeln("The numeric values above are expressed in bytes");

} else {
writeln("Microsoft OneDrive quota information is being restricted for this Drive ID: ", driveId);
}
Expand Down
9 changes: 9 additions & 0 deletions src/util.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import std.json;
import std.traits;
import core.stdc.stdlib;
import core.thread;
import std.math;
import std.format;

// What other modules that we have created do we need to import?
import log;
Expand Down Expand Up @@ -790,4 +792,11 @@ bool hasETag(const ref JSONValue item) {

bool hasSharedElement(const ref JSONValue item) {
return ("eTag" in item) != null;
}

// Convert bytes to GB
string byteToGibiByte(ulong bytes) {
double gib = bytes / pow(1024.0,3);
double roundedGib = round(gib * 100) / 100;
return to!string(format("%.2f", roundedGib)); // Format to ensure two decimal places
}

0 comments on commit 16595ef

Please sign in to comment.