All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Amadeusz Żołnowski" <aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
To: Victor Lowther <victor.lowther-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter
Date: Wed, 7 Jul 2010 11:19:46 +0200	[thread overview]
Message-ID: <20100707111946.568b4775@etiriah> (raw)
In-Reply-To: <1278341637.4056.17.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1255 bytes --]

Victor Lowther <victor.lowther-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> # 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  parent reply	other threads:[~2010-07-07  9:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-05  7:06 [PATCH 1/3] dracut: info which module is sourced; updated dracut usage Amadeusz Żołnowski
2010-07-05  7:08 ` [PATCH 2/3] dracut-functions: info which udev rules are skipped Amadeusz Żołnowski
2010-07-05  7:12   ` [PATCH 3/3] dracut-functions: find_rule a bit smarter Amadeusz Żołnowski
2010-07-05  9:24     ` Amadeusz Żołnowski
2010-07-05 14:53       ` Victor Lowther
     [not found]         ` <1278341637.4056.17.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-07-07  9:19           ` Amadeusz Żołnowski [this message]
2010-07-07 10:27             ` [PATCH] dracut-functions: find_rule a bit smarter; thanks to V. Lowther Amadeusz Żołnowski
2010-07-09 13:48   ` [PATCH 2/3] dracut-functions: info which udev rules are skipped Harald Hoyer
2010-07-09 13:47 ` [PATCH 1/3] dracut: info which module is sourced; updated dracut usage Harald Hoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100707111946.568b4775@etiriah \
    --to=aidecoe-2qtfh70ttyba5ebddlwbiw@public.gmane.org \
    --cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=victor.lowther-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.