google-code-export / tovid

Automatically exported from code.google.com/p/tovid
1 stars 0 forks source link

df(1) invocation non-portable #152

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
To estimate the amount of space left in the working directory, tovid invokes 
``df -mP''. The -m is meant to request output in megabytes and the -P -- to get 
it in POSIX format.

This invocation is not very portable: for example, df(1M) on Solaris-10 does 
not have the -m flag at all, and only /usr/xpg4/bin/df (but not the 
/usr/bin/df) accept the -P.

On FreeBSD (and, likely, other BSD-systems), -P forces output to be in 512-byte 
blocks, although specifying -m after -P fixes that.

A simple fix would be to call df -Pm instead of -mP -- this would work on Linux 
and BSD, but still leave Solaris in the cold. A more complex fix would be to 
ensure, /usr/xpg4/bin is in the PATH ahead of /usr/bin and then use only the -P 
switch and perform the necessary computations in awk:

AVAIL_SPACE=$(df -P . | awk 'NR==1 {sub("-blocks", "", $2); blocksize=$2} NR!=1 
{print int($4/1024*blocksize/1024)}')

Original issue reported on code.google.com by virtuale...@gmail.com on 18 Nov 2011 at 5:58

GoogleCodeExporter commented 9 years ago
Here is the patch with the latter implementation.

Original comment by virtuale...@gmail.com on 18 Nov 2011 at 10:00

Attachments:

GoogleCodeExporter commented 9 years ago
The portable df line was changed in tovid svn r-3422 and will be part of tovid 
0.35.
Thanks for the input.

Original comment by grepper@gmail.com on 24 Jul 2012 at 1:28