Skip to content

Commit

Permalink
snagrecover: utils: Correct USB path parsing
Browse files Browse the repository at this point in the history
There is a bug in the parse_usb_path() function that causes paths of the
form "^\d-\d\d$" to be parsed incorrectly. For example, "2-10" should be
parsed to (2, 10) but it will be parsed to (2, 1, 0) instead.

Correct parse_usb_path() to fix this.

Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
  • Loading branch information
rgantois committed Jul 1, 2024
1 parent 8d57eec commit 70341d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/snagrecover/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def parse_usb_path(path: str) -> tuple:
if match is None:
cli_error(f"failed to parse USB device path {path}")
groups = match.groups()
port_numbers = groups[1]
port_numbers = [groups[1]]
if groups[2] != "":
port_numbers = [port_numbers] + groups[2].split(".")[1:]
port_numbers += groups[2].split(".")[1:]
# Formatted for usb.core.find
port_tuple = tuple([int(x) for x in port_numbers])
return (int(groups[0]), port_tuple)
Expand Down

0 comments on commit 70341d7

Please sign in to comment.