mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
Avoid overflow and use boost::format
If the user has an object greater than 1024 yottabytes, it'll just display it as N yottabytes instead of overflowing. Swaps to use boost::format strings instead of std::setw and std::setprecision.
This commit is contained in:
parent
3407a5d936
commit
c908df881f
1 changed files with 7 additions and 6 deletions
|
@ -4,8 +4,9 @@
|
|||
#include "json.hh"
|
||||
#include "common-args.hh"
|
||||
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include <boost/format.hpp>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace nix;
|
||||
|
||||
|
@ -67,20 +68,20 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
|
|||
void printSize(int value)
|
||||
{
|
||||
if (!humanReadable) {
|
||||
std::cout << '\t' << std::setw(11) << value;
|
||||
std::cout << '\t' << boost::format("%11d") % value;
|
||||
return;
|
||||
}
|
||||
|
||||
static constexpr std::array<char, 6> idents = {
|
||||
' ', 'K', 'M', 'G', 'T', 'P'
|
||||
static constexpr std::array<char, 9> idents = {
|
||||
' ', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
|
||||
};
|
||||
size_t power = 0;
|
||||
double res = value;
|
||||
while (res > 1024) {
|
||||
while (res > 1024 && power < idents.size()) {
|
||||
++power;
|
||||
res /= 1024;
|
||||
}
|
||||
std::cout << '\t' << std::setw(11) << std::setprecision(3) << res << idents[power];
|
||||
std::cout << '\t' << boost::format("%11.1f") % res << idents[power];
|
||||
}
|
||||
|
||||
void run(ref<Store> store, Paths storePaths) override
|
||||
|
|
Loading…
Reference in a new issue