]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Make output of "ccache -k max_size" parsable
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 13 Mar 2023 18:26:50 +0000 (19:26 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 17 Apr 2023 06:27:55 +0000 (08:27 +0200)
src/Config.cpp

index 1707da01dbee263f258e6f2950bb5d842e35f21a..982134e1d99b7b6a0bf287661fb3d5394f404c68 100644 (file)
@@ -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;