MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / remove_model

Method remove_model

src/pull/model_downloader.cpp:358–406  ·  view source on GitHub ↗

\brief Remove a model and all its files \param model_tag the model tag \return true if the model was successfully removed, false otherwise

Source from the content-addressed store, hash-verified

356/// \param model_tag the model tag
357/// \return true if the model was successfully removed, false otherwise
358bool ModelDownloader::remove_model(const std::string& model_tag, bool sub_process_mode) {
359 try {
360 // Check if model exists in supported models by trying to get its info
361 try {
362 supported_models.get_model_info(model_tag);
363 } catch (const std::exception& e) {
364 header_print("ERROR", "Model not found: " + model_tag);
365 model_not_found(model_tag);
366 return false;
367 }
368
369 // Get model path
370 std::string model_path = supported_models.get_model_path(model_tag);
371
372 // Check if model directory exists
373 if (!std::filesystem::exists(model_path)) {
374 header_print("FLM", "Model directory does not exist: " + model_path);
375 return true; // Consider it already removed
376 }
377
378 if (!sub_process_mode) {
379 header_print("FLM", "Removing model: " + model_tag);
380 header_print("FLM", "Path: " + model_path);
381 }
382
383 // Remove all files in the model directory
384 size_t removed_files = 0;
385 for (const auto& entry : std::filesystem::directory_iterator(model_path)) {
386 if (entry.is_regular_file()) {
387 std::filesystem::remove(entry.path());
388 removed_files++;
389 }
390 }
391
392 // Remove the model directory itself
393 if (std::filesystem::remove(model_path)) {
394 if(!sub_process_mode)
395 header_print("FLM", "Successfully removed " + std::to_string(removed_files) + " files and model directory.");
396 return true;
397 } else {
398 header_print("ERROR", "Failed to remove model directory: " + model_path);
399 return false;
400 }
401
402 } catch (const std::exception& e) {
403 header_print("ERROR", "Exception during model removal: " + std::string(e.what()));
404 return false;
405 }
406}
407
408/// \brief Check hash of model files
409/// \param model_tag the model tag

Callers 1

mainFunction · 0.80

Calls 3

get_model_infoMethod · 0.80
get_model_pathMethod · 0.80
to_stringFunction · 0.50

Tested by

no test coverage detected