unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Kevin Ryde <user42@zip.com.au>
Cc: Chong Yidong <cyd@stupidchicken.com>,
	3911@emacsbugs.donarmstrong.com, control@bugs.debian.org
Subject: bug#3911: get-free-disk-space when default-directory doesn't exist
Date: Fri, 21 Aug 2009 23:57:20 -0400	[thread overview]
Message-ID: <jwv1vn4ec6b.fsf-monnier+emacsbugreports@gnu.org> (raw)
In-Reply-To: <87r5v7xxz5.fsf@blah.blah> (Kevin Ryde's message of "Thu, 20 Aug 2009 08:03:42 +1000")

How 'bout this patch instead (which could even work on Tramp
directories)?


        Stefan


--- files.el.~1.1069.~	2009-08-21 23:47:30.000000000 -0400
+++ files.el	2009-08-21 23:56:57.000000000 -0400
@@ -782,9 +782,12 @@
 ;;       nil)))
 
 (defun locate-dominating-file (file name)
-  "Look up the directory hierarchy from FILE for a file named NAME.
+  "Look up the directory hierarchy from FILE for a directory containing NAME.
 Stop at the first parent directory containing a file NAME,
-and return the directory.  Return nil if not found."
+and return the directory.  Return nil if not found.
+Instead of a string, NAME can also be a predicate taking one argument
+\(a directory) and returning a non-nil value if that directory is the one for
+which we're looking."
   ;; We used to use the above locate-dominating-files code, but the
   ;; directory-files call is very costly, so we're much better off doing
   ;; multiple calls using the code in here.
@@ -812,13 +815,15 @@
                     ;;   (setq user (nth 2 (file-attributes file)))
                     ;;   (and prev-user (not (equal user prev-user))))
                     (string-match locate-dominating-stop-dir-regexp file)))
-      (setq try (file-exists-p (expand-file-name name file)))
+      (setq try (if (stringp name)
+                    (file-exists-p (expand-file-name name file))
+                  (funcall name file)))
       (cond (try (setq root file))
             ((equal file (setq prev-file file
                                file (file-name-directory
                                      (directory-file-name file))))
              (setq file nil))))
-    root))
+    (file-name-as-directory root)))
 
 
 (defun executable-find (command)
@@ -5398,21 +5403,18 @@
 	(let ((fsinfo (file-system-info dir)))
 	  (if fsinfo
 	      (format "%.0f" (/ (nth 2 fsinfo) 1024))))
+      (setq dir (expand-file-name dir))
       (save-match-data
 	(with-temp-buffer
 	  (when (and directory-free-space-program
 		     ;; Avoid failure if the default directory does
 		     ;; not exist (Bug#2631, Bug#3911).
-		     (let ((default-directory default-directory))
-		       (setq dir (expand-file-name dir))
-		       (unless (and (not (file-remote-p default-directory))
-				    (file-directory-p default-directory)
-				    (file-readable-p default-directory))
-			 (setq default-directory "/"))
+		     (let ((default-directory
+                             (locate-dominating-file dir 'file-directory-p)))
 		       (eq (call-process directory-free-space-program
 					 nil t nil
 					 directory-free-space-args
-					 dir)
+					 (file-relative-name dir))
 			   0)))
 	    ;; Usual format is a header line followed by a line of
 	    ;; numbers.





  reply	other threads:[~2009-08-22  3:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <871vnclhoz.fsf@cyd.mit.edu>
2009-07-23 22:19 ` bug#3911: 23.1.50; get-free-disk-space relative to non-existent default-directory Kevin Ryde
2009-08-16  0:40   ` bug#3911: marked as done (23.1.50; get-free-disk-space relative to non-existent default-directory) Emacs bug Tracking System
2009-10-02  0:35   ` bug#3911: marked as done (get-free-disk-space race condition on default-directory test) Emacs bug Tracking System
2009-08-18  0:23 ` bug#3911: get-free-disk-space when default-directory doesn't exist Kevin Ryde
2009-08-18  1:02   ` Chong Yidong
2009-08-19 21:43     ` Kevin Ryde
2009-08-19 22:03     ` Kevin Ryde
2009-08-22  3:57       ` Stefan Monnier [this message]
2009-08-24 23:45         ` Kevin Ryde
2009-08-25 18:29           ` Stefan Monnier
2009-08-29  1:32             ` Kevin Ryde
2009-08-29  3:37               ` Stefan Monnier
2009-09-01  1:37                 ` Kevin Ryde
2009-09-01  6:05                   ` Stefan Monnier
2009-09-07  0:28                     ` Kevin Ryde
     [not found] <87d4cjzf89.fsf@cyd.mit.edu>
2009-03-10 22:24 ` bug#2631: " Kevin Ryde
2009-03-11  2:10   ` Stefan Monnier
2009-03-11  4:23     ` Eli Zaretskii
2009-03-11 21:00     ` Kevin Ryde
2009-03-15  2:40   ` bug#2631: marked as done (get-free-disk-space when default-directory doesn't exist) Emacs bug Tracking System
2009-08-16  0:40   ` bug#2631: marked as done (get-free-disk-space when home dir also " Emacs bug Tracking System
2009-03-17  0:02 ` bug#2631: get-free-disk-space when default-directory doesn't exist Kevin Ryde
2009-03-17  4:05   ` Eli Zaretskii
2009-03-27 23:32     ` Kevin Ryde
2009-03-27 23:17   ` Kevin Ryde
2009-03-27 23:25     ` Processed: " Emacs bug Tracking System

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/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1vn4ec6b.fsf-monnier+emacsbugreports@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=3911@emacsbugs.donarmstrong.com \
    --cc=control@bugs.debian.org \
    --cc=cyd@stupidchicken.com \
    --cc=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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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