1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 00:11:17 +02:00

Make large path warnings human-readable

This commit is contained in:
Eelco Dolstra 2024-05-10 16:58:19 +02:00
parent 5314430437
commit cf3b044b7e
4 changed files with 8 additions and 7 deletions

View file

@ -171,7 +171,7 @@ std::pair<StorePath, Hash> StoreDirConfig::computeStorePath(
{ {
auto [h, size] = hashPath(path, method.getFileIngestionMethod(), hashAlgo, filter); auto [h, size] = hashPath(path, method.getFileIngestionMethod(), hashAlgo, filter);
if (size && *size >= settings.largePathWarningThreshold) if (size && *size >= settings.largePathWarningThreshold)
warn("hashed large path '%s' (%d bytes)", path, *size); warn("hashed large path '%s' (%s)", path, renderSize(*size));
return { return {
makeFixedOutputPathFromCA( makeFixedOutputPathFromCA(
name, name,
@ -215,7 +215,7 @@ StorePath Store::addToStore(
LengthSource lengthSource(*source); LengthSource lengthSource(*source);
auto storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair); auto storePath = addToStoreFromDump(lengthSource, name, fsm, method, hashAlgo, references, repair);
if (lengthSource.total >= settings.largePathWarningThreshold) 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; return storePath;
} }

View file

@ -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<char, 9> prefixes{{ static const std::array<char, 9> prefixes{{
'K', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' 'K', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
@ -123,7 +123,7 @@ std::string renderSize(uint64_t value)
++power; ++power;
res /= 1024; 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));
} }

View file

@ -139,9 +139,10 @@ N string2IntWithUnitPrefix(std::string_view s)
/** /**
* Pretty-print a byte value, e.g. 12433615056 is rendered as `11.6 * 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. * Parse a string into a float.

View file

@ -140,7 +140,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
void printSize(uint64_t value) void printSize(uint64_t value)
{ {
if (humanReadable) if (humanReadable)
std::cout << fmt("\t%s", renderSize(value)); std::cout << fmt("\t%s", renderSize(value, true));
else else
std::cout << fmt("\t%11d", value); std::cout << fmt("\t%11d", value);
} }