mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-16 15:17:18 +02:00
Make large path warnings human-readable
This commit is contained in:
parent
5314430437
commit
cf3b044b7e
4 changed files with 8 additions and 7 deletions
|
@ -171,7 +171,7 @@ std::pair<StorePath, Hash> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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{{
|
||||
'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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue