Blender V5.3
asset_indexer_remote_file_status.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_fileops.hh"
10#include "BLI_path_utils.hh"
11#include "BLI_string.hh"
12
13#include "AS_remote_library.hh"
14
15#include "CLG_log.h"
16
18
19static CLG_LogRef LOG = {"asset.remote_listing"};
20
21using namespace blender::asset_system;
22
24
33constexpr const char *hash_service_filename_prefix = "_file_hashes";
34
36 : library_root_path_(library_root_path)
37{
38 char dfhs_path[PATH_MAX];
40 dfhs_path, sizeof(dfhs_path), library_root_path.c_str(), hash_service_filename_prefix);
41 this->dfhs_ = disk_file_hash_service_get(dfhs_path);
42}
43
45{
46 const StringRefNull relative_file_path = file_to_check.local_path;
47
48 /* Check against our own cache to see if we checked this file before. */
49 if (file_to_check.file_status.has_value()) {
50 return *file_to_check.file_status;
51 }
52
53 /* Construct the absolute path, so we can check its hash on disk. */
54 char file_abspath[PATH_MAX];
56 file_abspath, sizeof(file_abspath), library_root_path_.c_str(), relative_file_path.c_str());
57
58 if (!BLI_exists(file_abspath)) {
59 return this->remember(file_to_check, RemoteAssetFileStatus::NOT_ON_DISK);
60 }
61
62 /* Split METHOD:HASH into two StringRefs. */
63 const StringRefNull hash_with_method = file_to_check.download_url.hash;
64 const int64_t colon_index = hash_with_method.find_first_of(':');
65 if (colon_index == StringRef::not_found) {
66 CLOG_WARN(&LOG, "Asset file hash not in METHOD:HASH format: %s", hash_with_method.c_str());
67 return this->remember(file_to_check, RemoteAssetFileStatus::NO_MATCH);
68 }
69 std::string hash_algorithm = hash_with_method.substr(0, colon_index);
70 const StringRef hexhash = hash_with_method.substr(colon_index + 1);
71
72 BLI_str_tolower_ascii(hash_algorithm.data(), hash_algorithm.length());
73
74 /* Check with the Disk File Hash Service. */
75 const bool is_match = dfhs_->file_matches(
76 file_abspath, hash_algorithm, hexhash, file_to_check.size_in_bytes);
77
78 return this->remember(file_to_check,
80}
81
82asset_system::RemoteAssetFileStatus FileStatusChecker::remember(
84{
85 file_to_check.file_status = status;
86 return status;
87}
88
89} // namespace blender::ed::asset::index
File and directory operations.
#define PATH_MAX
#define BLI_path_join(...)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
constexpr const char * c_str() const
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
static constexpr int64_t not_found
constexpr StringRef substr(int64_t start, int64_t size) const
asset_system::RemoteAssetFileStatus remote_file_status(RemoteListingFileEntry &file_to_check)
#define LOG(level)
Definition log.h:97
std::unique_ptr< DiskFileHashService > disk_file_hash_service_get(StringRef storage_path)
constexpr const char * hash_service_filename_prefix
__int64 int64_t
Definition BKE_text.h:90
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1)
std::optional< asset_system::RemoteAssetFileStatus > file_status