aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2001-12-21 15:20:42 +0000
committerEli Zaretskii2001-12-21 15:20:42 +0000
commit01b26b907083382000c3d0b9dd30f75d48e2e16b (patch)
tree9ef707a2c80f5f96b11426249ee7d6ec5d44a3d1
parentd743da264342d075295a477c9e49dd185ee654a4 (diff)
downloademacs-01b26b907083382000c3d0b9dd30f75d48e2e16b.tar.gz
emacs-01b26b907083382000c3d0b9dd30f75d48e2e16b.zip
(directory-free-space-program): Mention
file-system-info in the doc string. (get-free-disk-space): New function; code moved from insert-directory. (insert-directory): Call get-free-disk-space to get the amount of free space.
-rw-r--r--lisp/files.el79
1 files changed, 46 insertions, 33 deletions
diff --git a/lisp/files.el b/lisp/files.el
index 8c89bc8595c..7e0f24268e7 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3561,7 +3561,10 @@ We assume the output has the format of `df'.
3561The value of this variable must be just a command name or file name; 3561The value of this variable must be just a command name or file name;
3562if you want to specify options, use `directory-free-space-args'. 3562if you want to specify options, use `directory-free-space-args'.
3563 3563
3564A value of nil disables this feature." 3564A value of nil disables this feature.
3565
3566If the function `file-system-info' is defined, it is always used in
3567preference to the program given by this variable."
3565 :type '(choice (string :tag "Program") (const :tag "None" nil)) 3568 :type '(choice (string :tag "Program") (const :tag "None" nil))
3566 :group 'dired) 3569 :group 'dired)
3567 3570
@@ -3570,6 +3573,42 @@ A value of nil disables this feature."
3570 :type 'string 3573 :type 'string
3571 :group 'dired) 3574 :group 'dired)
3572 3575
3576(defun get-free-disk-space (dir)
3577 "Return the mount of free space on directory DIR's file system.
3578The result is a string that gives the number of free 1KB blocks,
3579or nil if the system call or the program which retrieve the infornmation
3580fail.
3581
3582This function calls `file-system-info' if it is available, or invokes the
3583program specified by `directory-free-space-program' if that is non-nil."
3584 ;; Try to find the number of free blocks. Non-Posix systems don't
3585 ;; always have df, but might have an equivalent system call.
3586 (if (fboundp 'file-system-info)
3587 (let ((fsinfo (file-system-info dir)))
3588 (if fsinfo
3589 (format "%.0f" (/ (nth 2 fsinfo) 1024))))
3590 (save-match-data
3591 (with-temp-buffer
3592 (when (and directory-free-space-program
3593 (zerop (call-process directory-free-space-program
3594 nil t nil
3595 directory-free-space-args
3596 dir)))
3597 ;; Usual format is a header line followed by a line of
3598 ;; numbers.
3599 (goto-char (point-min))
3600 (forward-line 1)
3601 (if (not (eobp))
3602 (progn
3603 ;; Move to the end of the "available blocks" number.
3604 (skip-chars-forward "^ \t")
3605 (forward-word 3)
3606 ;; Copy it into AVAILABLE.
3607 (let ((end (point)))
3608 (forward-word -1)
3609 (buffer-substring (point) end)))))))))
3610
3611
3573;; insert-directory 3612;; insert-directory
3574;; - must insert _exactly_one_line_ describing FILE if WILDCARD and 3613;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
3575;; FULL-DIRECTORY-P is nil. 3614;; FULL-DIRECTORY-P is nil.
@@ -3689,38 +3728,12 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
3689 (goto-char (point-min)) 3728 (goto-char (point-min))
3690 ;; First find the line to put it on. 3729 ;; First find the line to put it on.
3691 (when (re-search-forward "^total" nil t) 3730 (when (re-search-forward "^total" nil t)
3692 ;; Try to find the number of free blocks. 3731 (let ((available (get-free-disk-space ".")))
3693 ;; Non-Posix systems don't always have df, 3732 (when available
3694 ;; but might have an equivalent system call. 3733 ;; Replace "total" with "used", to avoid confusion.
3695 (if (fboundp 'file-system-info) 3734 (replace-match "used")
3696 (let ((fsinfo (file-system-info "."))) 3735 (end-of-line)
3697 (if fsinfo 3736 (insert " available " available))))))))))
3698 (setq available (format "%.0f" (/ (nth 2 fsinfo) 1024)))))
3699 (save-match-data
3700 (with-temp-buffer
3701 (when (and directory-free-space-program
3702 (zerop (call-process directory-free-space-program
3703 nil t nil
3704 directory-free-space-args
3705 ".")))
3706 ;; Usual format is a header line
3707 ;; followed by a line of numbers.
3708 (goto-char (point-min))
3709 (forward-line 1)
3710 (if (not (eobp))
3711 (progn
3712 ;; Move to the end of the "available blocks" number.
3713 (skip-chars-forward "^ \t")
3714 (forward-word 3)
3715 ;; Copy it into AVAILABLE.
3716 (let ((end (point)))
3717 (forward-word -1)
3718 (setq available (buffer-substring (point) end)))))))))
3719 (when available
3720 ;; Replace "total" with "used", to avoid confusion.
3721 (replace-match "used")
3722 (end-of-line)
3723 (insert " available " available)))))))))
3724 3737
3725(defun insert-directory-safely (file switches 3738(defun insert-directory-safely (file switches
3726 &optional wildcard full-directory-p) 3739 &optional wildcard full-directory-p)