download: check available disk space before downloading

We don't check *while* the download happens, so it might
still be that we don't have enough space later
This commit is contained in:
moneromooo-monero 2017-02-28 22:15:54 +00:00
parent f36c5f1e08
commit 749ebacebd
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

View File

@ -95,6 +95,14 @@ namespace tools
{
MINFO("Content-Length: " << length);
content_length = length;
boost::filesystem::path path(control->path);
boost::filesystem::space_info si = boost::filesystem::space(path);
if (si.available < (size_t)content_length)
{
const uint64_t avail = (si.available + 1023) / 1024, needed = (content_length + 1023) / 1024;
MERROR("Not enough space to download " << needed << " kB to " << path << " (" << avail << " kB available)");
return false;
}
}
return true;
}