15#include <fmt/format.h>
34 fstream stream{path.
c_str(), std::ios_base::in | std::ios_base::binary};
35 stream.seekg(0, std::ios_base::end);
36 const int64_t size = stream.tellg();
37 stream.seekg(0, std::ios_base::beg);
40 stream.read(buffer.
data(), size);
50 const std::optional<Vector<char>> buffer =
read_file(path);
54 return XXH3_128bits(buffer->data(), buffer->size());
72 const XXH128_hash_t
hash = XXH3_128bits(
data, size);
115 std::lock_guard
lock(mutex);
117 if (cached_hash->last_modified == stat.st_mtime) {
118 return cached_hash->hash;
124 if (
id.runtime->src_blend_modifification_time != 0) {
125 if (stat.st_mtime !=
id.runtime->src_blend_modifification_time) {
148 XXH3_state_t *hash_state = XXH3_createState();
149 XXH3_128bits_reset(hash_state);
150 XXH3_128bits_update(hash_state, id_name.
data(), id_name.
size());
151 XXH3_128bits_update(hash_state, &*file_hash,
sizeof(XXH128_hash_t));
152 XXH128_hash_t shallow_hash = XXH3_128bits_digest(hash_state);
153 XXH3_freeState(hash_state);
166 if (!
id.deep_hash.is_null()) {
167 r_hashes.
add(&
id,
id.deep_hash);
170 current_stack.
add(&
id);
173 if (!id_shallow_hash) {
177 XXH3_state_t *hash_state = XXH3_createState();
179 XXH3_128bits_reset(hash_state);
180 XXH3_128bits_update(hash_state, &*id_shallow_hash,
sizeof(XXH128_hash_t));
184 const_cast<Main *
>(&bmain),
185 const_cast<ID *
>(&
id),
204 if (!referenced_id) {
207 const int random_data = 452942579;
208 XXH3_128bits_update(hash_state, &random_data,
sizeof(
int));
213 if (current_stack.
contains(referenced_id)) {
215 const int random_data = 234632342;
216 XXH3_128bits_update(hash_state, &random_data,
sizeof(
int));
221 if (!referenced_id_hash) {
225 XXH3_128bits_update(hash_state, referenced_id_hash->
data,
sizeof(
IDHash));
235 const XXH128_hash_t new_deep_hash_xxh128 = XXH3_128bits_digest(hash_state);
236 static_assert(
sizeof(
IDHash) ==
sizeof(XXH128_hash_t));
237 memcpy(new_deep_hash.
data, &new_deep_hash_xxh128,
sizeof(
IDHash));
238 r_hashes.
add(&
id, new_deep_hash);
244 for (
const ID *
id : ids) {
256 for (
const ID *
id : ids) {
271 hex_str += fmt::format(
"{:02x}",
byte);
File and directory operations.
#define BLI_SCOPED_DEFER(function_to_defer)
#define ID_IS_LINKED(_id)
const Value * lookup_ptr(const Key &key) const
bool add_overwrite(const Key &key, const Value &value)
bool add(const Key &key, const Value &value)
const Value * lookup_ptr_as(const ForwardKey &key) const
bool contains(const Key &key) const
bool contains(const Key &key) const
bool remove(const Key &key)
constexpr bool is_empty() const
constexpr const char * c_str() const
bool add_as(ForwardKey &&key)
constexpr int64_t size() const
constexpr const char * data() const
static std::optional< XXH128_hash_t > get_source_file_hash(const ID &id, DeepHashErrors &r_errors)
static std::optional< XXH128_hash_t > compute_file_hash_with_file_read(const StringRefNull path)
static void compute_deep_hash_recursive(const Main &bmain, const ID &id, Set< const ID * > ¤t_stack, Map< const ID *, IDHash > &r_hashes, DeepHashErrors &r_errors)
static std::optional< XXH128_hash_t > compute_file_hash(const StringRefNull path)
static std::optional< XXH128_hash_t > get_id_shallow_hash(const ID &id, DeepHashErrors &r_errors)
static std::optional< XXH128_hash_t > compute_file_hash_with_memory_map(const StringRefNull path)
std::variant< ValidDeepHashes, DeepHashErrors > IDHashResult
static std::optional< Vector< char > > read_file(const StringRefNull path)
IDHashResult compute_linked_id_deep_hashes(const Main &bmain, Span< const ID * > root_ids)
std::string id_hash_to_hex(const IDHash &hash)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t BLI_mmap_get_length(const BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
BLI_mmap_file * BLI_mmap_open(int fd) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_mmap_free(BLI_mmap_file *file) ATTR_NONNULL(1)
BMesh const char void * data
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BLI_mmap_any_io_error(const BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
void * BLI_mmap_get_pointer(BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
@ IDWALK_CB_EMBEDDED_NOT_OWNING
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
LibraryForeachIDCallbackFlag cb_flag
VectorSet< std::string > updated_files
VectorSet< std::string > missing_from_files
VectorSet< std::string > missing_files