@@ -28,7 +28,7 @@ from shlex import quote
2828import xml .etree .ElementTree as ET
2929
3030# Constants
31- VERSION = "0.1.13 "
31+ VERSION = "0.1.14 "
3232ZYPPER_PID_FILE = "/run/zypp.pid"
3333VALID_CMD = ["dup" , "run" , "rollback" ]
3434VALID_OPT = ["--reboot" , "--apply" , "--shell" , "--continue" , "--no-verify" , \
@@ -202,12 +202,26 @@ signal.signal(signal.SIGINT, sigint_handler)
202202COMMAND = ""
203203OPT = []
204204ARG = []
205+ SKIP = False
206+ continue_num = None # optional snapshot number to continue from
205207for index , item in enumerate (sys .argv ):
206- if index == 0 :
208+ if SKIP or index == 0 :
209+ SKIP = False
207210 continue
208211 if item .startswith ("--" ):
209212 if item in VALID_OPT :
210213 OPT .append (item )
214+ if item == "--continue" :
215+ try :
216+ continue_num = int (sys .argv [index + 1 ])
217+ if not continue_num in range (1 , 999999 ):
218+ print ("Invalid value for option '--continue'. Must be between 1 to 999999 (inclusive)" )
219+ sys .exit (1 )
220+ SKIP = True
221+ except ValueError :
222+ pass
223+ except IndexError :
224+ pass
211225 else :
212226 print (f"Invalid option { item !r} . See usage below.\n " )
213227 print (help_text .strip ())
@@ -257,23 +271,9 @@ logging.basicConfig(
257271 level = logging .DEBUG if DEBUG else logging .INFO ,
258272)
259273
260- # check if there's a snapshot number provided to continue from
261- continue_num = None
262- if "--continue" in OPT :
263- try :
264- continue_num = int (sys .argv [sys .argv .index ("--continue" ) + 1 ])
265- if not continue_num in range (1 , 999999 ):
266- logging .error ("Invalid value for option '--continue'. Must be between 1 to 999999 (inclusive)" )
267- sys .exit (1 )
268- except ValueError :
269- logging .debug ("No numerical value provided for option '--continue'" )
270- pass
271- except IndexError :
272- logging .debug ("No value provided for option '--continue'" )
273- pass
274-
274+ # validate optional snapshot provided to continue from exists
275275if continue_num :
276- ret = os .system (f"btrfs subvolume list / | grep '@/.snapshots/{ continue_num } /snapshot'" )
276+ ret = os .system (f"btrfs subvolume list / | grep '@/.snapshots/{ continue_num } /snapshot' > /dev/null 2>&1 " )
277277 if ret != 0 :
278278 logging .error (f"Provided snapshot { continue_num } for option '--continue' does not exist" )
279279 sys .exit (1 )
@@ -294,7 +294,7 @@ if COMMAND == "rollback":
294294 pass
295295
296296if rollback_num :
297- ret = os .system (f"btrfs subvolume list / | grep '@/.snapshots/{ rollback_num } /snapshot'" )
297+ ret = os .system (f"btrfs subvolume list / | grep '@/.snapshots/{ rollback_num } /snapshot' > /dev/null 2>&1 " )
298298 if ret != 0 :
299299 logging .error (f"Provided snapshot { rollback_num } for rollback does not exist" )
300300 sys .exit (1 )
0 commit comments