procmail
[Top] [All Lists]

Re: testing for existence of a file without a fork

2002-05-02 11:14:24
Is there a way to test for a plain file's existence with procmail internals?

I can't help but feel that there should be through the lockfiles -
something equivalent to the command-line

  lockfile -0 -r0 plainfile

which returns 0 (true) if it could lock the file - hence the file didn't
already exist - and non-zero if it could not.  Those options say don't
wait if you can't get a lock, and don't retry.

But I don't think there are sufficient options with the in-procmail
locking to do that (I can't think of a way to say "don't retry, and
fail if you can't get a lock").

Failing that, on a system where /bin/test is a shell script, what would you
folks recommend as a small, cheap-to-run fork that (1) can take a filename as
a positional parameter [so that there's no need to fork a shell to handle
"<"], (2) will exit with an error if the file doesn't exist. and (3) will not
read the whole blasted file if it does exist and is long.  The best I can
think of is head -0.

The above lockfile command should be reasonably lightweight!

Cheers,
Martin
-- 
Martin McCarthy                 /</    http://procmail.non-prophet.org
    `Procmail Companion'        \>\
     Addison Wesley             /</                  PGP key available
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail