}
file_digest = *ret;
cpp_hash.hash_delimiter(using_pch_sum ? "pch_sum_hash" : "pch_hash");
- cpp_hash.hash(util::format_legacy_digest(file_digest));
+ cpp_hash.hash(util::format_base16(file_digest));
}
if (ctx.config.direct_mode()) {
if (depend_mode_hash) {
depend_mode_hash->hash_delimiter("include");
- depend_mode_hash->hash(util::format_legacy_digest(file_digest));
+ depend_mode_hash->hash(util::format_base16(file_digest));
}
}
LOG("Added result key to manifest {}", util::format_base16(manifest_key));
core::CacheEntry::Header header(ctx.config, core::CacheEntryType::manifest);
ctx.storage.put(manifest_key,
- core::CacheEntryType::manifest,
core::CacheEntry::serialize(header, ctx.manifest));
} else {
LOG("Did not add result key to manifest {}",
}
}
- ctx.storage.put(result_key, core::CacheEntryType::result, cache_entry_data);
+ ctx.storage.put(result_key, cache_entry_data);
return true;
}
// Direct mode was disabled by hash_source_code_file.
return {};
}
- hash.hash(util::format_legacy_digest(*input_file_digest));
+ hash.hash(util::format_base16(*input_file_digest));
return hash.digest();
}
util::format_base16(manifest_key));
core::CacheEntry::Header header(ctx.config, core::CacheEntryType::manifest);
ctx.storage.local.put(manifest_key,
- core::CacheEntryType::manifest,
core::CacheEntry::serialize(header, ctx.manifest),
storage::Overwrite::yes);
}
LOG("Hash from manifest doesn't match preprocessor output");
LOG("Likely reason: different CCACHE_BASEDIRs used");
LOG("Removing manifest as a safety measure");
- ctx.storage.remove(*manifest_key, core::CacheEntryType::manifest);
+ ctx.storage.remove(*manifest_key);
put_result_in_manifest = true;
}
// expansions.
Hash hash;
- hash.hash(util::format_legacy_digest(digest));
+ hash.hash(util::format_base16(digest));
if (result.contains(SourceCodeScan::found_date)) {
hash.hash_delimiter("date");
{
const auto result = hash_binary_file(ctx, path);
if (result) {
- hash.hash(util::format_legacy_digest(*result));
+ hash.hash(util::format_base16(*result));
}
return result.has_value();
}
{
std::optional<util::Bytes> return_value;
- const auto cache_file = look_up_cache_file(key, type);
+ const auto cache_file = look_up_cache_file(key);
if (cache_file.dir_entry.is_regular_file()) {
const auto value = util::read_file<util::Bytes>(cache_file.path);
if (value) {
void
LocalStorage::put(const Hash::Digest& key,
- const core::CacheEntryType type,
std::span<const uint8_t> value,
Overwrite overwrite)
{
- const auto cache_file = look_up_cache_file(key, type);
+ const auto cache_file = look_up_cache_file(key);
if (overwrite == Overwrite::no && cache_file.dir_entry.exists()) {
LOG("Not storing {} in local storage since it already exists",
cache_file.path);
}
void
-LocalStorage::remove(const Hash::Digest& key, const core::CacheEntryType type)
+LocalStorage::remove(const Hash::Digest& key)
{
- const auto cache_file = look_up_cache_file(key, type);
+ const auto cache_file = look_up_cache_file(key);
if (!cache_file.dir_entry) {
LOG("No {} to remove from local storage", util::format_base16(key));
return;
LocalStorage::get_raw_file_path(const Hash::Digest& result_key,
uint8_t file_number) const
{
- const auto cache_file =
- look_up_cache_file(result_key, core::CacheEntryType::result);
+ const auto cache_file = look_up_cache_file(result_key);
return get_raw_file_path(cache_file.path, file_number);
}
FMT("Too many raw files: {} > {}", raw_files.size(), k_max_raw_files));
}
- const auto cache_file = look_up_cache_file(key, core::CacheEntryType::result);
+ const auto cache_file = look_up_cache_file(key);
core::ensure_dir_exists(cache_file.path.parent_path());
int64_t files_change = 0;
}
LocalStorage::LookUpCacheFileResult
-LocalStorage::look_up_cache_file(const Hash::Digest& key,
- const core::CacheEntryType type) const
+LocalStorage::look_up_cache_file(const Hash::Digest& key) const
{
- // Try new format first: base16 without suffix
const auto key_string = util::format_base16(key);
for (uint8_t level = k_min_cache_levels; level <= k_max_cache_levels;
}
}
- // Try old format with R/M suffix
- const auto old_key_string = util::format_legacy_digest(key);
- const std::string old_suffix =
- type == core::CacheEntryType::manifest ? "M" : "R";
- const auto old_key_string_with_suffix = old_key_string + old_suffix;
- for (uint8_t level = k_min_cache_levels; level <= k_max_cache_levels;
- ++level) {
- const auto path = get_path_in_cache(level, old_key_string_with_suffix);
- DirEntry dir_entry(path);
- if (dir_entry.is_regular_file()) {
- const auto new_path = get_path_in_cache(level, key_string);
- LOG("Migrating {} to {}", path, new_path);
- if (fs::rename(path, new_path)) {
- return {new_path, DirEntry(new_path), level};
- } else {
- LOG("Failed to rename {} to {}", path, new_path);
- return {path, dir_entry, level};
- }
- }
- }
-
const auto shallowest_path =
get_path_in_cache(k_min_cache_levels, key_string);
return {shallowest_path, DirEntry(), k_min_cache_levels};
core::CacheEntryType type);
void put(const Hash::Digest& key,
- core::CacheEntryType type,
std::span<const uint8_t> value,
Overwrite overwrite);
- void remove(const Hash::Digest& key, core::CacheEntryType type);
+ void remove(const Hash::Digest& key);
static std::filesystem::path
get_raw_file_path(const std::filesystem::path& result_path,
uint8_t level;
};
- LookUpCacheFileResult look_up_cache_file(const Hash::Digest& key,
- core::CacheEntryType type) const;
+ LookUpCacheFileResult look_up_cache_file(const Hash::Digest& key) const;
std::filesystem::path get_subdir(uint8_t l1_index) const;
std::filesystem::path get_subdir(uint8_t l1_index, uint8_t l2_index) const;
get_from_remote_storage(key, type, [&](util::Bytes&& data) {
if (!m_config.remote_only()) {
- local.put(key, type, data, Overwrite::no);
+ local.put(key, data, Overwrite::no);
}
return entry_receiver(std::move(data));
});
}
void
-Storage::put(const Hash::Digest& key,
- const core::CacheEntryType type,
- std::span<const uint8_t> value)
+Storage::put(const Hash::Digest& key, std::span<const uint8_t> value)
{
if (!m_config.remote_only()) {
- local.put(key, type, value, Overwrite::yes);
+ local.put(key, value, Overwrite::yes);
}
put_in_remote_storage(key, value, Overwrite::yes);
}
void
-Storage::remove(const Hash::Digest& key, const core::CacheEntryType type)
+Storage::remove(const Hash::Digest& key)
{
if (!m_config.remote_only()) {
- local.remove(key, type);
+ local.remove(key);
}
remove_from_remote_storage(key);
}
core::CacheEntryType type,
const EntryReceiver& entry_receiver);
- void put(const Hash::Digest& key,
- core::CacheEntryType type,
- std::span<const uint8_t> value);
+ void put(const Hash::Digest& key, std::span<const uint8_t> value);
- void remove(const Hash::Digest& key, core::CacheEntryType type);
+ void remove(const Hash::Digest& key);
void stop_remote_storage_helpers();
return result;
}
-std::string
-format_base32hex(std::span<const uint8_t> data)
-{
- static const char digits[] = "0123456789abcdefghijklmnopqrstuv";
- std::string result;
- result.reserve(data.size() * 8 / 5 + 1);
- uint8_t i = 0;
- uint16_t bits = 0;
- for (uint8_t b : data) {
- bits <<= 8;
- bits |= b;
- i += 8;
- while (i >= 5) {
- result += digits[(bits >> (i - 5)) & 0x1f];
- i -= 5;
- }
- }
- if (i > 0) {
- DEBUG_ASSERT(i < 5);
- result += digits[(bits << (5 - i)) & 0x1f];
- }
- return result;
-}
-
-std::string
-format_legacy_digest(std::span<const uint8_t> data)
-{
- const size_t base16_bytes = 2;
- ASSERT(data.size() >= base16_bytes);
- return format_base16({data.data(), base16_bytes})
- + format_base32hex(
- {data.data() + base16_bytes, data.size() - base16_bytes});
-}
-
std::string
format_duration(std::chrono::milliseconds ms)
{
// `2 * data.size()` long.
std::string format_base16(std::span<const uint8_t> data);
-// Format a lowercase base32hex string representing `data`. No padding
-// characters will be added.
-std::string format_base32hex(std::span<const uint8_t> data);
-
// Format `ms` as a duration string.
std::string format_duration(std::chrono::milliseconds ms);
std::string format_human_readable_diff(int64_t diff,
SizeUnitPrefixType prefix_type);
-// Format a hash digest representing `data`.
-//
-// The first two bytes are encoded as four lowercase base16 digits to maintain
-// compatibility with the cleanup algorithm in older ccache versions and to
-// allow for up to four uniform cache levels. The rest are encoded as lowercase
-// base32hex digits without padding characters.
-std::string format_legacy_digest(std::span<const uint8_t> data);
-
// Format `size` as a human-readable string.
std::string format_human_readable_size(uint64_t size,
SizeUnitPrefixType prefix_type);
}
}
-TEST_CASE("util::format_base32hex")
-{
- // Test vectors (without padding) from RFC 4648.
- const uint8_t input[] = {'f', 'o', 'o', 'b', 'a', 'r'};
- CHECK(util::format_base32hex({input, 0}) == "");
- CHECK(util::format_base32hex({input, 1}) == "co");
- CHECK(util::format_base32hex({input, 2}) == "cpng");
- CHECK(util::format_base32hex({input, 3}) == "cpnmu");
- CHECK(util::format_base32hex({input, 4}) == "cpnmuog");
- CHECK(util::format_base32hex({input, 5}) == "cpnmuoj1");
- CHECK(util::format_base32hex({input, 6}) == "cpnmuoj1e8");
-}
-
TEST_CASE("util::format_human_readable_diff")
{
using SUPT = util::SizeUnitPrefixType;