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

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