Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Victor Lowther <victor.lowther@xxxxxxxxx>:
> # Parsing the output of ls can lead to strange and subtle bugs.
> # Use globbing and parameter expansion instead, and go with the first
> # matching file.
> 	local f
> 	for f in "$r/$1" "$r/${1%%-*}-udev-%{1##*-}" "$r/"*"$1"; do
> 		[[ -f $f ]] || continue
> 		echo "$f"
> 		return 0


Thank you for advice!  I've modified function to the following form:

# Final efect the same as previous, but in addition detects ambiguousness
# among multiple directories.  If it's not desired uncomment the line with
# "break" statement.
find_rule() {
    local rd f files=()

    [[ -f $1 ]] && { echo "$1"; return 0; }

    for rd in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
        for f in "$rd/$1" "$rd"/*-"$1"
        do
            [[ -f $f ]] || continue
            [[ ${f##*/} =~ [0-9][0-9]-.*\.rules ]] || continue
            files+=($f)
        done
        # (( ${#files[@]} >= 1 )) && break
    done

    (( ${#files[@]} < 1 )) && return 1
    (( ${#files[@]} > 1 )) && {
        derror "Ambigous rules filename.  Matches: ${files[@]}"
        return 1
    }

    echo "$files"
}


-- 
PGP key: 1024D/C284750D

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux