Skip to content

Commit a1f2b1e

Browse files
committed
Do not discard snapshot if shell option is present
1 parent e9f585c commit a1f2b1e

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

atomic-update

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ from shlex import quote
2828
import xml.etree.ElementTree as ET
2929

3030
# Constants
31-
VERSION = "0.1.0"
31+
VERSION = "0.1.1"
3232
ZYPPER_PID_FILE = "/run/zypp.pid"
3333
VALID_CMD = ["dup", "run", "rollback"]
3434
VALID_OPT = ["--reboot", "--apply", "--shell", "--continue", "--no-verify", \
@@ -405,20 +405,24 @@ chroot {TMP_MOUNT_DIR} mount -a;
405405
logging.info("Performing distribution upgrade within chroot...")
406406
ret = os.system(f"zypper --root {TMP_MOUNT_DIR} {'' if CONFIRM else '--non-interactive'} --no-cd dist-upgrade")
407407
if ret != 0:
408-
logging.error(f"Zypper returned exit code {ret}. Discarding snapshot {atomic_snap}")
409-
shell_exec(f"snapper -c {snapper_root_config} delete {atomic_snap}")
410-
cleanup()
411-
sys.exit(9)
408+
logging.error(f"Zypper returned exit code {ret}")
409+
if not SHELL:
410+
logging.info(f"Discarding snapshot {atomic_snap}")
411+
shell_exec(f"snapper -c {snapper_root_config} delete {atomic_snap}")
412+
cleanup()
413+
sys.exit(9)
412414
logging.info(f"Distribution upgrade completed successfully")
413415
elif COMMAND == "run":
414416
exec_cmd = ' '.join(ARG)
415417
logging.info(f"Running command {exec_cmd!r} within chroot...")
416418
ret = os.system(f"chroot {TMP_MOUNT_DIR} {exec_cmd}")
417419
if ret != 0:
418-
logging.error(f"Command returned exit code {ret}. Discarding snapshot {atomic_snap}")
419-
shell_exec(f"snapper -c {snapper_root_config} delete {atomic_snap}")
420-
cleanup()
421-
sys.exit(9)
420+
logging.error(f"Command returned exit code {ret}")
421+
if not SHELL:
422+
logging.info(f"Discarding snapshot {atomic_snap}")
423+
shell_exec(f"snapper -c {snapper_root_config} delete {atomic_snap}")
424+
cleanup()
425+
sys.exit(9)
422426
logging.info("Command run successfully")
423427
if SHELL:
424428
logging.info(f"Opening bash shell within chroot of snapshot {atomic_snap}")

0 commit comments

Comments
 (0)