mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-28 10:19:04 +01:00
fix(plugins): Improve uninstall retry logic with permission fix and root fallback
- Fix permissions with ProcessUtilities before removal retry - Add subprocess fallback if running as root - Add filesystem sync delay after removal - Better error messages showing all attempted methods Fixes: pm2Manager and paypalPremiumPlugin uninstall failures
This commit is contained in:
@@ -625,18 +625,50 @@ def uninstall_plugin(request, plugin_name):
|
||||
# Verify removal succeeded
|
||||
pluginInstalled = '/usr/local/CyberCP/' + plugin_name
|
||||
if os.path.exists(pluginInstalled):
|
||||
# Removal failed - try again with more aggressive method
|
||||
# Removal failed - try again with more aggressive methods
|
||||
logging.writeToFile(f'Plugin directory still exists after removeFiles, trying ProcessUtilities')
|
||||
try:
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
|
||||
# First, try to fix permissions with ProcessUtilities
|
||||
chown_cmd = f'chown -R cyberpanel:cyberpanel {pluginInstalled}'
|
||||
ProcessUtilities.normalExecutioner(chown_cmd)
|
||||
|
||||
chmod_cmd = f'chmod -R u+rwX,go+rX {pluginInstalled}'
|
||||
ProcessUtilities.normalExecutioner(chmod_cmd)
|
||||
|
||||
# Then try to remove
|
||||
rm_cmd = f'rm -rf {pluginInstalled}'
|
||||
ProcessUtilities.normalExecutioner(rm_cmd)
|
||||
|
||||
# Wait a moment for filesystem to sync
|
||||
import time
|
||||
time.sleep(0.5)
|
||||
|
||||
# Verify again
|
||||
if os.path.exists(pluginInstalled):
|
||||
raise Exception(f'Plugin directory still exists after ProcessUtilities removal: {pluginInstalled}')
|
||||
# Last resort: try subprocess with shell=True as root
|
||||
logging.writeToFile(f'ProcessUtilities removal failed, trying subprocess as root')
|
||||
try:
|
||||
import subprocess
|
||||
# Check if we're root
|
||||
is_root = os.geteuid() == 0 if hasattr(os, 'geteuid') else False
|
||||
if is_root:
|
||||
# Running as root - use subprocess directly
|
||||
result = subprocess.run(
|
||||
['rm', '-rf', pluginInstalled],
|
||||
capture_output=True, text=True, timeout=30
|
||||
)
|
||||
time.sleep(0.5)
|
||||
if os.path.exists(pluginInstalled):
|
||||
raise Exception(f'Plugin directory still exists after all removal attempts: {pluginInstalled}')
|
||||
else:
|
||||
raise Exception(f'Plugin directory still exists after ProcessUtilities removal: {pluginInstalled}')
|
||||
except Exception as e3:
|
||||
logging.writeToFile(f'Subprocess removal also failed: {str(e3)}')
|
||||
raise Exception(f'Failed to remove plugin directory. Tried removeFiles(), ProcessUtilities, and subprocess. Directory still exists: {pluginInstalled}')
|
||||
except Exception as e2:
|
||||
logging.writeToFile(f'ProcessUtilities removal also failed: {str(e2)}')
|
||||
logging.writeToFile(f'ProcessUtilities removal failed: {str(e2)}')
|
||||
raise Exception(f'Failed to remove plugin directory. Tried removeFiles() and ProcessUtilities. Directory still exists: {pluginInstalled}')
|
||||
except Exception as e:
|
||||
logging.writeToFile(f'Error removing plugin files: {str(e)}')
|
||||
|
||||
Reference in New Issue
Block a user