unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#2631: get-free-disk-space when default-directory doesn't exist
@ 2009-03-10 22:24 ` Kevin Ryde
  2009-03-11  2:10   ` Stefan Monnier
                     ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-03-10 22:24 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1389 bytes --]

Evaluating

    (with-temp-buffer
      (setq default-directory "/no/such/dir")
      (get-free-disk-space "/tmp"))

gets an error

    (file-error "Setting current directory" "no such file or directory" "/no/such/dir")

where I hoped it wouldn't care about default-directory, only the given
directory argument.  Perhaps a let-bind per below.



In GNU Emacs 22.2.1 (i486-pc-linux-gnu, GTK+ Version 2.12.11)
 of 2008-11-10 on raven, modified by Debian
configured using `configure  '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs22:/etc/emacs:/usr/local/share/emacs/22.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/22.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/22.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU
  locale-coding-system: iso-8859-1
  default-enable-multibyte-characters: t



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.free-space.diff --]
[-- Type: text/x-diff, Size: 980 bytes --]

*** files.el	11 Mar 2009 08:46:04 +1100	1.1038
--- files.el	11 Mar 2009 09:14:14 +1100	
***************
*** 5336,5345 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (eq 0 (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5336,5346 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
!                      (let ((default-directory "/"))
!                        (eq 0 (call-process directory-free-space-program
!                                            nil t nil
!                                            directory-free-space-args
!                                            dir))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
  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
  2 siblings, 2 replies; 26+ messages in thread
From: Stefan Monnier @ 2009-03-11  2:10 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: bug-gnu-emacs, 2631

> *** files.el	11 Mar 2009 08:46:04 +1100	1.1038
> --- files.el	11 Mar 2009 09:14:14 +1100	
> ***************
> *** 5336,5345 ****
>         (save-match-data
>   	(with-temp-buffer
>   	  (when (and directory-free-space-program
> ! 		     (eq 0 (call-process directory-free-space-program
> ! 					 nil t nil
> ! 					 directory-free-space-args
> ! 					 dir)))
>   	    ;; Usual format is a header line followed by a line of
>   	    ;; numbers.
>   	    (goto-char (point-min))
> --- 5336,5346 ----
>         (save-match-data
>   	(with-temp-buffer
>   	  (when (and directory-free-space-program
> !                      (let ((default-directory "/"))
> !                        (eq 0 (call-process directory-free-space-program
> !                                            nil t nil
> !                                            directory-free-space-args
> !                                            dir))))
>   	    ;; Usual format is a header line followed by a line of
>   	    ;; numbers.
>   	    (goto-char (point-min))

That would probably work OK, but why not bind default-directory to dir?
And even use process-file, while we're at it, so it has a chance to work
on Tramp.


        Stefan








^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
  2009-03-11  2:10   ` Stefan Monnier
@ 2009-03-11  4:23     ` Eli Zaretskii
  2009-03-11 21:00     ` Kevin Ryde
  1 sibling, 0 replies; 26+ messages in thread
From: Eli Zaretskii @ 2009-03-11  4:23 UTC (permalink / raw)
  To: Stefan Monnier, 2631; +Cc: user42

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Tue, 10 Mar 2009 22:10:13 -0400
> Cc: bug-gnu-emacs@gnu.org, 2631@emacsbugs.donarmstrong.com
> 
> > *** files.el	11 Mar 2009 08:46:04 +1100	1.1038
> > --- files.el	11 Mar 2009 09:14:14 +1100	
> > ***************
> > *** 5336,5345 ****
> >         (save-match-data
> >   	(with-temp-buffer
> >   	  (when (and directory-free-space-program
> > ! 		     (eq 0 (call-process directory-free-space-program
> > ! 					 nil t nil
> > ! 					 directory-free-space-args
> > ! 					 dir)))
> >   	    ;; Usual format is a header line followed by a line of
> >   	    ;; numbers.
> >   	    (goto-char (point-min))
> > --- 5336,5346 ----
> >         (save-match-data
> >   	(with-temp-buffer
> >   	  (when (and directory-free-space-program
> > !                      (let ((default-directory "/"))
> > !                        (eq 0 (call-process directory-free-space-program
> > !                                            nil t nil
> > !                                            directory-free-space-args
> > !                                            dir))))
> >   	    ;; Usual format is a header line followed by a line of
> >   	    ;; numbers.
> >   	    (goto-char (point-min))
> 
> That would probably work OK, but why not bind default-directory to dir?

Yes, this is much better, since "/" is not guaranteed to work
(accessibility and stuff).

> And even use process-file, while we're at it, so it has a chance to work
> on Tramp.

Even better.






^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
  2009-03-11  2:10   ` Stefan Monnier
  2009-03-11  4:23     ` Eli Zaretskii
@ 2009-03-11 21:00     ` Kevin Ryde
  1 sibling, 0 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-03-11 21:00 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 2631

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> why not bind default-directory to dir?

I think that'd make it error out on a non-existant dir argument, where
currently it returns nil (from the df parsing code, and it looks like
from file-system-info in dosfns.c).

There's a few other places binding to "/", like man.el and message.el,
if it ought to be something else ...






^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: marked as done (get-free-disk-space when  default-directory doesn't exist)
  2009-03-10 22:24 ` bug#2631: " Kevin Ryde
  2009-03-11  2:10   ` Stefan Monnier
@ 2009-03-15  2:40   ` 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
  2 siblings, 0 replies; 26+ messages in thread
From: Emacs bug Tracking System @ 2009-03-15  2:40 UTC (permalink / raw)
  To: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]


Your message dated Sat, 14 Mar 2009 22:34:14 -0400
with message-id <87d4cjzf89.fsf@cyd.mit.edu>
and subject line Re: bug#2631: get-free-disk-space when default-directory doesn't exist
has caused the Emacs bug report #2631,
regarding get-free-disk-space when default-directory doesn't exist
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@emacsbugs.donarmstrong.com
immediately.)


-- 
2631: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=2631
Emacs Bug Tracking System
Contact owner@emacsbugs.donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 4871 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 1389 bytes --]

Evaluating

    (with-temp-buffer
      (setq default-directory "/no/such/dir")
      (get-free-disk-space "/tmp"))

gets an error

    (file-error "Setting current directory" "no such file or directory" "/no/such/dir")

where I hoped it wouldn't care about default-directory, only the given
directory argument.  Perhaps a let-bind per below.



In GNU Emacs 22.2.1 (i486-pc-linux-gnu, GTK+ Version 2.12.11)
 of 2008-11-10 on raven, modified by Debian
configured using `configure  '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs22:/etc/emacs:/usr/local/share/emacs/22.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/22.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/22.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU
  locale-coding-system: iso-8859-1
  default-enable-multibyte-characters: t



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: files.el.free-space.diff --]
[-- Type: text/x-diff, Size: 980 bytes --]

*** files.el	11 Mar 2009 08:46:04 +1100	1.1038
--- files.el	11 Mar 2009 09:14:14 +1100	
***************
*** 5336,5345 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (eq 0 (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5336,5346 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
!                      (let ((default-directory "/"))
!                        (eq 0 (call-process directory-free-space-program
!                                            nil t nil
!                                            directory-free-space-args
!                                            dir))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

[-- Attachment #3: Type: message/rfc822, Size: 1729 bytes --]

From: Chong Yidong <cyd@stupidchicken.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Kevin Ryde <user42@zip.com.au>, Eli Zaretskii <eliz@gnu.org>, 2631-done@emacsbugs.donarmstrong.com
Subject: Re: bug#2631: get-free-disk-space when default-directory doesn't exist
Date: Sat, 14 Mar 2009 22:34:14 -0400
Message-ID: <87d4cjzf89.fsf@cyd.mit.edu>

Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> That would probably work OK, but why not bind default-directory to
> dir?  And even use process-file, while we're at it, so it has a chance
> to work on Tramp.

I don't think there's any chance to make get-free-disk-space to work on
remote files without major surgery (it currently returns nil immediately
if the file is remote).

I've checked in a modified version of Kevin's patch, which sets
default-directory to "~/" rather than "/", but only if the existing
default-directory is not usable.


^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
       [not found] <87d4cjzf89.fsf@cyd.mit.edu>
  2009-03-10 22:24 ` bug#2631: " Kevin Ryde
@ 2009-03-17  0:02 ` Kevin Ryde
  2009-03-17  4:05   ` Eli Zaretskii
  2009-03-27 23:17   ` Kevin Ryde
  1 sibling, 2 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-03-17  0:02 UTC (permalink / raw)
  To: Chong Yidong; +Cc: 2631

[-- Attachment #1: Type: text/plain, Size: 642 bytes --]

Chong Yidong <cyd@stupidchicken.com> writes:
>
> default-directory to "~/" rather than "/"

What is it that's not good about "/"?  It doesn't have to be readable or
anything I don't think, just somewhere capable of a chdir().  Wouldn't
it be the only thing certain to work with chdir()?  As I mentioned
before there's other places using "/" for the same purpose if there's
something wrong with it.


Either way what I missed from my first post was that a change to
default-directory ought to absolutize the given dir argument, so that
say

    (get-free-disk-space ".")

gives info about the original default-directory, not the mangled one.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.disk-space-expand.diff --]
[-- Type: text/x-diff, Size: 426 bytes --]

*** files.el	17 Mar 2009 10:35:50 +1100	1.1040
--- files.el	17 Mar 2009 10:53:40 +1100	
***************
*** 5341,5346 ****
--- 5341,5347 ----
  				      (file-directory-p default-directory)
  				      (file-readable-p default-directory))
  				 default-directory
+ 			       (setq dir (expand-file-name dir))
  			       (expand-file-name "~/"))))
  		       (eq (call-process directory-free-space-program
  					 nil t nil

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
  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
  1 sibling, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2009-03-17  4:05 UTC (permalink / raw)
  To: Kevin Ryde, 2631; +Cc: cyd

> From: Kevin Ryde <user42@zip.com.au>
> Date: Tue, 17 Mar 2009 11:02:26 +1100
> Cc: 2631@emacsbugs.donarmstrong.com
> 
> > default-directory to "~/" rather than "/"
> 
> What is it that's not good about "/"?  It doesn't have to be readable or
> anything I don't think, just somewhere capable of a chdir().

Doesn't chdir need certain rights? what if the user doesn't have them?

> Either way what I missed from my first post was that a change to
> default-directory ought to absolutize the given dir argument, so that
> say
> 
>     (get-free-disk-space ".")
> 
> gives info about the original default-directory, not the mangled one.

What "mangled one"?






^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
  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:17   ` Kevin Ryde
  2009-03-27 23:25     ` Processed: " Emacs bug Tracking System
  1 sibling, 1 reply; 26+ messages in thread
From: Kevin Ryde @ 2009-03-27 23:17 UTC (permalink / raw)
  To: control, 2631

[-- Attachment #1: Type: text/plain, Size: 915 bytes --]

reopen 2631
retitle 2631 get-free-disk-space when home dir also doesn't exist
tags 2631 +patch
thanks

If both default-directory and home directory both don't exist
get-free-disk-space still gets an error

    (progn
      (setq default-directory "/no/such/dir")
      (setenv "HOME" "/another/no/such/dir")
      (get-free-disk-space "/"))
    => (file-error "Setting current directory" "no such file or directory" "/another/no/such/dir/")

Although plenty of things probably depend on a home dir I don't think
get-free-disk-space needs to be one of them.

Change below is like what's also in the following funcs, I believe for
the same purpose, ie. just to make sure call-process will be happy, when
the program run doesn't care about the current directory.

    Man-init-defvars,
    mail-source-movemail
    message-send-mail-with-sendmail
    sendmail-send-it
    gamegrid-add-score-with-update-game-score-1



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.disk-space-root.diff --]
[-- Type: text/x-diff, Size: 1202 bytes --]

*** files.el	28 Mar 2009 09:50:47 +1100	1.1041
--- files.el	28 Mar 2009 09:56:48 +1100	
***************
*** 5336,5352 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (let ((default-directory
! 			     (if (and (not (file-remote-p default-directory))
! 				      (file-directory-p default-directory)
! 				      (file-readable-p default-directory))
! 				 default-directory
! 			       (expand-file-name "~/"))))
! 		       (eq (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)
! 			   0)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5336,5349 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (progn
! 		       (setq dir (expand-file-name dir)) ;; in case relative
! 		       (let ((default-directory "/"))
! 			 (eq (call-process directory-free-space-program
! 					   nil t nil
! 					   directory-free-space-args
! 					   dir)
! 			     0))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Processed: Re: bug#2631: get-free-disk-space when default-directory doesn't exist
  2009-03-27 23:17   ` Kevin Ryde
@ 2009-03-27 23:25     ` Emacs bug Tracking System
  0 siblings, 0 replies; 26+ messages in thread
From: Emacs bug Tracking System @ 2009-03-27 23:25 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: Emacs Bugs

Processing commands for control@emacsbugs.donarmstrong.com:

> reopen 2631
bug#2631: get-free-disk-space when default-directory doesn't exist
bug reopened, originator not changed.

> retitle 2631 get-free-disk-space when home dir also doesn't exist
bug#2631: get-free-disk-space when default-directory doesn't exist
Changed bug title to `get-free-disk-space when home dir also doesn't exist' from `get-free-disk-space when default-directory doesn't exist'.

> tags 2631 +patch
bug#2631: get-free-disk-space when home dir also doesn't exist
There were no tags set.
Tags added: patch

> thanks
Stopping processing here.

Please contact me if you need assistance.

Don Armstrong
(administrator, Emacs bugs database)




^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: get-free-disk-space when default-directory doesn't exist
  2009-03-17  4:05   ` Eli Zaretskii
@ 2009-03-27 23:32     ` Kevin Ryde
  0 siblings, 0 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-03-27 23:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 2631

Eli Zaretskii <eliz@gnu.org> writes:
>
> Doesn't chdir need certain rights?

Only search perms in the parent directories leading to a given dir, I
believe.

I suppose the root dir could be unreadable/unsearchable too.  Dunno what
chdir would do in that case (I'm not brave enough to try it either!) but
certainly if the root dir is unsearchable then no subdir can work.






^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: 23.1.50; get-free-disk-space relative to non-existent default-directory
@ 2009-07-23 22:19 ` 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
  0 siblings, 2 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-07-23 22:19 UTC (permalink / raw)
  To: emacs-pretest-bug

[-- Attachment #1: Type: text/plain, Size: 1039 bytes --]

On a non-existent directory get-free-disk-space returns nil, eg.

    (get-free-disk-space "/no/such/dir")
    => nil

But if it's done by a relative path from a default-directory which
doesn't exist, then the answer is the space in your home directory

    (let ((default-directory "/no/such/dir"))
      (get-free-disk-space "."))
    => 3705637

I hoped the two answers would be the same.

This is with the "df"-running code in get-free-disk-space, ie. no
`file-system-info' function.

Perhaps absolutize per below with an inserted setq, the diff being just
re-indent.

(I still think the use of the home dir there is either complicated and
unnecessary, or complicated and necessary everywhere.  Or maybe better
call-process could not attempt a chdir at all if a caller doesn't care
about the current directory.  But leaving that unchanged as yet.)

2009-07-24  Kevin Ryde  <user42@zip.com.au>

	* files.el (get-free-disk-space): Absolutize the dir before
	changing default-directory, so as not to answer about a different
	directory.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.disk-space-absolutize.diff --]
[-- Type: text/x-diff, Size: 1795 bytes --]

*** files.el	24 Jul 2009 07:35:37 +1000	1.1063
--- files.el	24 Jul 2009 08:07:01 +1000	
***************
*** 5394,5410 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (let ((default-directory
! 			     (if (and (not (file-remote-p default-directory))
! 				      (file-directory-p default-directory)
! 				      (file-readable-p default-directory))
! 				 default-directory
! 			       (expand-file-name "~/"))))
! 		       (eq (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)
! 			   0)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5394,5413 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
!                      (progn
!                        ;; absolutize before changing default-directory
!                        (setq dir (expand-file-name dir))
!                        (let ((default-directory
!                                (if (and (not (file-remote-p default-directory))
!                                         (file-directory-p default-directory)
!                                         (file-readable-p default-directory))
!                                    default-directory
!                                  (expand-file-name "~/"))))
!                          (eq (call-process directory-free-space-program
!                                            nil t nil
!                                            directory-free-space-args
!                                            dir)
!                              0))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

[-- Attachment #3: Type: text/plain, Size: 539 bytes --]






In GNU Emacs 23.1.50.4 (i586-pc-linux-gnu, GTK+ Version 2.16.4)
 of 2009-07-24 on blah.blah
configured using `configure  'CFLAGS=-O -g' '--prefix=/down/emacs/b/inst' '--with-x-toolkit=gtk''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU
  value of $XMODIFIERS: nil
  locale-coding-system: iso-latin-1-unix
  default-enable-multibyte-characters: t

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#2631: marked as done (get-free-disk-space when home dir also doesn't exist)
  2009-03-10 22:24 ` bug#2631: " Kevin Ryde
  2009-03-11  2:10   ` Stefan Monnier
  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   ` Emacs bug Tracking System
  2 siblings, 0 replies; 26+ messages in thread
From: Emacs bug Tracking System @ 2009-08-16  0:40 UTC (permalink / raw)
  To: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]


Your message dated Sat, 15 Aug 2009 20:34:52 -0400
with message-id <871vnclhoz.fsf@cyd.mit.edu>
and subject line Re: get-free-disk-space when default-directory doesn't exist
has caused the Emacs bug report #2631,
regarding get-free-disk-space when home dir also doesn't exist
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@emacsbugs.donarmstrong.com
immediately.)


-- 
2631: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=2631
Emacs Bug Tracking System
Contact owner@emacsbugs.donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 4871 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 1389 bytes --]

Evaluating

    (with-temp-buffer
      (setq default-directory "/no/such/dir")
      (get-free-disk-space "/tmp"))

gets an error

    (file-error "Setting current directory" "no such file or directory" "/no/such/dir")

where I hoped it wouldn't care about default-directory, only the given
directory argument.  Perhaps a let-bind per below.



In GNU Emacs 22.2.1 (i486-pc-linux-gnu, GTK+ Version 2.12.11)
 of 2008-11-10 on raven, modified by Debian
configured using `configure  '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs22:/etc/emacs:/usr/local/share/emacs/22.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/22.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/22.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU
  locale-coding-system: iso-8859-1
  default-enable-multibyte-characters: t



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: files.el.free-space.diff --]
[-- Type: text/x-diff, Size: 980 bytes --]

*** files.el	11 Mar 2009 08:46:04 +1100	1.1038
--- files.el	11 Mar 2009 09:14:14 +1100	
***************
*** 5336,5345 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (eq 0 (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5336,5346 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
!                      (let ((default-directory "/"))
!                        (eq 0 (call-process directory-free-space-program
!                                            nil t nil
!                                            directory-free-space-args
!                                            dir))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

[-- Attachment #3: Type: message/rfc822, Size: 1613 bytes --]

From: Chong Yidong <cyd@stupidchicken.com>
To: Kevin Ryde <user42@zip.com.au>
Cc: 2631-done@emacsbugs.donarmstrong.com, 3911-done@emacsbugs.donarmstrong.com
Subject: Re: get-free-disk-space when default-directory doesn't exist
Date: Sat, 15 Aug 2009 20:34:52 -0400
Message-ID: <871vnclhoz.fsf@cyd.mit.edu>

> What is it that's not good about "/"?  It doesn't have to be readable
> or anything I don't think, just somewhere capable of a chdir()...  If
> both default-directory and home directory both don't exist
> get-free-disk-space still gets an error

You're right; it's probably better to fall back on / instead of ~.  I've
just checked in your suggested change.

> (let ((default-directory "/no/such/dir"))
>   (get-free-disk-space "."))
> => 3705637

I checked in your suggestion to do expand-file-name before changing the
default-directory, as well.  Thanks.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: marked as done (23.1.50; get-free-disk-space relative to non-existent default-directory)
  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   ` 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
  1 sibling, 0 replies; 26+ messages in thread
From: Emacs bug Tracking System @ 2009-08-16  0:40 UTC (permalink / raw)
  To: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]


Your message dated Sat, 15 Aug 2009 20:34:52 -0400
with message-id <871vnclhoz.fsf@cyd.mit.edu>
and subject line Re: get-free-disk-space when default-directory doesn't exist
has caused the Emacs bug report #3911,
regarding 23.1.50; get-free-disk-space relative to non-existent default-directory
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@emacsbugs.donarmstrong.com
immediately.)


-- 
3911: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3911
Emacs Bug Tracking System
Contact owner@emacsbugs.donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 5863 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 1039 bytes --]

On a non-existent directory get-free-disk-space returns nil, eg.

    (get-free-disk-space "/no/such/dir")
    => nil

But if it's done by a relative path from a default-directory which
doesn't exist, then the answer is the space in your home directory

    (let ((default-directory "/no/such/dir"))
      (get-free-disk-space "."))
    => 3705637

I hoped the two answers would be the same.

This is with the "df"-running code in get-free-disk-space, ie. no
`file-system-info' function.

Perhaps absolutize per below with an inserted setq, the diff being just
re-indent.

(I still think the use of the home dir there is either complicated and
unnecessary, or complicated and necessary everywhere.  Or maybe better
call-process could not attempt a chdir at all if a caller doesn't care
about the current directory.  But leaving that unchanged as yet.)

2009-07-24  Kevin Ryde  <user42@zip.com.au>

	* files.el (get-free-disk-space): Absolutize the dir before
	changing default-directory, so as not to answer about a different
	directory.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: files.el.disk-space-absolutize.diff --]
[-- Type: text/x-diff, Size: 1795 bytes --]

*** files.el	24 Jul 2009 07:35:37 +1000	1.1063
--- files.el	24 Jul 2009 08:07:01 +1000	
***************
*** 5394,5410 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (let ((default-directory
! 			     (if (and (not (file-remote-p default-directory))
! 				      (file-directory-p default-directory)
! 				      (file-readable-p default-directory))
! 				 default-directory
! 			       (expand-file-name "~/"))))
! 		       (eq (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)
! 			   0)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5394,5413 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
!                      (progn
!                        ;; absolutize before changing default-directory
!                        (setq dir (expand-file-name dir))
!                        (let ((default-directory
!                                (if (and (not (file-remote-p default-directory))
!                                         (file-directory-p default-directory)
!                                         (file-readable-p default-directory))
!                                    default-directory
!                                  (expand-file-name "~/"))))
!                          (eq (call-process directory-free-space-program
!                                            nil t nil
!                                            directory-free-space-args
!                                            dir)
!                              0))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

[-- Attachment #2.1.3: Type: text/plain, Size: 539 bytes --]






In GNU Emacs 23.1.50.4 (i586-pc-linux-gnu, GTK+ Version 2.16.4)
 of 2009-07-24 on blah.blah
configured using `configure  'CFLAGS=-O -g' '--prefix=/down/emacs/b/inst' '--with-x-toolkit=gtk''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU
  value of $XMODIFIERS: nil
  locale-coding-system: iso-latin-1-unix
  default-enable-multibyte-characters: t

[-- Attachment #3: Type: message/rfc822, Size: 1646 bytes --]

From: Chong Yidong <cyd@stupidchicken.com>
To: Kevin Ryde <user42@zip.com.au>
Cc: 2631-done@emacsbugs.donarmstrong.com, 3911-done@emacsbugs.donarmstrong.com
Subject: Re: get-free-disk-space when default-directory doesn't exist
Date: Sat, 15 Aug 2009 20:34:52 -0400
Message-ID: <871vnclhoz.fsf@cyd.mit.edu>

> What is it that's not good about "/"?  It doesn't have to be readable
> or anything I don't think, just somewhere capable of a chdir()...  If
> both default-directory and home directory both don't exist
> get-free-disk-space still gets an error

You're right; it's probably better to fall back on / instead of ~.  I've
just checked in your suggested change.

> (let ((default-directory "/no/such/dir"))
>   (get-free-disk-space "."))
> => 3705637

I checked in your suggestion to do expand-file-name before changing the
default-directory, as well.  Thanks.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
       [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-18  0:23 ` Kevin Ryde
  2009-08-18  1:02   ` Chong Yidong
  1 sibling, 1 reply; 26+ messages in thread
From: Kevin Ryde @ 2009-08-18  0:23 UTC (permalink / raw)
  To: Chong Yidong; +Cc: 3911

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

Chong Yidong <cyd@stupidchicken.com> writes:
>
> You're right; it's probably better to fall back on / instead of ~.

I think the test for file-remote-p is covered by the first line of the
func so it's not needed in the dir condition bit, per below.


I still think "/" might as well be used unconditionally though.  The
reason I'm still banging on about that is that there's probably 3 or 4
other places in emacs which also don't care about the current directory
when spawning a program.  They would make use of the same idiom,
whatever it might best be.  (I arrived at this first when some of my own
code bombed in a non-existent default-directory.  I've seen it in other
people's code too.)



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.disk-space-noremote.diff --]
[-- Type: text/x-diff, Size: 882 bytes --]

*** files.el	18 Aug 2009 08:51:19 +1000	1.1068
--- files.el	18 Aug 2009 10:12:22 +1000	
***************
*** 5400,5407 ****
  		     ;; 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 "/"))
  		       (eq (call-process directory-free-space-program
--- 5400,5406 ----
  		     ;; not exist (Bug#2631, Bug#3911).
  		     (let ((default-directory default-directory))
  		       (setq dir (expand-file-name dir))
! 		       (unless (and (file-directory-p default-directory)
  				    (file-readable-p default-directory))
  			 (setq default-directory "/"))
  		       (eq (call-process directory-free-space-program

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  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
  0 siblings, 2 replies; 26+ messages in thread
From: Chong Yidong @ 2009-08-18  1:02 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: 3911

Kevin Ryde <user42@zip.com.au> writes:

> I think the test for file-remote-p is covered by the first line of the
> func so it's not needed in the dir condition bit, per below.

But that applies to DIR, not default-directory.

> I still think "/" might as well be used unconditionally though.

Principle of least surprise.  If we don't have to change the default
directory, let's not, even if it seems harmless (because we can never be
sure of every eventuality).





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-18  1:02   ` Chong Yidong
@ 2009-08-19 21:43     ` Kevin Ryde
  2009-08-19 22:03     ` Kevin Ryde
  1 sibling, 0 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-08-19 21:43 UTC (permalink / raw)
  To: Chong Yidong; +Cc: 3911

Chong Yidong <cyd@stupidchicken.com> writes:
>
> But that applies to DIR, not default-directory.

Oops, I confused myself thinking the given dir could be used there.

> Principle of least surprise.  If we don't have to change the default
> directory, let's not,

Err, well, I think the unhappy surprise may be if an operation about one
directory depends on what's happening in another directory ...





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  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
  1 sibling, 1 reply; 26+ messages in thread
From: Kevin Ryde @ 2009-08-19 22:03 UTC (permalink / raw)
  To: control, 3911; +Cc: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 1983 bytes --]

reopen 3911
retitle 3911 get-free-disk-space race condition on default-directory test
tags 3911 +patch
thanks

If the default-directory is flicking in and out of existence then the
code in get-free-disk-space which chooses between default-directory and
"/" can suffer a race condition.  default-directory can exist for the
test, but then be gone by the time call-process tries to use it.

I can provoke this on my pc with one emacs making a directory flicker,

    (while t
      (make-directory "/tmp/somedir")
      (delete-directory "/tmp/somedir"))

And in another emacs a loop

    (while t
      (let ((default-directory "/tmp/somedir/"))
        (get-free-disk-space "/")))

The latter loop errors out after 5 or 10 minutes.  I hoped that asking
get-free-disk-space about the space on some directory would not depend
on the value of default-directory.

The problem can be provoked much quicker with a (sit-for 0.1) between
the test and the call-process.  Otherwise I presume it requires a random
context switch just at the inopportune time.


The perils of "test before use" come up in shell scripts often (because
it's hard to do better), and in sloppy perl code.  Alas the tendency is
to work most of the time, but lack robustness in special circumstances.

I suppose the rule for call-process would be: if the operation is not
related to default-directory then go to "/" so as to be independent of
default-directory's existence, or bouncing in and out of existence.  I
expect that's why other places have "/".  It sounds fairly simple, dunno
if that's too obvious to have a crib in the manual (under "Subprocess
Creation").

At any rate, umm, third time lucky with what I posted first ...


2009-08-20  Kevin Ryde  <user42@zip.com.au>

	* files.el (get-free-disk-space): Bind default-directory to "/", to be
	independent of default-directory existence.  (Cannot test usability of
	default-directory first since it may disappear in between the test and
	the call-process.)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: files.el.disk-space-root-2.diff --]
[-- Type: text/x-diff, Size: 1028 bytes --]

*** files.el	18 Aug 2009 08:51:19 +1000	1.1068
--- files.el	20 Aug 2009 08:03:13 +1000	
***************
*** 5398,5409 ****
  	  (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 "/"))
  		       (eq (call-process directory-free-space-program
  					 nil t nil
  					 directory-free-space-args
--- 5398,5405 ----
  	  (when (and directory-free-space-program
  		     ;; Avoid failure if the default directory does
  		     ;; not exist (Bug#2631, Bug#3911).
! 		     (setq dir (expand-file-name dir))
! 		     (let ((default-directory "/"))
  		       (eq (call-process directory-free-space-program
  					 nil t nil
  					 directory-free-space-args

^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-19 22:03     ` Kevin Ryde
@ 2009-08-22  3:57       ` Stefan Monnier
  2009-08-24 23:45         ` Kevin Ryde
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2009-08-22  3:57 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: Chong Yidong, 3911, control

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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-22  3:57       ` Stefan Monnier
@ 2009-08-24 23:45         ` Kevin Ryde
  2009-08-25 18:29           ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Kevin Ryde @ 2009-08-24 23:45 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chong Yidong, 3911

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> How 'bout this patch instead (which could even work on Tramp
> directories)?

I don't think so.  It's still a race condition in between choosing an
apparently existent directory and then making use of that directory,
isn't it?  I think "/" is the only place certain to exist and not go
away.  It's also the simplest approach.

`sha1-string-external' is another place this comes up.  In that case the
operation is completely unrelated to any directory, and so really should
go to "/" so as to be independent of default-directory or whether that
dir is coming or going.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-24 23:45         ` Kevin Ryde
@ 2009-08-25 18:29           ` Stefan Monnier
  2009-08-29  1:32             ` Kevin Ryde
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2009-08-25 18:29 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: Chong Yidong, 3911

>> How 'bout this patch instead (which could even work on Tramp
>> directories)?
> I don't think so.  It's still a race condition in between choosing an
> apparently existent directory and then making use of that directory,
> isn't it?

Emacs is made of such race conditions.  But there's a big difference
between DIR and/or its parents appearing/disappearing (as in my patch),
vs $HOME or some other unrealted directory appearing/disappearing.

> I think "/" is the only place certain to exist and not go
> away.  It's also the simplest approach.

I'd like to make it work for Tramp dirs as well.

> `sha1-string-external' is another place this comes up.  In that case the
> operation is completely unrelated to any directory, and so really should
> go to "/" so as to be independent of default-directory or whether that
> dir is coming or going.

For that one, yes, "/" is clearly a better choice.


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-25 18:29           ` Stefan Monnier
@ 2009-08-29  1:32             ` Kevin Ryde
  2009-08-29  3:37               ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Kevin Ryde @ 2009-08-29  1:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Chong Yidong, 3911

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
>
> Emacs is made of such race conditions.

But this one is easy to avoid.  I really don't understand why this bug
has gone on and on.  What's the objection to "/"?  As far as I can tell
it's smaller, faster, and certain to work.  (Faster especially if
there's some nfs or ftpfs or similar involved where a system chdir may
do some evil remote query.)

> I'd like to make it work for Tramp dirs as well.

Sounds good.  Tramp holds open a session doesn't it, so at least there'd
be no call-process to worry about for it. :)





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-29  1:32             ` Kevin Ryde
@ 2009-08-29  3:37               ` Stefan Monnier
  2009-09-01  1:37                 ` Kevin Ryde
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2009-08-29  3:37 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: Chong Yidong, 3911

>> Emacs is made of such race conditions.
> But this one is easy to avoid.  I really don't understand why this bug
> has gone on and on.  What's the objection to "/"?  As far as I can tell
> it's smaller, faster, and certain to work.  (Faster especially if
> there's some nfs or ftpfs or similar involved where a system chdir may
> do some evil remote query.)

The objection to / is only that it doesn't work for Tramp.

>> I'd like to make it work for Tramp dirs as well.
> Sounds good.  Tramp holds open a session doesn't it, so at least there'd
> be no call-process to worry about for it. :)

I don't know what you're referring to.


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-08-29  3:37               ` Stefan Monnier
@ 2009-09-01  1:37                 ` Kevin Ryde
  2009-09-01  6:05                   ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Kevin Ryde @ 2009-09-01  1:37 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 3911

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> The objection to / is only that it doesn't work for Tramp.

Umm, now it's me that doesn't understand! - the "df"-running part is for
local queries, ie. not-tramp, isn't it?  (No remotes at all, so not
ange-ftp or whatnot either ...?)





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-09-01  1:37                 ` Kevin Ryde
@ 2009-09-01  6:05                   ` Stefan Monnier
  2009-09-07  0:28                     ` Kevin Ryde
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2009-09-01  6:05 UTC (permalink / raw)
  To: Kevin Ryde; +Cc: 3911

>> The objection to / is only that it doesn't work for Tramp.
> Umm, now it's me that doesn't understand! - the "df"-running part is for
> local queries, ie. not-tramp, isn't it?  (No remotes at all, so not
> ange-ftp or whatnot either ...?)

Right now, it is.  But using my patch, together with changing
`call-process' with `process-file' would make it possible to remove the
file-remote-p check.


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: get-free-disk-space when default-directory doesn't exist
  2009-09-01  6:05                   ` Stefan Monnier
@ 2009-09-07  0:28                     ` Kevin Ryde
  0 siblings, 0 replies; 26+ messages in thread
From: Kevin Ryde @ 2009-09-07  0:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 3911

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> Right now, it is.

Prospective remote support isn't a reason to leave it dodgy for locals
now is it?

> `process-file'

The cd in tramp-handle-process-file will have the same problem as the
local cd in call-process.  If there has to be a cd then it should be a
safe place like the root dir or similar.

Perhaps default-directory as the remote root dir would get close.  Is
there a func to figure that?  Except I think remote support should go
through the file-name-handler thingie to allow for remotes with their
own free-space query mechanism, rather than running "df" (or assuming
that `directory-free-space-program' for the local machine is also good
on the remote, etc).





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#3911: marked as done (get-free-disk-space race condition on default-directory test)
  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   ` Emacs bug Tracking System
  1 sibling, 0 replies; 26+ messages in thread
From: Emacs bug Tracking System @ 2009-10-02  0:35 UTC (permalink / raw)
  To: Kevin Ryde

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

Your message dated Fri, 02 Oct 2009 10:24:49 +1000
with message-id <87bpkq7icu.fsf@blah.blah>
and subject line Re: bug#3911: get-free-disk-space when default-directory doesn't exist
has caused the Emacs bug report #3911,
regarding get-free-disk-space race condition on default-directory test
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@emacsbugs.donarmstrong.com
immediately.)


-- 
3911: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=3911
Emacs Bug Tracking System
Contact owner@emacsbugs.donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 5863 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 1039 bytes --]

On a non-existent directory get-free-disk-space returns nil, eg.

    (get-free-disk-space "/no/such/dir")
    => nil

But if it's done by a relative path from a default-directory which
doesn't exist, then the answer is the space in your home directory

    (let ((default-directory "/no/such/dir"))
      (get-free-disk-space "."))
    => 3705637

I hoped the two answers would be the same.

This is with the "df"-running code in get-free-disk-space, ie. no
`file-system-info' function.

Perhaps absolutize per below with an inserted setq, the diff being just
re-indent.

(I still think the use of the home dir there is either complicated and
unnecessary, or complicated and necessary everywhere.  Or maybe better
call-process could not attempt a chdir at all if a caller doesn't care
about the current directory.  But leaving that unchanged as yet.)

2009-07-24  Kevin Ryde  <user42@zip.com.au>

	* files.el (get-free-disk-space): Absolutize the dir before
	changing default-directory, so as not to answer about a different
	directory.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: files.el.disk-space-absolutize.diff --]
[-- Type: text/x-diff, Size: 1795 bytes --]

*** files.el	24 Jul 2009 07:35:37 +1000	1.1063
--- files.el	24 Jul 2009 08:07:01 +1000	
***************
*** 5394,5410 ****
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
! 		     (let ((default-directory
! 			     (if (and (not (file-remote-p default-directory))
! 				      (file-directory-p default-directory)
! 				      (file-readable-p default-directory))
! 				 default-directory
! 			       (expand-file-name "~/"))))
! 		       (eq (call-process directory-free-space-program
! 					 nil t nil
! 					 directory-free-space-args
! 					 dir)
! 			   0)))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))
--- 5394,5413 ----
        (save-match-data
  	(with-temp-buffer
  	  (when (and directory-free-space-program
!                      (progn
!                        ;; absolutize before changing default-directory
!                        (setq dir (expand-file-name dir))
!                        (let ((default-directory
!                                (if (and (not (file-remote-p default-directory))
!                                         (file-directory-p default-directory)
!                                         (file-readable-p default-directory))
!                                    default-directory
!                                  (expand-file-name "~/"))))
!                          (eq (call-process directory-free-space-program
!                                            nil t nil
!                                            directory-free-space-args
!                                            dir)
!                              0))))
  	    ;; Usual format is a header line followed by a line of
  	    ;; numbers.
  	    (goto-char (point-min))

[-- Attachment #2.1.3: Type: text/plain, Size: 539 bytes --]






In GNU Emacs 23.1.50.4 (i586-pc-linux-gnu, GTK+ Version 2.16.4)
 of 2009-07-24 on blah.blah
configured using `configure  'CFLAGS=-O -g' '--prefix=/down/emacs/b/inst' '--with-x-toolkit=gtk''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_AU
  value of $XMODIFIERS: nil
  locale-coding-system: iso-latin-1-unix
  default-enable-multibyte-characters: t

[-- Attachment #3: Type: message/rfc822, Size: 2217 bytes --]

From: Kevin Ryde <user42@zip.com.au>
To: 3911-done@emacsbugs.donarmstrong.com
Subject: Re: bug#3911: get-free-disk-space when default-directory doesn't exist
Date: Fri, 02 Oct 2009 10:24:49 +1000
Message-ID: <87bpkq7icu.fsf@blah.blah>

Installed by Stefan.

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2009-10-02  0:35 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
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

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