Skip to content

Commit

Permalink
src/data/listUsb: Fix O.D.D. always listed in target device list, fixes
Browse files Browse the repository at this point in the history
… #109

`expr` doesn't support extended regular expression, so the match always return false.  We fix this by using `grep` which is much capable of doing the job.  Also we simplify the match pattern a bit as long as the result is expected.

Related-GitHub-issue: Regression: src/data/listUsb: Optical Disk Drives still listed in the "Target device:" list · Issue #109 · slacka/WoeUSB <https://github.com/slacka/WoeUSB/issues/109>
Signed-off-by: 林博仁 <[email protected]>
  • Loading branch information
brlin-tw committed Jun 15, 2017
1 parent b25db28 commit 24bd015
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/data/listUsb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ is_removable_and_writable_device(){
local block_device_name="$1"

local -r sysfs_block_device_dir="/sys/block/${block_device_name}"

# We consider device not removable if the removable sysfs item not exist
if [ -f "${sysfs_block_device_dir}/removable" ] \
&& [ "$(cat "${sysfs_block_device_dir}/removable")" -eq 1 ]\
&& [ "$(cat "${sysfs_block_device_dir}/ro")" -eq 0 ]; then
Expand All @@ -52,13 +54,14 @@ declare device_capacity
declare device_model

while read block_device_name; do
if expr match "${block_device_name}" "^sr[0-9]+$\|^cdrom[0-9]*$" >/dev/null; then
if grep --extended-regexp "^sr.*$|^cdrom.*$" <<< "${block_device_name}" >/dev/null; then
# Known non-target blacklist
continue
elif expr match "${block_device_name}" '^loop[0-9]+' >/dev/null; then
if [ "${show_all_devices}" -eq 0 ]; then
continue
fi
# NOTE: We might not need this check at all as loop devices also has removable sysfs entry
# elif grep '^loop.*$' <<< "${block_device_name}" >/dev/null; then
# if [ "${show_all_devices}" -eq 0 ]; then
# continue
# fi
elif ! is_removable_and_writable_device "${block_device_name}"; then
if [ "${show_all_devices}" -eq 0 ]; then
continue
Expand Down

0 comments on commit 24bd015

Please sign in to comment.