Skip to content

Commit 23d9513

Browse files
committed
rel_upgrade_root: Stop the upgrade when a step fails or is cancelled.
The finished callback was called with any exit state, and the next step ran regardless, so a failed or cancelled package install could be followed by the additions, removals and update-grub. Quit with an error status instead. A cancelled confirmation dialog also left the script hanging, as no cancelled callback was set.
1 parent 15e45f3 commit 23d9513

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎usr/lib/linuxmint/mintUpdate/rel_upgrade_root.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python3
22

33
import apt
4+
import aptkit.enums
45
import aptkit.simpleclient
56
import gettext
67
import gi
@@ -44,6 +45,7 @@ class Upgrader():
4445
def __init__(self):
4546
self.refresh_done = False
4647
self.client = aptkit.simpleclient.SimpleAPTClient()
48+
self.client.set_cancelled_callback(lambda: self.quit(1))
4749
self.additions = file_to_list(f"/usr/share/mint-upgrade-info/{codename}/additions")
4850
self.removals = file_to_list(f"/usr/share/mint-upgrade-info/{codename}/removals")
4951
self.blacklist = file_to_list(f"/usr/share/mint-upgrade-info/{codename}/blacklist")
@@ -86,7 +88,17 @@ def on_cache_updated(self, transaction=None, exit_state=None):
8688
else:
8789
self.on_install_finished()
8890

91+
def quit(self, status):
92+
Gtk.main_quit()
93+
sys.exit(status)
94+
95+
def quit_if_failed(self, exit_state):
96+
if exit_state is not None and exit_state != aptkit.enums.EXIT_SUCCESS:
97+
syslog.syslog("Upgrade step failed: %s" % exit_state)
98+
self.quit(1)
99+
89100
def on_install_finished(self, transaction=None, exit_state=None):
101+
self.quit_if_failed(exit_state)
90102
# STEP 4: ADD PACKAGES
91103
if len(self.additions) > 0:
92104
self.client.set_finished_callback(self.on_additions_finished)
@@ -95,6 +107,7 @@ def on_install_finished(self, transaction=None, exit_state=None):
95107
self.on_additions_finished()
96108

97109
def on_additions_finished(self, transaction=None, exit_state=None):
110+
self.quit_if_failed(exit_state)
98111
# STEP 5: REMOVE PACKAGES
99112
removals = []
100113
cache = apt.Cache()
@@ -109,15 +122,15 @@ def on_additions_finished(self, transaction=None, exit_state=None):
109122
self.on_removals_finished()
110123

111124
def on_removals_finished(self, transaction=None, exit_state=None):
125+
self.quit_if_failed(exit_state)
112126
# STEP 6: UPDATE GRUB
113127
try:
114128
subprocess.run(["update-grub"])
115129
if os.path.exists("/usr/share/ubuntu-system-adjustments/systemd/adjust-grub-title"):
116130
subprocess.run(["/usr/share/ubuntu-system-adjustments/systemd/adjust-grub-title"])
117131
except Exception as detail:
118132
syslog.syslog("Couldn't update grub: %s" % detail)
119-
Gtk.main_quit()
120-
sys.exit(0)
133+
self.quit(0)
121134

122135
if __name__ == "__main__":
123136
upgrader =Upgrader()

0 commit comments

Comments
 (0)