const uint8_t k_raw_file_marker = 1;
std::string
-get_raw_file_path(string_view result_path, uint32_t entry_number)
+get_raw_file_path(string_view result_path, uint8_t entry_number)
{
+ if (entry_number >= 10) {
+ // To support more entries in the future, encode to [0-9a-z]. Note that
+ // PrimaryStorage::evict currently assumes that the entry number is
+ // represented as one character.
+ throw core::Error("Too high raw file entry number: {}", entry_number);
+ }
+
const auto prefix = result_path.substr(
0, result_path.length() - Result::k_file_suffix.length());
return FMT("{}{}W", prefix, entry_number);
}
const auto n_entries = m_reader.read_int<uint8_t>();
+ if (n_entries >= 10) {
+ throw core::Error("Too many entries raw file entries: {}", n_entries);
+ }
- uint32_t i;
+ uint8_t i;
for (i = 0; i < n_entries; ++i) {
read_entry(i, consumer);
}
}
void
-Reader::read_entry(uint32_t entry_number, Reader::Consumer& consumer)
+Reader::read_entry(uint8_t entry_number, Reader::Consumer& consumer)
{
const auto marker = m_reader.read_int<uint8_t>();
writer.write_int(k_result_format_version);
writer.write_int<uint8_t>(m_entries_to_write.size());
- uint32_t entry_number = 0;
+ uint8_t entry_number = 0;
for (const auto& entry : m_entries_to_write) {
const bool store_raw =
entry.value_type == ValueType::path
FileSizeAndCountDiff
Result::Writer::write_raw_file_entry(const std::string& path,
- uint32_t entry_number)
+ uint8_t entry_number)
{
const auto raw_file = get_raw_file_path(m_result_path, entry_number);
const auto old_stat = Stat::stat(raw_file);
public:
virtual ~Consumer() = default;
- virtual void on_entry_start(uint32_t entry_number,
+ virtual void on_entry_start(uint8_t entry_number,
FileType file_type,
uint64_t file_len,
nonstd::optional<std::string> raw_file) = 0;
core::CacheEntryReader& m_reader;
const std::string m_result_path;
- void read_entry(uint32_t entry_number, Reader::Consumer& consumer);
+ void read_entry(uint8_t entry_number, Reader::Consumer& consumer);
};
// This class knows how to write a result cache entry.
const std::string& path,
uint64_t file_size);
FileSizeAndCountDiff write_raw_file_entry(const std::string& path,
- uint32_t entry_number);
+ uint8_t entry_number);
};
} // namespace Result
}
void
-ResultExtractor::on_entry_start(uint32_t /*entry_number*/,
+ResultExtractor::on_entry_start(uint8_t /*entry_number*/,
Result::FileType file_type,
uint64_t /*file_len*/,
nonstd::optional<std::string> raw_file)
public:
ResultExtractor(const std::string& directory);
- void on_entry_start(uint32_t entry_number,
+ void on_entry_start(uint8_t entry_number,
Result::FileType file_type,
uint64_t file_len,
nonstd::optional<std::string> raw_file) override;
}
void
-ResultInspector::on_entry_start(uint32_t entry_number,
+ResultInspector::on_entry_start(uint8_t entry_number,
Result::FileType file_type,
uint64_t file_len,
optional<std::string> raw_file)
public:
ResultInspector(FILE* stream);
- void on_entry_start(uint32_t entry_number,
+ void on_entry_start(uint8_t entry_number,
Result::FileType file_type,
uint64_t file_len,
nonstd::optional<std::string> raw_file) override;
}
void
-ResultRetriever::on_entry_start(uint32_t entry_number,
+ResultRetriever::on_entry_start(uint8_t entry_number,
FileType file_type,
uint64_t file_len,
nonstd::optional<std::string> raw_file)
public:
ResultRetriever(Context& ctx, bool rewrite_dependency_target);
- void on_entry_start(uint32_t entry_number,
+ void on_entry_start(uint8_t entry_number,
Result::FileType file_type,
uint64_t file_len,
nonstd::optional<std::string> raw_file) override;