bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#6995: 24.0.50; get-free-disk-space doesn't return available space in


From: Thierry Volpiatto
Subject: bug#6995: 24.0.50; get-free-disk-space doesn't return available space in dired
Date: Wed, 15 Sep 2010 20:39:39 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> Stefan Monnier <address@hidden> writes:
>
>>> How about dropping the use of `df', at least on GNU/Linux?  It's IMO
>>> ridiculous to invoke an external program for a single system call.  I
>>> know that this system call is notoriously non-portable, and that doing
>>> in Emacs all that system-dependent stuff that `df' does is not a good
>>> idea.  But at least on the most popular free system (and perhaps on a
>>> few compatible ones) we could do it right without all that labor, and
>>> gain stability and reliability that depending on `df' will never
>>> achieve.
>>
>> That would make a lot of sense, yes,
>
> I agree too, but waiting such a change, you should rewrite
> `get-free-disk-space' as it can't work correctly on the output of df.
>
> ,----
> |         ;; Usual format is as follows:
> |         ;; Filesystem ...    Used  Available  Capacity ...
> |         ;; /dev/sda6  ...48106535   35481255  10669850 ...
> |         (goto-char (point-min))
> |         (when (re-search-forward " +Avail[^ \n]*"
> `----
>
> But usual format is not the same on all locales:
> Here it is:
>
> ,----
> | Sys. de fichiers    1024-blocs   Utilisé    Dispo. Capacité Monté sur
> | /dev/sda7             48947688  21618816  24842416      47% /home
> `----
>
> So (re-search-forward " +Avail[^ \n]*" is not portable here.
>
> I use this simplified version of get-free-disk-space if it can help:
>
> ,----
> | (defun get-free-disk-space (dir)
> |   (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)))))
> |     (nth 2 values)))
> `----

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


> Tough the version on 23.2 work also.
>
> Note that the value of "total used in directory" is always wrong.
> How do you get this value?

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]