Improve broken symlink removal

This commit is contained in:
VirtuBox
2024-04-21 17:37:30 +02:00
parent e7eb865648
commit 8ddaa7e98f
4 changed files with 13 additions and 10 deletions

View File

@@ -757,7 +757,7 @@ def setupwp_plugin(self, plugin_name, plugin_option, plugin_data, data):
def setwebrootpermissions(self, webroot): def setwebrootpermissions(self, webroot):
Log.debug(self, "Setting up permissions") Log.debug(self, "Setting up permissions")
try: try:
WOFileUtils.findBrokenSymlink(self, '/var/www/') WOFileUtils.findBrokenSymlink(self, f'{webroot}')
WOFileUtils.chown(self, webroot, WOVar.wo_php_user, WOFileUtils.chown(self, webroot, WOVar.wo_php_user,
WOVar.wo_php_user, recursive=True) WOVar.wo_php_user, recursive=True)
except Exception as e: except Exception as e:

View File

@@ -722,15 +722,20 @@ class WOSiteUpdateController(CementBaseController):
'hsts.conf.disabled' 'hsts.conf.disabled'
.format(wo_site_webroot)) .format(wo_site_webroot))
# find all broken symlinks # find all broken symlinks
sympath = "/var/www" sympath = (f'{wo_site_webroot}/conf')
WOFileUtils.findBrokenSymlink(self, sympath) WOFileUtils.findBrokenSymlink(self, sympath)
elif (pargs.letsencrypt == "clean" or elif (pargs.letsencrypt == "clean" or
pargs.letsencrypt == "purge"): pargs.letsencrypt == "purge"):
WOAcme.removeconf(self, wo_domain) WOAcme.removeconf(self, wo_domain)
# find all broken symlinks # find all broken symlinks
sympath = "/var/www" allsites = getAllsites(self)
for site in allsites:
if not site:
pass
sympath = "{0}/conf".format(site.site_path)
WOFileUtils.findBrokenSymlink(self, sympath) WOFileUtils.findBrokenSymlink(self, sympath)
if not WOService.reload_service(self, 'nginx'): if not WOService.reload_service(self, 'nginx'):
Log.error(self, "service nginx reload failed. " Log.error(self, "service nginx reload failed. "
"check issues with `nginx -t` command") "check issues with `nginx -t` command")

View File

@@ -253,8 +253,7 @@ class WOAcme:
for dir in acmedir: for dir in acmedir:
if os.path.exists('{0}'.format(dir)): if os.path.exists('{0}'.format(dir)):
WOFileUtils.rm(self, '{0}'.format(dir)) WOFileUtils.rm(self, '{0}'.format(dir))
# find all broken symlinks
WOFileUtils.findBrokenSymlink(self, "/var/www")
else: else:
if os.path.islink("{0}".format(sslconf)): if os.path.islink("{0}".format(sslconf)):
WOFileUtils.remove_symlink(self, "{0}".format(sslconf)) WOFileUtils.remove_symlink(self, "{0}".format(sslconf))

View File

@@ -318,10 +318,9 @@ class WOFileUtils():
""" """
links = [] links = []
broken = [] broken = []
ignored_dirs = ['./.git', './htdocs']
for root, dirs, files in os.walk(sympath): for root, dirs, files in os.walk(sympath):
if any(root.startswith(ignore_dir) for ignore_dir in ignored_dirs): if root.startswith('./.git'):
# Ignore the .git directory. # Ignore the .git directory.
continue continue
for filename in files: for filename in files: