| 279 | } |
| 280 | |
| 281 | void WasmModuleManager::deleteModuleIfExists(std::function<bool(std::string_view)> name_match) |
| 282 | { |
| 283 | UniqueLock lock(modules_mutex); |
| 284 | |
| 285 | for (auto it = modules.begin(); it != modules.end();) |
| 286 | { |
| 287 | if (!name_match(it->first)) |
| 288 | { |
| 289 | ++it; |
| 290 | continue; |
| 291 | } |
| 292 | |
| 293 | if (std::ranges::any_of(it->second.ptrs, [](const auto & ptr) { return !ptr.expired(); })) |
| 294 | throw Exception( |
| 295 | ErrorCodes::CANNOT_DROP_FUNCTION, |
| 296 | "Cannot delete WebAssembly module '{}' while it is in use. " |
| 297 | "Drop all functions referring to it first", |
| 298 | it->first); |
| 299 | |
| 300 | user_scripts_disk->removeFileIfExists(getFilePath(it->first)); |
| 301 | it = modules.erase(it); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | void WasmModuleManager::deleteModuleIfExists(std::string_view module_name) |
| 306 | { |