Q. can you explain the -r
flag a little better. i'm still a
little confused over it. please use some examples.
A. I can understand why you are confused, as there as two ways that you
could interpret this. I'll explain both, then tell you which is right.
First, however, let me explain what will happen if the -r
flag
is not specified.
Consider the following graphs:
Figure 1. | Figure 2. |
Figure 1 shows the subtree with /home/name4567/dir1
as its
root and Figure 2 shows the subtree with /home/name4567/dir2
as
its root. In these figures, the files all begin with the letter
"f
" and the directories with the letter "d
". The
blue color for f1
in /home/name4567/dir2/d1
indicates that it is newer than the copy of f1
in
/home/name4567/dir1/d1
.
When the user types:
% fssync /home/name4567/dir1 /home/name4567/dir2(without the
-r
flag) your program should synchronize the
ordinary files in /home/name4567/dir1
and
/home/name4567/dir2
. It should have no effect on subdirectories
or on files within those subdirectories. Therefore, the results of this will
be as shown in Figures 3 and 4, where the gold
color indicates a newly created file.
Figure 3. | Figure 4. |
As you can see, without the -r
flag given,
fssync
will not effect the directory structure nor descend into
it -- it will only synchronize ordinary files at the top level of each
subtree.
With that out of the way, let us consider what will happen if the
-r
flag is given.
The first possible interpretation is that your program shouldn't change the directory structure of either sub-tree but should synchronize the files within the existing and matching branches of each sub-tree. Under this interpretation, starting with the subtrees shown in Figures 1 and 2, if the user types:
% fssync -r /home/name4567/dir1 /home/name4567/dir2(with the
-r
flag), the resulting subtrees would be as
shown in Figures 5 and 6, where the red color
indicates the additional files copied with the recursion due to the
-r
flag and the blue color for
f1
in
/home/name4567/dir1/d1
indicates that it has been updated to be
synchronized with the copy of f1
in
/home/name4567/dir2/d1
.
Figure 5. | Figure 6. |
The second interpretation is that you should duplicate missing structure in the two subtrees, as well as synchronizing the ordinary files. Under this interpretation, starting with the subtrees shown in Figures 1 and 2, if the user types:
% fssync -r /home/name4567/dir1 /home/name4567/dir2(with the
-r
flag), the resulting subtrees would be as
shown in Figures 7 and 8, where the green color
indicates the additional changes resulting from the duplication of directory
structure (and copying of files within those directories) due to the
-r
flag.
Figure 7. | Figure 8. |
The correct interpretation is the second one -- your program should
duplicate missing structure in the two subtrees, as well as synchronizing the
ordinary files, when invoked with the -r
flag.
Because this was unclear in the original assignment, I will give you an extension on the due date of the project until Monday, November 12 at 6:00 pm, to complete this assignment. However, I will give bonus points to teams that complete the assignment on time. Please see the message of the day for details.
Q. from the project description, i think forking and then execing a
cp
call to copy a file is the easiest way to copy. do you see
anything wrong with that. that would work...right?
A. This will work fine for fssync
. However, you will have
problems with this approach when it comes to teamsync
as this
program will need to read using one UID and write using another UID,
something which cp
cannot do.
Q. What about cases you haven't covered in the assignment?
A. During office hours, I have had several students ask questions along these lines. For example, what if a user types:
% fssync /home/name4567/dir1/file1 /home/name4567/dir2/file2(Note that the file names are different.)
You could consider this to be improperly invoking the program in which case "the program should print an error message and exit" (as the assignment says). However, if instead, you regarded this as undefined in the assignment, you could handle it as you see fit, as long as your program does something reasonable. Reasonable things to do would include:
Q. In the file syncteam
we have to list the username of the
team members. Is this my 4X4 like user1395 or is this this the UID of
uid_t
type.
A. This is a UID of uid_t
type. (Acutally, since the
reading functions do not undertand this type, you'll read it as a sequence of
bytes and cast it to uid_t
.)