Skip to content

Commit

Permalink
Make large path warnings human-readable
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed May 10, 2024
1 parent 6b5d8ce commit 99c04ce
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,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,
Expand Down Expand Up @@ -219,7 +219,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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libutil/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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));
}


Expand Down
5 changes: 3 additions & 2 deletions src/libutil/util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/nix/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 99c04ce

Please sign in to comment.