diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index a2095e02e..0b78f999e 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -171,7 +171,7 @@ std::pair StoreDirConfig::computeStorePath( { auto [h, size] = hashPath(path, method.getFileIngestionMethod(), hashAlgo, filter); if (size && *size >= settings.largePathWarningThreshold) - warn("hashed large path '%s' (%d bytes)", path, *size); + warn("hashed large path '%s' (%s)", path, renderSize(*size)); return { makeFixedOutputPathFromCA( name, @@ -215,7 +215,7 @@ StorePath Store::addToStore( LengthSource lengthSource(*source); auto storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair); if (lengthSource.total >= settings.largePathWarningThreshold) - warn("copied large path '%s' to the store (%d bytes)", path, lengthSource.total); + warn("copied large path '%s' to the store (%s)", path, renderSize(lengthSource.total)); return storePath; } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index f893fc12d..16bca093c 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -112,7 +112,7 @@ std::string rewriteStrings(std::string s, const StringMap & rewrites) } -std::string renderSize(uint64_t value) +std::string renderSize(uint64_t value, bool align) { static const std::array prefixes{{ 'K', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' @@ -123,7 +123,7 @@ std::string renderSize(uint64_t value) ++power; res /= 1024; } - return fmt("%6.1f %ciB", power == 0 ? res / 1024 : res, prefixes.at(power)); + return fmt(align ? "%6.1f %ciB" : "%.1f %ciB", power == 0 ? res / 1024 : res, prefixes.at(power)); } diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 01e42ce57..0c8c82bfd 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -139,9 +139,10 @@ N string2IntWithUnitPrefix(std::string_view s) /** * Pretty-print a byte value, e.g. 12433615056 is rendered as `11.6 - * GiB`. + * GiB`. If `align` is set, the number will be right-justified + * (e.g. `__11.6 GiB`). */ -std::string renderSize(uint64_t value); +std::string renderSize(uint64_t value, bool align = false); /** * Parse a string into a float. diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index a1a2c40f4..47f9baee5 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -140,7 +140,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON void printSize(uint64_t value) { if (humanReadable) - std::cout << fmt("\t%s", renderSize(value)); + std::cout << fmt("\t%s", renderSize(value, true)); else std::cout << fmt("\t%11d", value); }