From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dirk Herrmann Newsgroups: gmane.lisp.guile.devel Subject: Re: file-exists? using stat Date: Sat, 13 Sep 2003 08:00:35 +0200 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <3F62B283.40508@dirk-herrmanns-seiten.de> References: <878yoxtvmy.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1063433568 25242 80.91.224.253 (13 Sep 2003 06:12:48 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 13 Sep 2003 06:12:48 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Sep 13 08:12:46 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 19y3eI-0002BX-00 for ; Sat, 13 Sep 2003 08:12:46 +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 19y3cN-00038S-7Z for guile-devel@m.gmane.org; Sat, 13 Sep 2003 02:10:47 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19y3c7-00036f-9W for guile-devel@gnu.org; Sat, 13 Sep 2003 02:10:31 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19y3c3-00032q-NQ for guile-devel@gnu.org; Sat, 13 Sep 2003 02:10:30 -0400 Original-Received: from [212.227.126.186] (helo=moutng.kundenserver.de) by monty-python.gnu.org with esmtp (Exim 4.22) id 19y3c3-00032e-8s for guile-devel@gnu.org; Sat, 13 Sep 2003 02:10:27 -0400 Original-Received: from [212.227.126.162] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 19y3bt-0000pT-00; Sat, 13 Sep 2003 08:10:17 +0200 Original-Received: from [80.131.38.162] (helo=dirk-herrmanns-seiten.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 19y3bt-0005h2-00; Sat, 13 Sep 2003 08:10:17 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: de, en Original-To: Kevin Ryde , guile-devel@gnu.org In-Reply-To: <878yoxtvmy.fsf@zip.com.au> 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:2790 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2790 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