From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: file-exists? using stat Date: Wed, 10 Sep 2003 09:00:37 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <878yoxtvmy.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1063154262 29807 80.91.224.253 (10 Sep 2003 00:37:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 10 Sep 2003 00:37:42 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Sep 10 02:37:40 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19wszM-0000bf-00 for ; Wed, 10 Sep 2003 02:37:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19wsz9-00022Q-IP for guile-devel@m.gmane.org; Tue, 09 Sep 2003 20:37:27 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19wrbP-0003Z8-VI for guile-devel@gnu.org; Tue, 09 Sep 2003 19:08:51 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19wrUS-0001IQ-JG for guile-devel@gnu.org; Tue, 09 Sep 2003 19:01:41 -0400 Original-Received: from [61.8.0.36] (helo=snoopy.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.22) id 19wrTd-0000d4-Lz for guile-devel@gnu.org; Tue, 09 Sep 2003 19:00:49 -0400 Original-Received: from mongrel.pacific.net.au (mongrel.pacific.net.au [61.8.0.107]) by snoopy.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h89N0lBt003347 for ; Wed, 10 Sep 2003 09:00:47 +1000 Original-Received: from localhost (ppp111.dyn228.pacific.net.au [203.143.228.111]) by mongrel.pacific.net.au (8.12.3/8.12.3/Debian-6.4) with ESMTP id h89Mx73G008879 for ; Wed, 10 Sep 2003 08:59:08 +1000 Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19wrTS-0000hJ-00; Wed, 10 Sep 2003 09:00:38 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2775 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2775 --=-=-= * 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. --=-=-= Content-Disposition: attachment; filename=boot-9.scm.file-exists.diff --- 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)))) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel --=-=-=--