From: Dirk Herrmann <dirk@dirk-herrmanns-seiten.de>
Subject: Re: file-exists? using stat
Date: Sat, 13 Sep 2003 08:00:35 +0200 [thread overview]
Message-ID: <3F62B283.40508@dirk-herrmanns-seiten.de> (raw)
In-Reply-To: <878yoxtvmy.fsf@zip.com.au>
Kevin Ryde wrote:
> * boot-9.scm (file-exists?): Use stat rather than access?, so
as to
> follow the effective UID/GID not the real ID. file-exists? will
> normally be used as a prelude to opening or some other
operation, and
> it's the effective ID which will apply there.
Hello folks,
I often find that there are nice explanations for changes and so given
in the
changelog, but these are not added to the code as comments. Thus, I would
like to encourage you to add explanations to the code also, or rather
more to
the code. For someone trying to understand the code later, they should not
have to read the changelog to understand what is going on or why certain
decisions were taken.
The comments that are added to the code, however, should comment the code as
it is, not the history. Aspects that cover the history should still go
to the
changelog only. Using Kevin's example below, it would IMO for the changelog
be sufficient to add:
* boot-9.scm (file-exists?): Use stat rather than access?
while the rest of the explanation (without discussion of the fact that
former
versions of the code used access?) would be more helpful in the code than in
the changelog, like:
[...]
>--- boot-9.scm.~1.318.~ 1970-01-01 10:00:01.000000000 +1000
>+++ boot-9.scm 2003-09-08 16:11:37.000000000 +1000
>@@ -407,10 +407,12 @@
> (if (provided? 'socket)
> (primitive-load-path "ice-9/networking.scm"))
>
>+;; ENHANCE-ME: Catching an exception from stat is a bit wasteful, do
this in
>+;; C where all that's needed is to inspect the return from stat().
> (define file-exists?
> (if (provided? 'posix)
+ ;; Make sure to follow the effective UID/GID not the real ID, as it is
+ ;; done by stat. file-exists? will normally be used as a prelude to
+ ;; opening or some other operation, and it's the effective ID
which will
+ ;; apply there.
> (lambda (str)
>- (access? str F_OK))
>+ (->bool (false-if-exception (stat str))))
> (lambda (str)
> (let ((port (catch 'system-error (lambda () (open-file str
OPEN_READ))
> (lambda args #f))))
Best regards
Dirk Herrmann
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
next prev parent reply other threads:[~2003-09-13 6:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-09 23:00 file-exists? using stat Kevin Ryde
2003-09-12 19:04 ` Rob Browning
2003-09-13 6:00 ` Dirk Herrmann [this message]
2003-09-15 20:41 ` Kevin Ryde
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3F62B283.40508@dirk-herrmanns-seiten.de \
--to=dirk@dirk-herrmanns-seiten.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).