27 return std::make_unique<DiskFileHashService>(storage_path);
31 : storage_path_(storage_path)
40void DiskFileHashService::release_python()
43 constexpr const char *SCRIPT = R
"(
44import _bpy_internal.disk_file_hash_service as dfhs
45from pathlib import Path
47dfhs.release_service(Path(storage_path))
64 constexpr const char *SCRIPT = R
"(
65import _bpy_internal.disk_file_hash_service as dfhs
66from pathlib import Path
68service = dfhs.get_service(Path(storage_path))
69_result = service.get_hash(Path(filepath), hash_algorithm)
80 nullptr, SCRIPT, *locals,
"_result");
81 if (!idprop_optptr.has_value()) {
82 const std::string filepath_str = filepath;
83 CLOG_ERROR(&
LOG,
"Failed to run hash script for file [%s].", filepath_str.c_str());
91 const std::string filepath_str = filepath;
93 "Hash for file [%s] was not returned as string. Please report this as a bug.",
94 filepath_str.c_str());
104 const std::string filepath_str = filepath;
106 "Blender was built without Python support, cannot compute hash for file [%s]",
107 filepath_str.c_str());
123 constexpr const char *SCRIPT = R
"(
124import _bpy_internal.disk_file_hash_service as dfhs
125from pathlib import Path
127# The '& 0xFFFFFFFF' makes Python interpret the values as unsigned ints.
128size_in_bytes = ((size_in_bytes_high & 0xFFFFFFFF) << 32) | (size_in_bytes_low & 0xFFFFFFFF)
130service = dfhs.get_service(Path(storage_path))
131_result = service.file_matches(Path(filepath), hash_algorithm, hexhash, size_in_bytes);
137 const int size_in_bytes_high = int((size_in_bytes >> 32) & 0xFFFFFFFF);
138 const int size_in_bytes_low = int(size_in_bytes & 0xFFFFFFFF);
150 nullptr, SCRIPT, *locals,
"_result");
151 if (!idprop_optptr.has_value()) {
152 const std::string filepath_str = filepath;
153 CLOG_ERROR(&
LOG,
"Failed to run hash match script for file [%s].", filepath_str.c_str());
159 if (is_match_idprop ==
nullptr || is_match_idprop->
type !=
IDP_BOOLEAN) {
161 const std::string filepath_str = filepath;
164 "Hash match check for file [%s] did not return a boolean. Please report this as a bug.",
165 filepath_str.c_str());
175 const std::string filepath_str = filepath;
177 "Blender was built without Python support, cannot check hash for file [%s]",
178 filepath_str.c_str());
#define IDP_string_get(prop)
#define IDP_bool_get(prop)
#define CLOG_ERROR(clg_ref,...)
bool file_matches(StringRef filepath, StringRef hash_algorithm, StringRef hexhash, int64_t size_in_bytes)
DiskFileHashService(StringRef storage_path)
std::string get_hash(StringRef filepath, StringRef hash_algorithm)
std::unique_ptr< DiskFileHashService > disk_file_hash_service_get(StringRef storage_path)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool BPY_run_string_exec_with_locals(bContext *C, StringRefNull script, IDProperty &locals)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
IDProperty * IDP_NewString(const char *st, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
void IDP_FreeProperty(IDProperty *prop)
std::optional< IDProperty * > BPY_run_string_exec_with_locals_return_idprop(bContext *C, StringRefNull script, IDProperty &locals, StringRefNull result_var_name)
IDProperty * IDP_NewInt(int value, blender::StringRef name, eIDPropertyFlag flags={})