GNU bug report logs -
#3911
get-free-disk-space race condition on default-directory test
Previous Next
Reported by: Kevin Ryde <user42 <at> zip.com.au>
Date: Thu, 23 Jul 2009 22:25:05 UTC
Severity: normal
Tags: patch
Merged with 2631
Done: Kevin Ryde <user42 <at> zip.com.au>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
This is an automatic notification regarding your bug report
which was filed against the emacs package:
#3911: 23.1.50; get-free-disk-space relative to non-existent default-directory
It has been closed by Chong Yidong <cyd <at> stupidchicken.com>.
Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Chong Yidong <cyd <at> stupidchicken.com> by
replying to this email.
--
3911: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3911
Emacs Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
> 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.
[Message part 3 (message/rfc822, inline)]
[Message part 4 (text/plain, inline)]
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 <at> 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.
[files.el.disk-space-absolutize.diff (text/x-diff, inline)]
*** 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))
[Message part 6 (text/plain, inline)]
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
This bug report was last modified 14 years and 83 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.