Aaron Schrab <aaron(_at_)schrab(_dot_)com> wrote:
At 14:17 +1200 27 Apr 2000, Volker Kuhlmann
<kuhlmav(_at_)elec(_dot_)canterbury(_dot_)ac(_dot_)nz> wrote:
# Most efficient way to test & mkdir
:0 ihc
* ! ? test -d $DIR
|mkdir -p $DIR
:0 wic # if needed, create today's ackdir; add sender
* $ ! TESTNAME ?? ^^$ACKS/fullacks/
| test -d $ACKS/$DATE || mkdir $ACKS/$DATE ;\
I'd say the efficiency is the same. Both versions run the external
program test, and mkdir if the test fails.
Not true. The second way runs a shell which then runs the commands.
The first way runs the commands directly, so there's one less process
used.
While I agree with you, Aaron, after looking it over, I gave up
on trying to change mine anyway. The reason is that mine is checking
an extra condition, and I don't see an easy way to get all that in
a recipe of the first (Philip's man page) format.
I tried, tentatively,
:0 whic # if needed, create today's ackdir; add sender
* $ ! TESTNAME ?? ^^$ACKS/fullacks/
* ! ? test -d $ACKS/$DATE
| mkdir -p $ACKS/$DATE;\
lockfile -r0 $ACKS/$DATE/"$FROM"
# We use lockfile in a nonstandard way[1], relying on the
# lagniappe of how it handles exit codes to avoid a possible
# race condition. -r0 says don't retry. (Mainly only
# another cascaded invocation of procmail would have
# yielded a failure, anyway. :-)
# [1] I.e., we're not using it as a semaphore but to
# create a durable file.
However, it was immediately clear to me that the lockfile trick to
create a file would not be initiated under this algorithm if there
had been no dir to begin with. Under my original algorithm, it
all works.
I see that I could divide it up into two recipes, maybe with
:0 A
| lockfile -r0 $ACKS/$DATE/"$FROM"
as the second one. But now we have two recipes to do what one
short one did before. I don't know if it's worth saving one
shell invocation. I am interested in efficiency and elegance,
both. Here we seem to have a conflicting balance between the
two. Comments?
I also have a question. I thought I needed "$" near the left
in condition lines when I am relying on a variable of mine in
the condition line. How come we don't need the "$" in the test -d
line above? This confuses me.
--
Dallman Ross <dman(_at_)nomotek(_dot_)com>
U.S. Voicemail/FAX: +1 (415) 680-2388
Residence Telephone: +49 (0) 6122 / 98 04 46
Cellular Telephone: +49 (0) 177 / 515 34 69