MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / validateModuleFile

Function validateModuleFile

src/Interpreters/WasmModuleManager.cpp:113–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113static std::expected<String, PreformattedMessage> validateModuleFile(const DiskPtr & user_scripts_disk, const String & path)
114{
115 std::filesystem::path file_path(path);
116
117 const auto & file_name = file_path.filename().string();
118
119 if (!endsWith(file_name, FILE_EXTENSION))
120 return formatUnexpected("Unexpected file extension '{}', expected '{}'", file_path.extension().string(), FILE_EXTENSION);
121
122 ReadSettings read_settings;
123 auto read_buf = user_scripts_disk->readFile(path, read_settings);
124 std::string file_header(16, '\0');
125 size_t n = read_buf->read(file_header.data(), file_header.size());
126 if (n != file_header.size())
127 return formatUnexpected("File '{}' is too small to be a valid WebAssembly module", path);
128
129 auto module_name = file_name.substr(0, file_name.size() - strlen(FILE_EXTENSION));
130 if (auto res = checkValidWasmCode(module_name, file_header); !res)
131 return std::unexpected(std::move(res.error()));
132 return module_name;
133}
134
135static std::unique_ptr<WebAssembly::IWasmEngine> createEngine(std::string_view engine_name)
136{

Callers 2

getModuleMethod · 0.85

Calls 9

formatUnexpectedFunction · 0.85
checkValidWasmCodeFunction · 0.85
endsWithFunction · 0.50
stringMethod · 0.45
readFileMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected