unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* file-exists? using stat
@ 2003-09-09 23:00 Kevin Ryde
  2003-09-12 19:04 ` Rob Browning
  2003-09-13  6:00 ` Dirk Herrmann
  0 siblings, 2 replies; 4+ messages in thread
From: Kevin Ryde @ 2003-09-09 23:00 UTC (permalink / raw)


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

        * 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.

For instance, testing before opening is precisely what
documentation.scm and slib.scm use file-exists? for.  And Emacs
file-exists-p uses stat(), I imagine for reasons along these lines.

Speaking of stat, it's actually provided unconditionally isn't it?
Meaning presumably there's no need to test (provided? 'posix) before
using it in file-is-directory? or now in file-exists?.

I'd be a bit inclined to apply this as a fix to the 1.6 branch too.


[-- Attachment #2: boot-9.scm.file-exists.diff --]
[-- Type: text/plain, Size: 613 bytes --]

--- 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)
       (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))))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: file-exists? using stat
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Rob Browning @ 2003-09-12 19:04 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> I'd be a bit inclined to apply this as a fix to the 1.6 branch too.

Agreed.  Please do.

-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: file-exists? using stat
  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
  2003-09-15 20:41   ` Kevin Ryde
  1 sibling, 1 reply; 4+ messages in thread
From: Dirk Herrmann @ 2003-09-13  6:00 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: file-exists? using stat
  2003-09-13  6:00 ` Dirk Herrmann
@ 2003-09-15 20:41   ` Kevin Ryde
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Ryde @ 2003-09-15 20:41 UTC (permalink / raw)
  Cc: guile-devel

Dirk Herrmann <dirk@dirk-herrmanns-seiten.de> writes:
>
>  +    ;; 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.

I guess I see access? as being just plain wrong, and that the gory
details concerning this are best covered in the manual (see other
message), since it's a general matter, applying to lots of places one
might think of using it.

I'll add to the code the note about what emacs does though.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-15 20:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2003-09-15 20:41   ` Kevin Ryde

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).