1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-08 07:20:28 -08:00

* files.el (get-free-disk-space): Search more robustly for "available" column.

Suggested by Ehud Karni <ehud@unix.mvs.co.il>:
http://lists.gnu.org/archive/html/emacs-devel/2010-09/msg00163.html
This commit is contained in:
Chong Yidong 2010-09-05 15:03:20 -04:00
parent 3cf628e8ec
commit 93a596e11b
2 changed files with 28 additions and 17 deletions

View file

@ -1,3 +1,9 @@
2010-09-05 Chong Yidong <cyd@stupidchicken.com>
* files.el (get-free-disk-space): Search more robustly for
"available" column. Suggested by Ehud Karni
<ehud@unix.mvs.co.il>.
2010-09-05 Juanma Barranquero <lekktu@gmail.com> 2010-09-05 Juanma Barranquero <lekktu@gmail.com>
* international/uni-bidi.el: * international/uni-bidi.el:

View file

@ -5563,12 +5563,14 @@ preference to the program given by this variable."
(defun get-free-disk-space (dir) (defun get-free-disk-space (dir)
"Return the amount of free space on directory DIR's file system. "Return the amount of free space on directory DIR's file system.
The result is a string that gives the number of free 1KB blocks, The return value is a string describing the amount of free
or nil if the system call or the program which retrieve the information space (normally, the number of free 1KB blocks).
fail. It returns also nil when DIR is a remote directory.
This function calls `file-system-info' if it is available, or invokes the This function calls `file-system-info' if it is available, or
program specified by `directory-free-space-program' if that is non-nil." invokes the program specified by `directory-free-space-program'
and `directory-free-space-args'. If the system call or program
is unsuccessful, or if DIR is a remote directory, this function
returns nil."
(unless (file-remote-p dir) (unless (file-remote-p dir)
;; Try to find the number of free blocks. Non-Posix systems don't ;; Try to find the number of free blocks. Non-Posix systems don't
;; always have df, but might have an equivalent system call. ;; always have df, but might have an equivalent system call.
@ -5588,19 +5590,22 @@ program specified by `directory-free-space-program' if that is non-nil."
directory-free-space-args directory-free-space-args
dir) dir)
0))) 0)))
;; Usual format is a header line followed by a line of ;; Usual format is as follows:
;; numbers. ;; Filesystem ... Used Available Capacity ...
;; /dev/sda6 ...48106535 35481255 10669850 ...
(goto-char (point-min)) (goto-char (point-min))
(when (re-search-forward " +Avail[^ \n]*"
(line-end-position) t)
(let ((beg (match-beginning 0))
(end (match-end 0))
str)
(forward-line 1) (forward-line 1)
(if (not (eobp)) (setq str
(progn (buffer-substring-no-properties
;; Move to the end of the "available blocks" number. (+ beg (point) (- (point-min)))
(skip-chars-forward "^ \t") (+ end (point) (- (point-min)))))
(forward-word 3) (when (string-match "\\` *\\([^ ]+\\)" str)
;; Copy it into AVAILABLE. (match-string 1 str))))))))))
(let ((end (point)))
(forward-word -1)
(buffer-substring (point) end))))))))))
;; The following expression replaces `dired-move-to-filename-regexp'. ;; The following expression replaces `dired-move-to-filename-regexp'.
(defvar directory-listing-before-filename-regexp (defvar directory-listing-before-filename-regexp