diff --git a/omlx/admin/routes.py b/omlx/admin/routes.py index 2fa37426..f83f8d92 100644 --- a/omlx/admin/routes.py +++ b/omlx/admin/routes.py @@ -3052,7 +3052,7 @@ async def delete_hf_model( except ValueError: raise HTTPException(status_code=400, detail="Invalid model name") - if not model_path.is_dir(): + if not model_path.is_dir() and not model_path.is_symlink(): raise HTTPException(status_code=400, detail="Not a model directory") # Unload model if loaded @@ -3082,11 +3082,15 @@ def _handle_onerror(func, path, exc_info): raise exc_info[1].with_traceback(exc_info[2]) try: - if sys.version_info >= (3, 12): + if model_path.is_symlink(): + model_path.unlink() + logger.info(f"Deleted model symlink: {model_path}") + elif sys.version_info >= (3, 12): shutil.rmtree(model_path, onexc=_handle_onexc) + logger.info(f"Deleted model directory: {model_path}") else: shutil.rmtree(model_path, onerror=_handle_onerror) - logger.info(f"Deleted model directory: {model_path}") + logger.info(f"Deleted model directory: {model_path}") except Exception as e: logger.error(f"Failed to delete model directory {model_path}: {e}") raise HTTPException(status_code=500, detail=f"Failed to delete model: {e}")