all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: bug-gnu-emacs@gnu.org
Subject: bug#6995: 24.0.50; get-free-disk-space doesn't return available space in dired
Date: Sat, 18 Sep 2010 15:54:45 +0200	[thread overview]
Message-ID: <87r5grxil6.fsf@tux.homenetwork> (raw)
In-Reply-To: <87d3sp5olh.fsf@tux.homenetwork>

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> With the windows stuff and no call when remote:
>
> (defun get-free-disk-space (dir)
>   (unless (file-remote-p dir)
>     ;; Try to find the number of free blocks.  Non-Posix systems don't
>     ;; always have df, but might have an equivalent system call.
>     (if (fboundp 'file-system-info)
> 	(let ((fsinfo (file-system-info dir)))
> 	  (if fsinfo
> 	      (format "%.0f" (/ (nth 2 fsinfo) 1024))))
>         (when (executable-find directory-free-space-program)
>           (let* ((data   (with-temp-buffer
>                            (call-process directory-free-space-program
>                                          nil t nil
>                                          directory-free-space-args
>                                          dir)
>                            (split-string (buffer-string) "\n" t)))
>                  (values (cdr (split-string (second data)))))
>             (when data (nth 2 values)))))))
>

But may be it's better to have other infos from output of df available:

(defun get-free-disk-space (dir &optional human)
  (unless (file-remote-p dir)
    ;; That is for windows.
    (if (fboundp 'file-system-info)
	(let ((fsinfo (file-system-info dir)))
	  (if fsinfo
	      (format "%.0f" (/ (nth 2 fsinfo) 1024))))
        ;; And this is for Unix/GNULinux.
        (when (executable-find directory-free-space-program)
          (getf (tv-get-disk-info dir human) :available)))))

(defun tv-get-disk-info (dir &optional human)
  (let* (args    (if human
                     (concat directory-free-space-args "h")
                     directory-free-space-args)
         (data   (with-temp-buffer
                   (call-process directory-free-space-program
                                 nil t nil args dir)
                   (split-string (buffer-string) "\n" t)))
         (values (split-string (second data))))
    (loop for i in '(:device :blocks :used :available :capacity :mount-point)
       for j in values
       append (list i j))))

-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 






  reply	other threads:[~2010-09-18 13:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-07 19:40 bug#6995: 24.0.50; get-free-disk-space doesn't return available space in dired Thierry Volpiatto
2010-09-07 20:36 ` Glenn Morris
2010-09-13  6:56   ` Eli Zaretskii
2010-09-13 10:14     ` Stefan Monnier
2010-09-13 13:22       ` Thierry Volpiatto
2010-09-15 18:39         ` Thierry Volpiatto
2010-09-18 13:54           ` Thierry Volpiatto [this message]
2010-09-25 20:17   ` Chong Yidong
2010-09-27  8:37     ` Thierry Volpiatto

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

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

  git send-email \
    --in-reply-to=87r5grxil6.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=bug-gnu-emacs@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.