]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Add --inspect option instead of --dump-manifest/--dump-result
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 24 Jan 2022 19:24:16 +0000 (20:24 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 25 Jan 2022 20:47:23 +0000 (21:47 +0100)
“Inspect” sounds more appropriate than “dump” for viewing metadata of
cache files. Also, it’s convenient to have one option instead of two
different.

17 files changed:
doc/MANUAL.adoc
src/CMakeLists.txt
src/Result.cpp
src/Result.hpp
src/ResultExtractor.cpp
src/ResultExtractor.hpp
src/ResultInspector.cpp [moved from src/ResultDumper.cpp with 59% similarity]
src/ResultInspector.hpp [moved from src/ResultDumper.hpp with 78% similarity]
src/ResultRetriever.cpp
src/ResultRetriever.hpp
src/ccache.cpp
src/core/CacheEntryHeader.cpp
src/core/CacheEntryHeader.hpp
src/core/mainoptions.cpp
test/suites/base.bash
test/suites/direct.bash
test/suites/no_compression.bash

index 06729bbb4db1c026c794010e952e32f53cf1e9c1..558f107a76dbd0fa23ff325da237885eed3e41f1 100644 (file)
@@ -216,21 +216,11 @@ cache directory to a certain size, use `CCACHE_MAXSIZE=_SIZE_ ccache -c`.
     Print the checksum (128 bit XXH3) of the file at _PATH_ (`-` for standard
     input).
 
-*--dump-manifest* _PATH_::
-
-    Dump manifest file at _PATH_ (`-` for standard input) in text format to
-    standard output. This is only useful when debugging ccache and its behavior.
-
-*--dump-result* _PATH_::
-
-    Dump result file at _PATH_ (`-` for standard input) in text format to
-    standard output. This is only useful when debugging ccache and its behavior.
-
 *--extract-result* _PATH_::
 
     Extract data stored in the result file at _PATH_ (`-` for standard input).
     The data will be written to `ccache-result.*` files in to the current
-    working directory. This is only useful when debugging ccache and its
+    working directory. This option is only useful when debugging ccache and its
     behavior.
 
 *-k* _KEY_, *--get-config* _KEY_::
@@ -243,6 +233,14 @@ cache directory to a certain size, use `CCACHE_MAXSIZE=_SIZE_ ccache -c`.
     Print the hash (160 bit BLAKE3) of the file at _PATH_ (`-` for standard
     input). This is only useful when debugging ccache and its behavior.
 
+*--inspect* _PATH_::
+
+    Print the content of a result or manifest file at _PATH_ (`-` for standard
+    input) to standard output in human-readable format. File content embedded in
+    a result file will however not be printed; use `--extract-result` to extract
+    the file content. This option is only useful when debugging ccache and its
+    behavior.
+
 *--print-stats*::
 
     Print statistics counter IDs and corresponding values in machine-parsable
index 1dc6bdbddaded75a9683ead3272b5ea7b4a33ef8..8fb4dd607faddd6a5d1caa582bbf9c6f1fb3918f 100644 (file)
@@ -11,8 +11,8 @@ set(
   Logging.cpp
   ProgressBar.cpp
   Result.cpp
-  ResultDumper.cpp
   ResultExtractor.cpp
+  ResultInspector.cpp
   ResultRetriever.cpp
   SignalHandler.cpp
   Stat.cpp
index f03e6d152c003efd82fadb0238bd8cddc10d2f45..35ac7f7147a4b43e50ad7b531d1136aafcb3e999 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -188,75 +188,45 @@ FileSizeAndCountDiff::operator+=(const FileSizeAndCountDiff& other)
   return *this;
 }
 
-Result::Reader::Reader(const std::string& result_path)
-  : m_result_path(result_path)
+Result::Reader::Reader(core::CacheEntryReader& cache_entry_reader,
+                       const std::string& result_path)
+  : m_reader(cache_entry_reader),
+    m_result_path(result_path)
 {
 }
 
-optional<std::string>
-Result::Reader::read(Consumer& consumer)
-{
-  LOG("Reading result {}", m_result_path);
-
-  try {
-    if (read_result(consumer)) {
-      return nullopt;
-    } else {
-      return "No such result file";
-    }
-  } catch (const core::Error& e) {
-    return e.what();
-  }
-}
-
-bool
-Reader::read_result(Consumer& consumer)
+void
+Reader::read(Consumer& consumer)
 {
-  FILE* file_stream;
-  File file;
-  if (m_result_path == "-") {
-    file_stream = stdin;
-  } else {
-    file = File(m_result_path, "rb");
-    if (!file) {
-      // Cache miss.
-      return false;
-    }
-    file_stream = file.get();
+  if (m_reader.header().entry_type != core::CacheEntryType::result) {
+    throw core::Error("Unexpected cache entry type: {}",
+                      to_string(m_reader.header().entry_type));
   }
 
-  core::FileReader file_reader(file_stream);
-  core::CacheEntryReader cache_entry_reader(file_reader);
-
-  const auto result_format_version = cache_entry_reader.read_int<uint8_t>();
+  const auto result_format_version = m_reader.read_int<uint8_t>();
   if (result_format_version != k_result_format_version) {
     throw core::Error("Unknown result format version: {}",
                       result_format_version);
   }
 
-  consumer.on_header(cache_entry_reader, result_format_version);
-
-  const auto n_entries = cache_entry_reader.read_int<uint8_t>();
+  const auto n_entries = m_reader.read_int<uint8_t>();
 
   uint32_t i;
   for (i = 0; i < n_entries; ++i) {
-    read_entry(cache_entry_reader, i, consumer);
+    read_entry(i, consumer);
   }
 
   if (i != n_entries) {
     throw core::Error("Too few entries (read {}, expected {})", i, n_entries);
   }
 
-  cache_entry_reader.finalize();
-  return true;
+  m_reader.finalize();
 }
 
 void
-Reader::read_entry(core::CacheEntryReader& cache_entry_reader,
-                   uint32_t entry_number,
-                   Reader::Consumer& consumer)
+Reader::read_entry(uint32_t entry_number, Reader::Consumer& consumer)
 {
-  const auto marker = cache_entry_reader.read_int<uint8_t>();
+  const auto marker = m_reader.read_int<uint8_t>();
 
   switch (marker) {
   case k_embedded_file_marker:
@@ -267,9 +237,9 @@ Reader::read_entry(core::CacheEntryReader& cache_entry_reader,
     throw core::Error("Unknown entry type: {}", marker);
   }
 
-  const auto type = cache_entry_reader.read_int<UnderlyingFileTypeInt>();
+  const auto type = m_reader.read_int<UnderlyingFileTypeInt>();
   const auto file_type = FileType(type);
-  const auto file_len = cache_entry_reader.read_int<uint64_t>();
+  const auto file_len = m_reader.read_int<uint64_t>();
 
   if (marker == k_embedded_file_marker) {
     consumer.on_entry_start(entry_number, file_type, file_len, nullopt);
@@ -278,21 +248,24 @@ Reader::read_entry(core::CacheEntryReader& cache_entry_reader,
     size_t remain = file_len;
     while (remain > 0) {
       size_t n = std::min(remain, sizeof(buf));
-      cache_entry_reader.read(buf, n);
+      m_reader.read(buf, n);
       consumer.on_entry_data(buf, n);
       remain -= n;
     }
   } else {
     ASSERT(marker == k_raw_file_marker);
 
-    auto raw_path = get_raw_file_path(m_result_path, entry_number);
-    auto st = Stat::stat(raw_path, Stat::OnError::throw_error);
-    if (st.size() != file_len) {
-      throw core::Error(
-        "Bad file size of {} (actual {} bytes, expected {} bytes)",
-        raw_path,
-        st.size(),
-        file_len);
+    std::string raw_path;
+    if (m_result_path != "-") {
+      raw_path = get_raw_file_path(m_result_path, entry_number);
+      auto st = Stat::stat(raw_path, Stat::OnError::throw_error);
+      if (st.size() != file_len) {
+        throw core::Error(
+          "Bad file size of {} (actual {} bytes, expected {} bytes)",
+          raw_path,
+          st.size(),
+          file_len);
+      }
     }
 
     consumer.on_entry_start(entry_number, file_type, file_len, raw_path);
index 67aadd1c24798340a1c896e0e9abc83109625482..d691ba616062750c969b6ed9389032981a188e35 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,6 +18,8 @@
 
 #pragma once
 
+#include <core/Reader.hpp>
+
 #include "third_party/nonstd/expected.hpp"
 #include "third_party/nonstd/optional.hpp"
 
@@ -99,15 +101,14 @@ struct FileSizeAndCountDiff
 class Reader
 {
 public:
-  Reader(const std::string& result_path);
+  Reader(core::CacheEntryReader& cache_entry_reader,
+         const std::string& result_path);
 
   class Consumer
   {
   public:
     virtual ~Consumer() = default;
 
-    virtual void on_header(core::CacheEntryReader& cache_entry_reader,
-                           uint8_t result_format_version) = 0;
     virtual void on_entry_start(uint32_t entry_number,
                                 FileType file_type,
                                 uint64_t file_len,
@@ -116,16 +117,14 @@ public:
     virtual void on_entry_end() = 0;
   };
 
-  // Returns error message on error, otherwise nonstd::nullopt.
-  nonstd::optional<std::string> read(Consumer& consumer);
+  // Throws core::Error on error.
+  void read(Consumer& consumer);
 
 private:
+  core::CacheEntryReader& m_reader;
   const std::string m_result_path;
 
-  bool read_result(Consumer& consumer);
-  void read_entry(core::CacheEntryReader& cache_entry_reader,
-                  uint32_t entry_number,
-                  Reader::Consumer& consumer);
+  void read_entry(uint32_t entry_number, Reader::Consumer& consumer);
 };
 
 // This class knows how to write a result cache entry.
index dcbf28b43196202f980584ae60f8d6beaeae5141..84df13611f0546b1188042739d531e55657b1f5a 100644 (file)
@@ -33,12 +33,6 @@ ResultExtractor::ResultExtractor(const std::string& directory)
 {
 }
 
-void
-ResultExtractor::on_header(core::CacheEntryReader& /*cache_entry_reader*/,
-                           const uint8_t /*result_format_version*/)
-{
-}
-
 void
 ResultExtractor::on_entry_start(uint32_t /*entry_number*/,
                                 Result::FileType file_type,
@@ -63,6 +57,9 @@ ResultExtractor::on_entry_start(uint32_t /*entry_number*/,
       throw core::Error(
         "Failed to open {} for writing: {}", m_dest_path, strerror(errno));
     }
+  } else if (raw_file->empty()) {
+    PRINT_RAW(stderr,
+              "Note: Can't extract raw file since reading from stdin\n");
   } else {
     try {
       Util::copy_file(*raw_file, m_dest_path, false);
index 4ee2a3a9ba8a3cf6d175fc6089758d35fc86263e..9f2ffc1e9aae871b533df32cf145b208e92d2c99 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -29,8 +29,6 @@ class ResultExtractor : public Result::Reader::Consumer
 public:
   ResultExtractor(const std::string& directory);
 
-  void on_header(core::CacheEntryReader& cache_entry_reader,
-                 uint8_t result_format_version) override;
   void on_entry_start(uint32_t entry_number,
                       Result::FileType file_type,
                       uint64_t file_len,
similarity index 59%
rename from src/ResultDumper.cpp
rename to src/ResultInspector.cpp
index 220ca2228b140750901ca5590a384686fcb60eb0..49a3370ac1352811a98a4f202b2ef53b350d5369 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-#include "ResultDumper.hpp"
+#include "ResultInspector.hpp"
 
 #include "Context.hpp"
 #include "Logging.hpp"
 #include "fmtmacros.hpp"
 
-#include <core/CacheEntryReader.hpp>
-
 using nonstd::optional;
 
-ResultDumper::ResultDumper(FILE* stream) : m_stream(stream)
-{
-}
-
-void
-ResultDumper::on_header(core::CacheEntryReader& cache_entry_reader,
-                        const uint8_t result_format_version)
+ResultInspector::ResultInspector(FILE* stream) : m_stream(stream)
 {
-  cache_entry_reader.header().dump(m_stream);
-  PRINT(m_stream, "Result format version: {}\n", result_format_version);
 }
 
 void
-ResultDumper::on_entry_start(uint32_t entry_number,
-                             Result::FileType file_type,
-                             uint64_t file_len,
-                             optional<std::string> raw_file)
+ResultInspector::on_entry_start(uint32_t entry_number,
+                                Result::FileType file_type,
+                                uint64_t file_len,
+                                optional<std::string> raw_file)
 {
   PRINT(m_stream,
         "{} file #{}: {} ({} bytes)\n",
@@ -53,11 +43,11 @@ ResultDumper::on_entry_start(uint32_t entry_number,
 }
 
 void
-ResultDumper::on_entry_data(const uint8_t* /*data*/, size_t /*size*/)
+ResultInspector::on_entry_data(const uint8_t* /*data*/, size_t /*size*/)
 {
 }
 
 void
-ResultDumper::on_entry_end()
+ResultInspector::on_entry_end()
 {
 }
similarity index 78%
rename from src/ResultDumper.hpp
rename to src/ResultInspector.hpp
index 0274efaf4afb67d9cbec884e9969f4e3f5399140..98d725cb513b196dbbe0b064e90caa63aefdd354 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 #include <cstdint>
 #include <cstdio>
 
-// This class dumps information about the result entry to `stream`.
-class ResultDumper : public Result::Reader::Consumer
+// This class writes information about the result entry to `stream`.
+class ResultInspector : public Result::Reader::Consumer
 {
 public:
-  ResultDumper(FILE* stream);
+  ResultInspector(FILE* stream);
 
-  void on_header(core::CacheEntryReader& cache_entry_reader,
-                 uint8_t result_format_version) override;
   void on_entry_start(uint32_t entry_number,
                       Result::FileType file_type,
                       uint64_t file_len,
index 54b1f50b9c78d823bc090021b7eedf89d45d1aee..576038c3772d09ced280a6380b03aa17bc5f7603 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -41,12 +41,6 @@ ResultRetriever::ResultRetriever(Context& ctx, bool rewrite_dependency_target)
 {
 }
 
-void
-ResultRetriever::on_header(core::CacheEntryReader& /*cache_entry_reader*/,
-                           const uint8_t /*result_format_version*/)
-{
-}
-
 void
 ResultRetriever::on_entry_start(uint32_t entry_number,
                                 FileType file_type,
index 3924965ab891b53d2fd98ca662b4f28defd2e693..3edfc69ec0670264e07c739fce13cd0384a532f9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -29,8 +29,6 @@ class ResultRetriever : public Result::Reader::Consumer
 public:
   ResultRetriever(Context& ctx, bool rewrite_dependency_target);
 
-  void on_header(core::CacheEntryReader& cache_entry_reader,
-                 uint8_t result_format_version) override;
   void on_entry_start(uint32_t entry_number,
                       Result::FileType file_type,
                       uint64_t file_len,
index 51da46b6650950b68c0c02f0c5836237529613b0..0d2664caa2747a966f721657829364e33a02d356 100644 (file)
@@ -1844,13 +1844,17 @@ from_cache(Context& ctx, FromCacheCallMode mode, const Digest& result_key)
     return false;
   }
 
-  Result::Reader result_reader(*result_path);
+  File file(*result_path, "rb");
+  core::FileReader file_reader(file.get());
+  core::CacheEntryReader cache_entry_reader(file_reader);
+  Result::Reader result_reader(cache_entry_reader, *result_path);
   ResultRetriever result_retriever(
     ctx, should_rewrite_dependency_target(ctx.args_info));
 
-  auto error = result_reader.read(result_retriever);
-  if (error) {
-    LOG("Failed to get result from cache: {}", *error);
+  try {
+    result_reader.read(result_retriever);
+  } catch (core::Error& e) {
+    LOG("Failed to get result from cache: {}", e.what());
     return false;
   }
 
index c0ec49c6a91b441a563f6873838783006b26d3f2..e9cf93b85661afb737d82260c52602c8032dac5a 100644 (file)
@@ -70,7 +70,7 @@ CacheEntryHeader::set_entry_size_from_payload_size(const uint64_t payload_size)
 }
 
 void
-CacheEntryHeader::dump(FILE* const stream) const
+CacheEntryHeader::inspect(FILE* const stream) const
 {
   PRINT(stream, "Magic: {:04x}\n", magic);
   PRINT(stream, "Entry format version: {}\n", entry_format_version);
index 01fc0bdd53853ab1f216449e4bb411a6cb134538..4c3e04c737d0a82ada52a278d77a058a3d1ef137 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -76,7 +76,7 @@ struct CacheEntryHeader
 
   uint64_t payload_size() const;
   void set_entry_size_from_payload_size(uint64_t payload_size);
-  void dump(FILE* stream) const;
+  void inspect(FILE* stream) const;
 
 private:
   size_t non_payload_size() const;
index 868e9c6dcc91dc4174f933ea29754608fde5c12f..ead5a3aa27e512ffdb544a4cb8a567048f06ad5e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -24,8 +24,9 @@
 #include <Hash.hpp>
 #include <InodeCache.hpp>
 #include <ProgressBar.hpp>
-#include <ResultDumper.hpp>
+#include <Result.hpp>
 #include <ResultExtractor.hpp>
+#include <ResultInspector.hpp>
 #include <ccache.hpp>
 #include <core/CacheEntryReader.hpp>
 #include <core/FileReader.hpp>
@@ -133,13 +134,13 @@ Options for secondary storage:
 Options for scripting or debugging:
         --checksum-file PATH   print the checksum (128 bit XXH3) of the file at
                                PATH
-        --dump-manifest PATH   dump manifest file at PATH in text format
-        --dump-result PATH     dump result file at PATH in text format
-        --extract-result PATH  extract data stored in result file at PATH to the
-                               current working directory
+        --extract-result PATH  extract file data stored in result file at PATH
+                               to the current working directory
     -k, --get-config KEY       print the value of configuration key KEY
         --hash-file PATH       print the hash (160 bit BLAKE3) of the file at
                                PATH
+        --inspect PATH         print result/manifest file at PATH in
+                               human-readable format
         --print-stats          print statistics counter IDs and corresponding
                                values in machine-parsable format
 
@@ -154,6 +155,38 @@ configuration_printer(const std::string& key,
   PRINT(stdout, "({}) {} = {}\n", origin, key, value);
 }
 
+static int
+inspect_path(const std::string& path)
+{
+  File file = path == "-" ? File(stdin) : File(path, "rb");
+  if (!file) {
+    PRINT(stderr, "Error: Failed to open \"{}\"", path);
+    return EXIT_FAILURE;
+  }
+  core::FileReader file_reader(file.get());
+  core::CacheEntryReader cache_entry_reader(file_reader);
+
+  const auto& header = cache_entry_reader.header();
+  header.inspect(stdout);
+
+  switch (header.entry_type) {
+  case core::CacheEntryType::manifest: {
+    core::Manifest manifest;
+    manifest.read(cache_entry_reader);
+    cache_entry_reader.finalize();
+    manifest.dump(stdout);
+    break;
+  }
+  case core::CacheEntryType::result:
+    Result::Reader result_reader(cache_entry_reader, path);
+    ResultInspector result_inspector(stdout);
+    result_reader.read(result_inspector);
+    break;
+  }
+
+  return EXIT_SUCCESS;
+}
+
 static void
 print_compression_statistics(const storage::primary::CompressionStatistics& cs)
 {
@@ -270,6 +303,7 @@ enum {
   EVICT_OLDER_THAN,
   EXTRACT_RESULT,
   HASH_FILE,
+  INSPECT,
   PRINT_STATS,
   SHOW_LOG_STATS,
   TRIM_DIR,
@@ -284,15 +318,16 @@ const option long_options[] = {
   {"clear", no_argument, nullptr, 'C'},
   {"config-path", required_argument, nullptr, CONFIG_PATH},
   {"dir", required_argument, nullptr, 'd'},
-  {"directory", required_argument, nullptr, 'd'}, // backward compatibility
-  {"dump-manifest", required_argument, nullptr, DUMP_MANIFEST},
-  {"dump-result", required_argument, nullptr, DUMP_RESULT},
+  {"directory", required_argument, nullptr, 'd'},               // bwd compat
+  {"dump-manifest", required_argument, nullptr, DUMP_MANIFEST}, // bwd compat
+  {"dump-result", required_argument, nullptr, DUMP_RESULT},     // bwd compat
   {"evict-namespace", required_argument, nullptr, EVICT_NAMESPACE},
   {"evict-older-than", required_argument, nullptr, EVICT_OLDER_THAN},
   {"extract-result", required_argument, nullptr, EXTRACT_RESULT},
   {"get-config", required_argument, nullptr, 'k'},
   {"hash-file", required_argument, nullptr, HASH_FILE},
   {"help", no_argument, nullptr, 'h'},
+  {"inspect", required_argument, nullptr, INSPECT},
   {"max-files", required_argument, nullptr, 'F'},
   {"max-size", required_argument, nullptr, 'M'},
   {"print-stats", no_argument, nullptr, PRINT_STATS},
@@ -388,30 +423,6 @@ process_main_options(int argc, const char* const* argv)
       break;
     }
 
-    case DUMP_MANIFEST: {
-      File file(arg, "rb");
-      if (!file) {
-        throw Fatal("No such file: {}", arg);
-      }
-      core::FileReader file_reader(*file);
-      core::CacheEntryReader reader(file_reader);
-      core::Manifest manifest;
-      manifest.read(reader);
-      reader.finalize();
-      manifest.dump(stdout);
-      return 0;
-    }
-
-    case DUMP_RESULT: {
-      ResultDumper result_dumper(stdout);
-      Result::Reader result_reader(arg);
-      auto error = result_reader.read(result_dumper);
-      if (error) {
-        PRINT(stderr, "Error: {}\n", *error);
-      }
-      return error ? EXIT_FAILURE : EXIT_SUCCESS;
-    }
-
     case EVICT_NAMESPACE: {
       evict_namespace = arg;
       break;
@@ -424,12 +435,16 @@ process_main_options(int argc, const char* const* argv)
 
     case EXTRACT_RESULT: {
       ResultExtractor result_extractor(".");
-      Result::Reader result_reader(arg);
-      auto error = result_reader.read(result_extractor);
-      if (error) {
-        PRINT(stderr, "Error: {}\n", *error);
+      File file = arg == "-" ? File(stdin) : File(arg, "rb");
+      if (!file) {
+        PRINT(stderr, "Error: Failed to open \"{}\"", arg);
+        return EXIT_FAILURE;
       }
-      return error ? EXIT_FAILURE : EXIT_SUCCESS;
+      core::FileReader file_reader(file.get());
+      core::CacheEntryReader cache_entry_reader(file_reader);
+      Result::Reader result_reader(cache_entry_reader, arg);
+      result_reader.read(result_extractor);
+      return EXIT_SUCCESS;
     }
 
     case HASH_FILE: {
@@ -443,6 +458,11 @@ process_main_options(int argc, const char* const* argv)
       break;
     }
 
+    case INSPECT:
+    case DUMP_MANIFEST: // Backward compatibility
+    case DUMP_RESULT:   // Backward compatibility
+      return inspect_path(arg);
+
     case PRINT_STATS: {
       StatisticsCounters counters;
       time_t last_updated;
index 65122591411f46a508e70e8582062f7361b491fc..08f17e475218bbd72fd4c39ccb8aae7e3bdb20c8 100644 (file)
@@ -306,7 +306,7 @@ fi
 
     $CCACHE_COMPILE -c test1.c
     result_file=$(find $CCACHE_DIR -name '*R')
-    if ! $CCACHE --dump-result $result_file | grep 'Compression type: zstd' >/dev/null 2>&1; then
+    if ! $CCACHE --inspect $result_file | grep 'Compression type: zstd' >/dev/null 2>&1; then
         test_failed "Result file not uncompressed according to metadata"
     fi
     if [ $(file_size $result_file) -ge $(file_size test1.o) ]; then
index be62f1f4588d01884a69b92cd66405a7adef8a20..deadb2a98ecd9ebf22c6f6f99f0eae686ec4f4e6 100644 (file)
@@ -1029,19 +1029,19 @@ EOF
 
     manifest=`find $CCACHE_DIR -name '*M'`
     if [ -n "$manifest" ]; then
-        data="`$CCACHE --dump-manifest $manifest | egrep '/dev/(stdout|tty|sda|hda'`"
+        data="`$CCACHE --inspect $manifest | egrep '/dev/(stdout|tty|sda|hda'`"
         if [ -n "$data" ]; then
             test_failed "$manifest contained troublesome file(s): $data"
         fi
     fi
 
     # -------------------------------------------------------------------------
-    TEST "--dump-manifest"
+    TEST "--inspect"
 
     $CCACHE_COMPILE test.c -c -o test.o
 
     manifest=`find $CCACHE_DIR -name '*M'`
-    $CCACHE --dump-manifest $manifest >manifest.dump
+    $CCACHE --inspect $manifest >manifest.dump
 
     checksum_test1_h='b7273h0ksdehi0o4pitg5jeehal3i54ns'
     checksum_test2_h='24f1315jch5tcndjbm6uejtu8q3lf9100'
@@ -1052,7 +1052,7 @@ EOF
        grep "Hash: $checksum_test3_h" manifest.dump >/dev/null 2>&1; then
         : OK
     else
-        test_failed "Unexpected output of --dump-manifest"
+        test_failed "Unexpected output of --inspect"
     fi
 
     # -------------------------------------------------------------------------
@@ -1092,7 +1092,7 @@ EOF
 
     CCACHE_IGNOREHEADERS="subdir/ignore.h" $CCACHE_COMPILE -c ignore.c
     manifest=`find $CCACHE_DIR -name '*M'`
-    data="`$CCACHE --dump-manifest $manifest | grep subdir/ignore.h`"
+    data="`$CCACHE --inspect $manifest | grep subdir/ignore.h`"
     if [ -n "$data" ]; then
         test_failed "$manifest contained ignored header: $data"
     fi
@@ -1112,7 +1112,7 @@ EOF
 
     CCACHE_IGNOREHEADERS="subdir" $CCACHE_COMPILE -c ignore.c
     manifest=`find $CCACHE_DIR -name '*M'`
-    data="`$CCACHE --dump-manifest $manifest | grep subdir/ignore.h`"
+    data="`$CCACHE --inspect $manifest | grep subdir/ignore.h`"
     if [ -n "$data" ]; then
         test_failed "$manifest contained ignored header: $data"
     fi
index d690b19e14d72cf0df5fad2c40ef4765efa7452b..820a13d1ed4b048944c6fb16c5747c899f7ee8fc 100644 (file)
@@ -28,7 +28,7 @@ SUITE_no_compression() {
 
     $CCACHE_COMPILE -c test.c
     result_file=$(find $CCACHE_DIR -name '*R')
-    if ! $CCACHE --dump-result $result_file | grep 'Compression type: none' >/dev/null 2>&1; then
+    if ! $CCACHE --inspect $result_file | grep 'Compression type: none' >/dev/null 2>&1; then
         test_failed "Result file not uncompressed according to metadata"
     fi
     if [ $(file_size $result_file) -le $(file_size test.o) ]; then