Skip to content

Commit

Permalink
Prevent reading an empty file when reinstalling conflict packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sandakov committed Sep 12, 2024
1 parent e4ce4ae commit c5506a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
17 changes: 10 additions & 7 deletions cloudlinux7to8/actions/mariadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def _prepare_action(self) -> action.ActionResult:
rpm.remove_packages(packages_to_remove)

# Avoid reinstallation if mariadb installed by governor
if _is_governor_mariadb_installed():
# if there are no such packages installed, don't create the file as well
if _is_governor_mariadb_installed() or len(packages_to_remove) == 0:
return action.ActionResult()

with open(self.removed_packages_file, "a") as f:
Expand All @@ -343,9 +344,10 @@ def _post_action(self) -> action.ActionResult:
if not os.path.exists(self.removed_packages_file):
return action.ActionResult()

with open(self.removed_packages_file, "r") as f:
packages_to_install = [self.conflict_pkgs_map[pkg] for pkg in set(f.read().splitlines())]
rpm.install_packages(packages_to_install)
if os.path.getsize(self.removed_packages_file) > 0:
with open(self.removed_packages_file, "r") as f:
packages_to_install = [self.conflict_pkgs_map[pkg] for pkg in set(f.read().splitlines())]
rpm.install_packages(packages_to_install)

os.unlink(self.removed_packages_file)
return action.ActionResult()
Expand All @@ -354,9 +356,10 @@ def _revert_action(self) -> action.ActionResult:
if not os.path.exists(self.removed_packages_file):
return action.ActionResult()

with open(self.removed_packages_file, "r") as f:
packages_to_install = list(set(f.read().splitlines()))
rpm.install_packages(packages_to_install)
if os.path.getsize(self.removed_packages_file) > 0:
with open(self.removed_packages_file, "r") as f:
packages_to_install = list(set(f.read().splitlines()))
rpm.install_packages(packages_to_install)

os.unlink(self.removed_packages_file)
return action.ActionResult()
Expand Down
14 changes: 8 additions & 6 deletions cloudlinux7to8/actions/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ def _post_action(self) -> action.ActionResult:
log.warn("File with removed packages list does not exist. While the action itself was not skipped. Skip reinstalling packages.")
return action.ActionResult()

with open(self.removed_packages_file, "r") as f:
packages_to_install = [self.conflict_pkgs_map[pkg] for pkg in set(f.read().splitlines())]
rpm.install_packages(packages_to_install)
if os.path.getsize(self.removed_packages_file) > 0:
with open(self.removed_packages_file, "r") as f:
packages_to_install = [self.conflict_pkgs_map[pkg] for pkg in set(f.read().splitlines())]
rpm.install_packages(packages_to_install)

os.unlink(self.removed_packages_file)
return action.ActionResult()
Expand All @@ -146,9 +147,10 @@ def _revert_action(self) -> action.ActionResult:
log.warn("File with removed packages list does not exist. While the action itself was not skipped. Skip reinstalling packages.")
return action.ActionResult()

with open(self.removed_packages_file, "r") as f:
packages_to_install = list(set(f.read().splitlines()))
rpm.install_packages(packages_to_install)
if os.path.getsize(self.removed_packages_file) > 0:
with open(self.removed_packages_file, "r") as f:
packages_to_install = list(set(f.read().splitlines()))
rpm.install_packages(packages_to_install)

os.unlink(self.removed_packages_file)
return action.ActionResult()
Expand Down

0 comments on commit c5506a5

Please sign in to comment.