Why a 400 GB Drive showed as 429 GB
On 28 November I added cloud storage to the Merge Clouds Home screen. Each Google Drive and MEGA tile gets a bar and a line like “12.4 GB of 15 GB used”. The bar turns amber at 85% and to the error colour at 95%. S3 and B2 just say “Pay as you go storage”, since there’s no quota to show.
The backend side is one endpoint per cloud. It calls rclone’s operations/about for that cloud and returns {supported, total, used, free}, cached for 10 minutes because quotas change slowly.
It went into the 1.1.1 build. Fifteen minutes later I committed 1.1.2 with a fix, and a backend fix five minutes after that. The tiles were wrong in two separate ways.
Bug one: the wrong kind of gigabyte
A Google One 400 GB plan showed as 429 GB.
rclone reports quotas in bytes. My formatter divided by 10⁹ and called the result GB, and I’d even written a comment saying that’s how Google and MEGA show quotas. They don’t. A 400 GB plan is 400 × 1024³ bytes:
400 × 1024³ = 429,496,729,600 bytes
÷ 10⁹ = 429.5 → shown as "429 GB"
÷ 1024³ = 400 → shown as "400 GB"
MEGA’s 20 GB free plan had the same problem and showed as 21.5 GB. Both services sell and display binary units and label them “GB”. Whether that should be written GiB doesn’t matter here. The number on my tile has to match the number in the Google or MEGA app, or people assume my app is wrong. It was.
The fix in the app:
// Google Drive and MEGA sell and show quotas in binary units labelled "GB" (15 GB = 15 × 1024³ bytes),
// so dividing by 1024³ gives the same numbers people see in those apps ("400 GB", not "429 GB").
private const val GB = 1024.0 * 1024 * 1024
private const val TB = GB * 1024
TB now starts at 1024 GB instead of 10¹² bytes. I also shortened the text to “22.6 of 400 GB”, with both numbers in the total’s unit, because the longer line didn’t fit a half-width tile. The tests pin the cases that were wrong: 400 * gb must print “400 GB” and 20 * gb must print “20 GB”.
Bug two: “used” meant Drive files only
The units weren’t the only problem.
operations/about on Google Drive returns more than used. It also returns trashed and other. Drive’s used counts only files in Drive. But a Google account’s quota is shared with Gmail and Google Photos, and those land in other. Google’s own storage page shows what fills the account, all of it.
My first version only filled in a missing number:
if (free == null && used != null) free = Math.max(0, total - used);
if (used == null && free != null) used = Math.max(0, total - free);
So when Drive sent all three, I showed its used as is. The fix is to trust free whenever it’s there:
// Google Drive's "used" is Drive files only; the quota is shared with Gmail, Photos and trash
// ("other", "trashed"). What fills the account is total - free, which is what Google shows.
if (free != null) used = Math.max(0, total - free);
else if (used != null) free = Math.max(0, total - used);
The test for it uses a made-up 400 GB account with 21 GB in Drive and 163 GB in other. It expects 184 GB used, not 21.
The check I do now
Before a storage change goes out, I open Google’s storage page next to the tile and compare the numbers.