unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: file-exists? using stat
Date: Wed, 10 Sep 2003 09:00:37 +1000	[thread overview]
Message-ID: <878yoxtvmy.fsf@zip.com.au> (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

             reply	other threads:[~2003-09-09 23:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-09 23:00 Kevin Ryde [this message]
2003-09-12 19:04 ` file-exists? using stat Rob Browning
2003-09-13  6:00 ` Dirk Herrmann
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=878yoxtvmy.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /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).