From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Pittman Newsgroups: gmane.emacs.bugs,gmane.emacs.pretest.bugs Subject: bug#1135: 23.0.60; (expand-file-name ".." "/") produces surprising results Date: Sat, 11 Oct 2008 10:54:57 +1100 Organization: I know I put it down here, somewhere. Message-ID: <873aj457la.fsf@rimspace.net> References: <87k5chce0s.fsf@rimspace.net> Reply-To: Daniel Pittman , 1135@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1223683821 871 80.91.229.12 (11 Oct 2008 00:10:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 11 Oct 2008 00:10:21 +0000 (UTC) Cc: emacs-pretest-bug@gnu.org, 1135@emacsbugs.donarmstrong.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Oct 11 02:11:18 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KoS4d-0004WZ-En for geb-bug-gnu-emacs@m.gmane.org; Sat, 11 Oct 2008 02:11:11 +0200 Original-Received: from localhost ([127.0.0.1]:51158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KoS3Z-0006EX-29 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 Oct 2008 20:10:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KoS3V-0006EF-Ry for bug-gnu-emacs@gnu.org; Fri, 10 Oct 2008 20:10:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KoS3V-0006Dx-BO for bug-gnu-emacs@gnu.org; Fri, 10 Oct 2008 20:10:01 -0400 Original-Received: from [199.232.76.173] (port=42033 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KoS3V-0006Dt-8D for bug-gnu-emacs@gnu.org; Fri, 10 Oct 2008 20:10:01 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:52718) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KoS3U-0001lr-KS for bug-gnu-emacs@gnu.org; Fri, 10 Oct 2008 20:10:01 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9B09wNu010567; Fri, 10 Oct 2008 17:09:58 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m9B056dI009558; Fri, 10 Oct 2008 17:05:06 -0700 X-Loop: don@donarmstrong.com Resent-From: Daniel Pittman Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Sat, 11 Oct 2008 00:05:06 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 1135 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 1135-submit@emacsbugs.donarmstrong.com id=B1135.12236829146978 (code B ref 1135); Sat, 11 Oct 2008 00:05:06 +0000 Original-Received: (at 1135) by emacsbugs.donarmstrong.com; 10 Oct 2008 23:55:14 +0000 Original-Received: from isinu.rimspace.net (ppp59-167-189-244.static.internode.on.net [59.167.189.244]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9ANt8Rx006697 for <1135@emacsbugs.donarmstrong.com>; Fri, 10 Oct 2008 16:55:10 -0700 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by isinu.rimspace.net (Postfix) with ESMTP id F3663301BDE70; Sat, 11 Oct 2008 03:55:07 +0400 (MSD) X-Virus-Scanned: amavisd-new at Original-Received: from isinu.rimspace.net ([127.0.0.1]) by localhost (isinu.rimspace.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XVqmXtrSQgKa; Sat, 11 Oct 2008 03:54:58 +0400 (MSD) Original-Received: from krosp (unknown [172.16.23.236]) by isinu.rimspace.net (Postfix) with ESMTP id 3840A300B6AFA; Sat, 11 Oct 2008 03:54:58 +0400 (MSD) Original-Received: by krosp (Postfix, from userid 1000) id ECF697061E69; Sat, 11 Oct 2008 10:54:57 +1100 (EST) In-Reply-To: (Stefan Monnier's message of "Fri, 10 Oct 2008 13:37:25 -0400") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Fri, 10 Oct 2008 20:10:01 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:21395 gmane.emacs.pretest.bugs:23195 Archived-At: Stefan Monnier writes: >> I use some code that uses (setq dir (expand-file-name ".." dir)) to >> walk up a directory tree to the root. > > Was there any particular reason not to use: > > (setq dir (directory-file-name (file-name-directory dir))) While applying `file-name-directory' to a directory works fine and makes sense, it never occurred to me to consider that. >> I debugged this down to the unexpected (to me) behaviour of > >> (expand-file-name ".." "/") >> => "/.." > >> (expand-file-name ".." "/..") >> => "/" > > That's a bit problematic, indeed. The reason for the first behavior is > because there exist(ed) special file systems that were accessible under > /.. (IIRC machines at cs.cmu.edu around early 90s, maybe late 80s, had > such a distributed filesystem that allowed access to other machines via > /..//..., maybe there were other such things). The second is > there because nobody knows what /../.. is supposed to mean in such > a context: if /.. is a mounted filesystem, then /../.. should get you > back to /; then again if /.. is really the Root, then /../.. should just > be /..; or maybe there's a hierarchy of roots so /../.. should just stay > as /../..? *nod* I would certainly (myself) encourage this to be documented, or to be added as a machine dependent extension to the code on those particular systems. I knew about a whole bunch of odd file-name handling on various systems through the decades, but this is a new one to me. I can imagine it would be rather a shock to, for example, people used only to Windows and Linux systems. :) For what it is worth, since I hit this only via Tramp I initially assumed that it was a bug in the implementation of `expand-file-name' in that code, probably through an optimization that didn't quite work out. >> This was causing the code, which checked if the current and previous >> result of (expand-file-name ".." dir) were the same, to go into an >> infinite loop cycling between those two values... > > The more I see such problems the more I think that such code should > check (> (length before) (length after)). At least, that should > *guarantee* termination, no matter how weird expand-file-name can > behave. *nod* I had assumed that while things like Tramp and, possibly, other random platforms meant my code couldn't assume that simply walking up to `(equal dir (expand-file-name "/"))' would assure termination, a back-and-forth loop would not occur. Anyway, thank you for both the advice on a better (and terminating) approach, and your interest in the fault. My suggestion would be the documentation approach; in my Emacs the help reads, with my extension following: expand-file-name is a built-in function in `C source code'. (expand-file-name name &optional default-directory) Convert filename name to absolute, and canonicalize it. Second arg default-directory is directory to start with if name is relative (does not start with slash or tilde); if default-directory is nil or missing, the current buffer's value of `default-directory' is used. File name components that are `.' are removed, and so are file name components followed by `..', along with the `..' itself; note that these simplifications are done without checking the resulting file names in the file system. An initial `~/' expands to your home directory. An initial `~USER/' expands to USER's home directory. See also the function `substitute-in-file-name'. In some cases `expand-file-name' can return surprising results, such as expanding `..' against `/', which correctly returns `/..'; in most cases `file-name-directory' and `directory-file-name' are more appropriate for walking filesystem trees. Regards, Daniel