Description
The primary learning objectives of this assignment include learning to perform commandline processing of arguments and creating and linking libraries. Additional learning objectives include the correct use of iterators and container classes. Utility Description diskusage reports, in various formats, the amount of disk space used in a directory tree. It traverses all files and computes total file sizes, providing different levels of detail (depending on command line arguments) in its report. The command-line format of invoking diskusage is as follows: ./diskusage -depth=(all|) (-b|-k|-m) – resource0 [resource1 […]] Where “resource” is used to mean a file, directory or symbolic link. At least one resource, resource0, must be provided to the utility and further resources are optional. Whenever an invalid or an otherwise undefined situation arises the program must exit with the “help” description of the utility. Options for diskusage All functionality used to parse the command-line options must be built to form a library. You will use at least one header file to declare non-static definitions that appear in your library but the executable must link to the library and not the *.o object file where argument parsing defintions appear. You can verify this is the case with the arguments to g++ during compilation and linking. You may use libs2.tar.gz under Resources in Scholar to parse arguments. You may also extend the functionality provided in that library. Depth Argument: -depth=all Perform no filtering based on depth. -depth= Show no resources more than levels deep. This argument may not be negative, must be an integer and may be multiple digits long. Note that “-depth=0” shows no more than the resource arguments provided to diskusage, “-depth=1” shows no more than 1 level deeper than “-depth=0” and so on. Unit Argument: -b Sizes are shown in bytes with a “B” suffix. -k Sizes are shown rounded up to the nearest kilobyte with a “kB” suffix. -m Sizes are shown rounded up to the nearest megabyte with a “MB” suffix. Note that these flags do not affect how the sizes are calculated. They affect only how the sizes as they are displayed. This is referred to as the rounded size. Type Argument: 3
f Allow files to be shown. Does not affect symlinks. d Allow directories to be shown. Does not affect symlinks. s Allow symbolic links to be shown. Regardless of what the symlink points to. A valid type argument is “-fds” with up to 2 of the character flags absent. That is, the type argument may be “-fds”, “-fd”, “-fs”, “-f”, “-ds”, “-d” and “-s” but not “-“ or any other string. If “f” is absent no files may be shown, if “d” is absent no directories may be shown and if “s” is absent no symbolic links may be shown. Behavior Visit and Print Order: Given a list of resources you should visit resources at the same level in lexical order and, for directories, visit their children in pre-order (i.e. A/ and B/ should always print A/, A/’s children, B/, then B/’s children regardless of the way they’re specified on the command line because A comes before B in lexical order). Symbolic links should not have their children traversed. The output should be printed in this order as well. Filtering: Both the depth and type arguments may restrict which resources are printed. When checking which resources should be printed it must pass at least one of the choices for type (i.e. file OR directory OR symlink for “-fds”) AND must pass the depth test. Size Calculation: A file’s total size and direct size are the size of its contents in bytes. A symlink’s total size and direct size are the size of its targets direct size. A directory’s total size is its direct size plus the total size of its contained items and its direct size is reported by QFileInfo::size. Note that these sizes are not affected by the unit argument. Printing: The order in which resources are printed is specified in “Visit and Print Order” when the program determines a resource should be printed it should print the rounded size in the left-hand column and the path to the resource in the right-hand column. Notes Don’t forget that even empty folders have a size that needs to be taken into consideration when calculating the total. This likely varies with your operating system/disk format. Check that subdirectories in the traversal each have their own totals properly calculated. Compare your results to the *nix command du. Citation This homework is based on Section 8.2.3 Exercise 1 from Design Patterns in C++ with Qt 4, 1st Edition.

