[Toybox] [PATCH] fix human_readable output for du
enh
enh at google.com
Mon Aug 10 21:52:06 PDT 2015
On Sat, Aug 8, 2015 at 7:09 PM, Rob Landley <rob at landley.net> wrote:
> On 08/08/2015 12:40 PM, enh wrote:
>> ping.
>>
>> On Sat, Jan 17, 2015 at 6:18 PM, enh <enh at google.com> wrote:
>>> this was the du patch. the documentation of the BSD function is
>>> https://www.freebsd.org/cgi/man.cgi?query=humanize_number&sektion=3&n=1
>>> and even just between dd and du a fair number of those flags are used.
>
> Ouch.
>
>>> i didn't know whether you'd prefer i fix all the -h'es (and add the
>>> missing ones) or just worry about them one at a time. i guess i should
>>> have just gone ahead and looked at df and ls in the meantime :-)
>
> In the long run it looks like the right thing to do is implement the
> darn bsd-compatible human_readable() function in lib/portability.c (or
> at least the compatible subset of which we actually use), with a compile
> time probe to use the libc one if it's there, on the theory that we may
> eventually build under bsd, and bionic might want to implement this
> itself someday.
(it's not in libc even in BSD. there's a separate libutil.)
> Basically this is horrible but the _problem_ is probably what's
> horrible, not the solution. If we can someday push this into posix we
> can stop implementing our own. Given that the BSD version _exists_ and
> it isn't immediately obvious how to improve on it, not being compatible
> with it seems silly.
sgtm.
> That said, I'm applying this patch now because you have test cases and
> users who tell you when it's wrong, and I don't, so I defer to your
> expertise here.
>
> (For a definition of "apply" that involves a lot of failed hunk fixups.
> I really need to just spend a month on the test suite at some point.)
>
>
> Um, the new du -h and the ubuntu du -h produce very different output:
>
> $ diff -u <(du -h toys) <(./du -h toys)--- /dev/fd/63 2015-08-08
> 21:07:06.034754585 -0500
> +++ /dev/fd/62 2015-08-08 21:07:06.034754585 -0500
> @@ -1,7 +1,7 @@
> 16K toys/example
> 36K toys/android
> -988K toys/pending
> -420K toys/posix
> -420K toys/other
> -84K toys/lsb
> +1.0M toys/pending
> +430K toys/posix
> +430K toys/other
> +86K toys/lsb
> 2.0M toys
>
> Looks like one of those power of 2 vs power of 10 things?
yeah, testing with conveniently-sized files confirms what the man page
claims about -h being multiples of 1024. time to add the appropriate
flag...
> (All I checked for dd is that it compiled, because pending. I did half a
> cleanup of that once but lost it in a mercurial version upgrade that
> trashed my repo so I had to restore from a backup and copy stuff over by
> hand...)
yeah, dd and the grep family will be the last things to switch over.
in both cases "toolbox" is already the full current BSD
implementation. the only improvement to grep i can think of that might
be interesting would be the ability to use pcre, but i suspect that's
more likely to come to BSD grep than toybox :-)
> Rob
--
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
1439268726.0
More information about the Toybox
mailing list