NOTE: This assignment, like the other projects in this class, is due at the beginning of the class period. This means that if you are even a minute late, you lose 20%. If you are worried about potentially being late, turn in your homework ahead of time. Do this by submitting them electronically then giving the hard copy to me or the TA during office hours or by sliding it under my office door within twenty-four hours after the time it is due. Do not send assignments to me through email or leave them in my departmental mail box.
Have you ever wished that you had the latest versions of your files available and hated having to search around for which ones were newer? Have you ever needed to "synchronize" the data on your palmtop with that on your laptop, or the data on your laptop with that on your desktop machine?
For this assignment, you will create a file and directory synchronization utility. It won't work between different machines using different file systems, because we haven't covered how to do interprocess communication between machines using different file systems yet, but it will work between different directories on the same file system. Further, you will expand your program to make it possible for different users, working together in a team, to synchronize their files and directories.
For this assignment, you will create two file system synchronization
utility programs. The first will be called fssync
for "file
system synchronization." It will be used to synchronize files and
directories belonging to a single user. The second will be called
teamsync
. It will be used to synchronize files and
directories belonging to a different users who are members of the same
team.
fssync
The fssync
utility will work as follows:
If fssync
is run with command line arguments consisting of
two files with the same name but in different directories, then
fssync
will determine which of the files is older (based on the
time of last modification of the file's data) and replace it with the newer
version. So, for example, if the user typed
% fssync /home/name4567/dir1/file1 /home/name4567/dir2/file1and the copy of
file1
in dir1
was older than the
copy of file1
in dir2
, then fssync
should replace the copy of file1
in dir1
with the
copy of file1
in dir2
.
After replacing the older file with the newer file, fssync
should change the time of last modification of the replaced file to match
that of the file with which is was replaced. So, to continue the example
above, the copy of file1
in dir1
would (after being
replaced by the copy of file1
in dir2
), have its
time of last modification changed to match the time of last modification of
the copy of file1
in dir2
.
After replacing one file with the other, fssync
should print
the message "<path1><filename> replaced by
<path2><filename>: <modtime>" (where <path1> is the
directory path of the replaced file, <path2> is the directory path of
the replacing file, <filename> is the file name in question, and
<modtime> is the time of the last modification of the newer version of
the file.)
If both files are the same age, then fssync
should print the
message "<path1><filename>: <path2><filename>: same
age" (where <path1>, <path2><, <filename>, and
<modtime>, are the directories, file name, and modification time
involved.)
After printing the appropriate message, fssync
should
exit.
If fssync
is run with command line arguments consisting of
two directories, then fssync
will synchronize all of the files
in these two directories. This means that, for each file in each directory:
If a file with the same name is found in the other directory,
fssync
will determine which of the files is older and replace it
with the newer version, change the time of last modification of the replaced
file to match that of the file with which is was replaced (as above), then
print the message "<path1><filename> replaced by
<path2><filename>: <modtime>" (as above). If both files
are the same age, then fssync
should print the message
"<path1><filename>: <path2><filename>: same age"
(as above).
If no file with the same name is found in the other directory,
fssync
will copy the file to the other directory, change the
time of last modification of the new file to match that of the original, then
print the message "<filename> added to <path>: <modtime>"
(where <filename> is the name of the file added to the other directory,
<path> is the other directory path, and <modtime> is the time of
the last modification of the original version of the file).
teamsync
The teamsync
utility will work like the fssync
utility, with one important difference. Whereas fssync
will
only work for files and directories that its user can access (read, write, or
execute as necessary), teamsync
will work for files that either
the user or the user's teammates can access. This will work as follows:
Each member of the team will have his or her own copy of
teamsync
. This copy of the program will be put where other team
members can access it to run it. This will be in a directory under the
user's home directory that will be named teamsyncdir
.
When it is run, teamsync
will check a file called
syncteam
, which will also be in teamsyncdir
. The
file syncteam
will consist of the user ID's of all team members,
one per line, and nothing else.
If the user running teamsync
is not listed (by
user ID) in syncteam
, then teamsync
will print the
message "Not authorized" and then exit.
If the user running teamsync
is listed (by
user ID) in syncteam
, then teamsync
will run as
described above for fssync
but will additionally check who owns
each directory and file in question.
If the owner of the directory to be copied from and the file
to be copied is the owner of the teamsync
executable being run,
and the owner of the directory to be copied to and the file to be written is
the current user of teamsync
, then teamsync
will
copy the file, making sure that the owner of the new file is the same as the
user running teamsync
.
If the owner of the directory to be copied from is not
the owner of the teamsync
executable being run, then
teamsync
will print the message "<dir> will not be copied
from: directory owned by <UID>" (where <dir> is the directory in
question and <UID> is the User ID of the directory owner).
If the owner of the file to be copied is not
the owner of the teamsync
executable being run, then
teamsync
will print the message "<pathname> will not be
copied: file owned by <UID>" (where <pathname> is the path name
of the file and <UID> is the User ID of the file).
If
the owner of the directory to be copied to is not
the user currently running teamsync
, then teamsync
will print the message "<dir> will not be copied to: directory
owned by <UID>" (where <dir> is the directory in
question and <UID> is the User ID of the directory owner).
If the owner of the file to be written is not
the user currently running teamsync
, then teamsync
will print the message "<pathname> will not be copied to: file owned by
<UID>" (where <pathname> is the path name of the file and
<UID> is the User ID of the file).
The teamsync
utility will only allow files to be
copied from teamsyncdir
or directories below
teamsyncdir
.
flags
Both fssync
and teamsync
will take the following
flags from the command line and interpret them as follows.
fssync
and teamsync
will prompt the user with the
message "<pathname> exists, overwrite? (y/n/x)" (where <pathname>
is the path name of the file to be overwritten). If the user answers "y" (or
"Y"), then the file will be overwritten and the program will proceed as
normal. If the user answers "n" (or "N"), then the file will not be
overwritten and the program will proceed as normal. If the user answers "x"
(or "X"), then the file will not be overwritten and the program will
exit.fssync
and teamsync
will prompt the user
as above for the -c flag for overwriting or with the message "Create
<pathname>? (y/n/x)" for creating a new file (where <pathname>
is the name that the file will be copied to). If the user answers "y"
(or "Y"), then the file will be copied and the program will proceed as
normal. If the user answers "n" (or "N"), then the file will not be copied
and the program will proceed as normal. If the user answers "x" (or "X"),
then the file will not be copied and the program will exit.% fssync -r -q -c -i /home/name4567/dir1 /home/name4567/dir2which would quitely, recursively, and interactively invoke
fssync
. (Note that specifying both -c and -i is redundant, as
-i encompasses all of the behavior of -c and then some.)
All copying of files in this assignment will use the POSIX system calls
open
, close
, read
, write
.
You will not be using the link
system call in this
assignment.
All messages printed by fssync
and teamsync
will
be printed to the standard out.
Both fssync
and teamsync
will ignore (neither
copy nor follow) symbolic links.
If fssync
or teamsync
are improperly invoked
(with too few command line arguments, one directory and one file, unknown
flags, etc.), the program should print an error message and exit.
You will turn in both a hard copy and an electronic copy of your assignment. You will be given instructions on how to send electronic copies. Do not send them to me though email.
Both the hard copy and the electronic copy will contain a write-up and all
source code for both fssync
and teamsync
. The
electronic copy will also contain the executable of both fssync
and teamsync
. The electronic copy of your write-up should not
be in a proprietary format (such as MS Word); it should be either in plain
ASCII text or in a portable format (such as Postscript or PDF). Your source
code should either be in a single file for each program, called
fssync.c
and teamsync.c
, respectively, or in
several files that can be compiled and linked using make
. In
the latter case, fssync.c
and teamsync.c
(or
fssync.cxx
and teamsync.cxx
) will contain the
function main()
and you will include your makefile and it will
be named makefile
. The executables generated by your makefile
should be called fssync
and teamsync
.
Your source code should be well structured and well commented. It should conform to good coding standards (e.g., no memory leaks).
Your write-up will contain 1/2 to 1 page (roughly 80 characters per line, 50 lines per page) explaining the data structures and algorithms used in your code. This page limitation does not include figures used in your explanation, which are encouraged and may take up any amount of space. (This explanation does not remove the requirement that your code be well commented.)
Your write-up will also contain a "man page" entry for fssync
and teamsync
. This will not be a real manual page entry that
can be displayed using the "man" command but will be a text file that roughly
follows the format of a man page and describes these utilities.
You may write your program from scratch or may start from programs for which the source code is freely available on the web or through other sources (such as friends or student organizations). If you do not start from scratch, you must give a complete and accurate accounting of where all of your code came from and indicate which parts are original, which are changed, and which you got from which other source. Failure to give credit where credit is due is academic fraud and will be dealt with accordingly.
As noted in the syllabus, you are required to work on this programming assignment in a group of at least two people. It is your responsibility to find other group members and work with them. The group should turn in only one (1) hard copy and one (1) electronic copy of the assignment. Both the electronic and hard copies should contain the names and student ID numbers of all group members. If your group composition changes during the course of working on this assignment (for example, a group of five splits into a group of two and a separate group of three), this must be clearly indicated in your write-up, including the names and student ID numbers of everyone involved.