From e3fc28a42a8bf3305749919a22127f3a31b3eac2 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 13 Mar 2023 19:26:50 +0100 Subject: [PATCH] fix: Make output of "ccache -k max_size" parsable --- src/Config.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 1707da01d..982134e1d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -246,12 +246,6 @@ format_bool(bool value) return value ? "true" : "false"; } -std::string -format_cache_size(uint64_t value, util::SizeUnitPrefixType prefix_type) -{ - return util::format_human_readable_size(value, prefix_type); -} - CompilerType parse_compiler_type(const std::string& value) { @@ -791,8 +785,15 @@ Config::get_string_value(const std::string& key) const case ConfigItem::max_files: return FMT("{}", m_max_files); - case ConfigItem::max_size: - return format_cache_size(m_max_size, m_size_prefix_type); + case ConfigItem::max_size: { + auto result = + util::format_human_readable_size(m_max_size, m_size_prefix_type); + if (util::ends_with(result, " bytes")) { + // Special case to make the output parsable by util::parse_size. + result.resize(result.size() - 6); + } + return result; + } case ConfigItem::msvc_dep_prefix: return m_msvc_dep_prefix; -- 2.47.3