From 99828245f8f03a8b3b54a04f67e6df31235838f4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Aug 2018 16:18:53 +0200 Subject: printSize() fixes Fix a 32-bit overflow that resulted in negative numbers being printed; use fmt() instead of boost::format(); change -H to -h for consistency with 'ls' and 'du'; make the columns narrower (since they can't be bigger than 1024.0). --- src/nix/path-info.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/nix') diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index fa4f45fb429d..916ed360e62d 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -5,8 +5,6 @@ #include "common-args.hh" #include -#include -#include using namespace nix; @@ -21,7 +19,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON { mkFlag('s', "size", "print size of the NAR dump of each path", &showSize); mkFlag('S', "closure-size", "print sum size of the NAR dumps of the closure of each path", &showClosureSize); - mkFlag('H', "human-readable", "with -s and -S, print sizes like 1K 234M 5.67G etc.", &humanReadable); + mkFlag('h', "human-readable", "with -s and -S, print sizes like 1K 234M 5.67G etc.", &humanReadable); mkFlag(0, "sigs", "show signatures", &showSigs); } @@ -44,7 +42,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON }, Example{ "To show a package's closure size and all its dependencies with human readable sizes:", - "nix path-info -rsSH nixpkgs.rust" + "nix path-info -rsSh nixpkgs.rust" }, Example{ "To check the existence of a path in a binary cache:", @@ -65,10 +63,10 @@ struct CmdPathInfo : StorePathsCommand, MixJSON }; } - void printSize(int value) + void printSize(unsigned long long value) { if (!humanReadable) { - std::cout << '\t' << boost::format("%11d") % value; + std::cout << fmt("\t%11d", value); return; } @@ -81,7 +79,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON ++power; res /= 1024; } - std::cout << '\t' << boost::format("%11.1f") % res << idents[power]; + std::cout << fmt("\t%6.1f%c", res, idents.at(power)); } void run(ref store, Paths storePaths) override -- cgit 1.4.1