Create 'du' command
Project: | JNode Shell |
Component: | Code |
Category: | feature request |
Priority: | normal |
Assigned: | mzsilak |
Status: | patch (code needs review) |
Description
Create the 'du' command for computing the size of directories with the most common options found in the du command of unix/linux distributions.
- Login to post comments
#1
Here is a patch for this...
#2
I guess you didn't know the methods org.jnode.util.NumberUtils#toBinaryByte(....) methods.
Please use them instead of the inner class FileSizePrinter in your patch.
#3
Also, can we hold on committing this. I've just about got all the fs-commands pulled into a separate project.
#4
Here is a patch using NumerUtils to convert file sizes to human readable.
Option to use powers of 1000 instead of 1024 was removed, because NumberUtils does not support it.
#5
That is strange...
I accidentally had this main() in the DuCommand:
It did run as expected but I changed it to
#6
Here's an explanation:
The JNode "thread", "proclet" and "isolate" invokers will normally call a command's "int execute()" method directly. They will only use the "public static void main(String[])" entry point if the command class does not extend AbstractCommand.
But you were right to correct this since the "default" invoker does use the "main" entry point exclusively, and the same would happen if you tried to run your command on classic Java.
#7
I haven't tested this yet, but just looking at the patch it looks good.
As per the refactoring of commands, i'll include this into org.jnode.command.file package. I'll take care of it though so no worries.
One thing i'd like to ask is the formatting of Argument instance variables. Because of the long lines these tend to occupy, i would prefer if the assignment portion be placed inside the constructor. I have done this across almost all of the commands in the current refactoring, and i think it makes the code a bit more readable.
#8
A couple of other things i'd like to point out.
In the xml syntax, dont include duplicate descriptions for options that map directly to arguments, as its the argument's description that is being used for help. It's fine to include descriptions for direct children of the syntax node, as it is used in the 'usage'.
Also, we should try to keep our flag usage as close to standard as possible. Just in reference to using -t/--total when the expected flags on other systems is -s/--summarize.
Nothing big, just some things i thought i would mention. I have taken care of these and have your patch in my tree at the moment, will be commited asap.
#9
OK, ill take a look at these things when it has been committed.
#10
patch has been committed
As i was testing it more, i found a bug. It was summing up sibling directory totals. In my setup i have 3 directories, test/{a,b,c} each with 2 1kb files. `du test` was telling me that test/a was 6kb, test/b was 4kb, and test/a was 2kb.
But this doesn't propogate to the parent directories, test itself was still 6kb
#11
bananenkasper: Option to use powers of 1000 instead of 1024 was removed, because NumberUtils does not support it.
It seems like you've not seen that NumberUtils support both. Use :
- NumberUtils.toBinaryByte(....) for powers of 1024
- NumberUtils.toDecimalByte(....) for powers of 1000
#15
I'll work on it these days...
#16
Attached a Patch for the DuCommand including updated descriptor.
#17
The code looks good and extends the functionality of 'du' significantly.
So I applied the patch.
I haven't tested it in great detail but I think some more testing and fixes would be good. For instance if I pass two directories like: du /jnode /jifs then I get a NullPointerException. Also the -m option might need more testing just as the combinations of various options.
If an option is not possible to implement in JNode or missing then that can appear in the command help as unsupported.
Lets keep this thread open for further work.
Thank you.
#18
I'll check the issues you mentioned.
A few options can't be implemented currently due to the lack of knowledge of jnode on my side, or due to the lack of needed methods in jnode.
I'll create feature/task requests as needed.
#19
I've fixed the NPE and also additionally an issue with -a. I also added a comment in the help for the arguments which are not implemented or not tested properly.
I created a new request for the block size issue (there is currently a warning about it in the DuCommand). http://www.jnode.org/node/3252
The DuCommand depends on that issue and should stay open until the issue got solved and implemented.
#20
The NPE and is fixed now.
I committed it.
Thank you.