[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: file-exists? using stat
From: |
Dirk Herrmann |
Subject: |
Re: file-exists? using stat |
Date: |
Sat, 13 Sep 2003 08:00:35 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 |
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