CITS2002 Systems Programming  
 

Unit home

Project 1

help2002

Lecture & Workshop
recordings on LMS

Schedule

FAQ

Unit outline

C textbooks

OS textbooks

Information resources


Extra reading

Past projects

Recent feedback


Working effectively

Look after yourself!

Project 2 2012 - merge the contents of multiple directories

When members of a software development team work on the same project, they each need copies of the files forming the project. Often each team member will be assigned to work on a subset of the files and, eventually, the individual files will need to be merged together to form the updated project. If the software team have not used version control software, then they must use other tools to merge the project's individual files together. Unfortunately the standard Unix command-line tools do not provide all of the necessary features and, if not careful, the software team could lose some of their changes.

The GOAL of this project is to write an ISO-C99 program to merge the contents of one-or-more input directories, leaving the merged result in a single output directory. The developed software tool, named mergedirs, will accept command-line options to direct its execution, and additional command-line arguments representing directory names. Each invocation of mergedirs will require the name of at least one input directory providing items to be merged, and exactly one output directory naming the (possibly new) directory to receive the merged files. Thus, a synopsis of the program's usage, where items appearing within square-brackets are optional, could be:

    mergedirs [options] indirectory1 [indirectory2 ....] outdirectory

Two files are deemed "the same" if they have identical pathnames and identical filenames - but they will, of course, come from different "top level" input directories. Thus bob/project2/options.c and carol/project2/options.c are deemed "the same" file, but ted/project2-backup/compare.c and alice/project2/compare.c are not.

Note that each input directory, itself, may contain other subdirectories (and so on). Thus, mergedirs performs its comparisions and copying recursively, not just on "flat" directories. Each directory will contain only files and subdirectories - in particular, there will be no links nor symbolic links.


Program requirements

  1. Your project, and its executable program, must be named mergedirs.

  2. Your project must be developed using multiple source files, and must employ a Makefile to build the whole project.

  3. Your program must use getopt() to accept the following command-line options. All students should attempt to implement all options.

    -l
    if multiple input directories contain files of the same name, then the largest file should be copied to the output directory.

    -m
    if multiple input directories contain files of the same name, then the file with the most-recent modification-time should be copied to the output directory.

    -v
    be verbose, and report (to stdout) the full pathname of each file being copied to the output directory (otherwise, stay silent).

    -i pattern
    🌶 if a subdirectory's name contains the indicated pattern, then it should be ignored. For example, the command

        mergedirs -i bak eve fargo outdir
    

    would ignore (skip) everything in the directory eve/project2-bak/
    Only one -i option may be provided.

    -c
    🌶 if two or more files from multiple input directories have the same name, but have different contents, then this is termed a conflict - as we don't know which file to copy to the output directory. If the -c command-line option is presented, the conflicts should be reported (to stdout) but no files should be copied. Attempt this option last of all.

  4. Each file copied to the output directory must have the same modification-time as the corresponding file from its input directory.

  5. If an error is detected during its execution, your program should use fprintf(stderr, ....) or perror() (as appropriate) to print an error message, and then immediately call exit(EXIT_FAILURE).

  6. Your program must employ sound programming practices, including the use of meaningful comments, well chosen identifier names, appropriate choice of basic data-structures and data-types, and appropriate choice of control-flow constructs.


Good luck!

Chris McDonald.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Presented by [email protected]