@@ -43,30 +43,29 @@ class DmesgCollector(InBandDataCollector[DmesgData, None]):
4343 DMESG_CMD = "dmesg --time-format iso -x"
4444
4545 DMESG_LOGS_CMD = (
46- r"ls -1 /var/log/dmesg /var/log/dmesg.1 /var/log/dmesg.[0-9]* .gz 2>/dev/null || true"
46+ r"ls -1 /var/log/dmesg* 2>/dev/null | grep -E '^ /var/log/dmesg(\ .[0-9]+(\ .gz)?)?$' || true"
4747 )
4848
4949 def _shell_quote (self , s : str ) -> str :
5050 """single-quote fix."""
5151 return "'" + s .replace ("'" , "'\" '\" '" ) + "'"
5252
5353 def _nice_dmesg_name (self , path : str ) -> str :
54- """Map path to filename"""
55- if path .endswith ("/dmesg" ):
54+ """Map path to filename."""
55+ base = path .rstrip ("/" ).rsplit ("/" , 1 )[- 1 ]
56+ if base == "dmesg" :
5657 return "dmesg.log"
57- if path .endswith ("/dmesg.1" ):
58- return "dmesg.1.log"
59- m = re .search (r"/dmesg\.(\d+)\.gz$" , path )
58+ m = re .fullmatch (r"dmesg\.(\d+)\.gz" , base )
6059 if m :
6160 return f"dmesg.{ m .group (1 )} .gz.log"
62- base = path .rsplit ("/" , 1 )[- 1 ]
63- return base .replace (".gz" , "" ) + ".log"
61+ m = re .fullmatch (r"dmesg\.(\d+)" , base )
62+ if m :
63+ return f"dmesg.{ m .group (1 )} .log"
64+
65+ return (base [:- 3 ] if base .endswith (".gz" ) else base ) + ".log"
6466
6567 def _collect_dmesg_rotations (self ) -> int :
66- list_res = self ._run_sut_cmd (
67- r"ls -1 /var/log/dmesg /var/log/dmesg.1 /var/log/dmesg.[0-9]*.gz 2>/dev/null || true" ,
68- sudo = True ,
69- )
68+ list_res = self ._run_sut_cmd (self .DMESG_LOGS_CMD , sudo = True )
7069 paths = [p .strip () for p in (list_res .stdout or "" ).splitlines () if p .strip ()]
7170 if not paths :
7271 self ._log_event (
0 commit comments