fix: Enhance removal process by adding database cleanup and improving error handling
This commit is contained in:
@@ -329,10 +329,25 @@ class instace:
|
||||
Output:
|
||||
- bool if the removal works (True: removal worked; False: didnt work)
|
||||
"""
|
||||
if execute_script(_var, _cmd, "remove", clear_special(name)):
|
||||
return True
|
||||
else:
|
||||
safe_name = clear_special(name)
|
||||
# try to remove via management script
|
||||
script_ok = execute_script(_var, _cmd, "remove", safe_name)
|
||||
if not script_ok:
|
||||
return False
|
||||
|
||||
# best-effort: remove the associated package entry from the database
|
||||
client = None
|
||||
try:
|
||||
client, packages = _get_users_collection()
|
||||
packages.delete_one({"client_name": name})
|
||||
except Exception:
|
||||
# don't fail the overall removal if DB cleanup fails
|
||||
pass
|
||||
finally:
|
||||
if client:
|
||||
client.close()
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def status(name: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user