Using Drop to Transfer Files
The drop
command that I created is a general-purpose tool that
transfers one file at a time to a destination. It transfers ownership
of the file to the recipient, so that they can do with it whatever
they want.
Think of this as like a physical drop box or like sliding an assignment under someone's door.
We can do this both from student teams to the CS 304 course account and from student to student.
In this explanation, I'm going to imagine that Hermione and Ron have worked together on an assignment using Hermione's account. Afterwards, they want to transfer the finished tarfile to Ron's account.
So, Hermione is the sender and Ron is the recipient.
Create a Drop Folder¶
To allow someone to drop a file to you, you have to create a drop folder in your home directory. This gives you a known place to look for files, and means that the sender can't drop them just anywhere in your account. So, do this first:
mkdir ~/drop
Ron needs to do this so that Hermione can drop a file to him.
Setting up a drop folder only needs to be done once, no matter how many files get dropped later.
Feel free to do an ls
on the drop folder for the course account:
~cs304/drop
Drop the File¶
Then, Hermione can drop a file to Ron. Here's the command in action
(here cs304guest
is dropping a file to gdome
):
[cs304guest@tempest ~]$ drop gdome unix.tar
Copying unix.tar (from cs304guest) to /students/gdome/drop/ (uid 707)
/students/gdome/drop/cs304guest doesn't exist, making it.
Successful drop.
Structure and Permissions¶
If Hermione (cs304guest) is anxious and wants to be sure that the file is really there in Ron's (gdome's) drop folder, she can list the files that she has dropped:
[cs304guest@tempest ~]$ ls -l ~gdome/drop/cs304guest/
total 20
-r--r-----. 1 gdome cs304guest 20480 Sep 5 12:34 unix.tar
Ron (gdome) can also check that it's there:
[gdome@tempest ~]$ ls -l ~/drop/cs304guest/
total 20
-r--r-----. 1 gdome cs304guest 20480 Sep 5 12:34 unix.tar
You'll note in this example that there's a cs304guest
(hermione)
subfolder to Ron's (gdome's) drop folder. Think of that as "these
are my files from Hermione". Each sender gets a subfolder with their
account name. The drop
command does this automatically.
This scheme allows all of the CS 304 students to drop a file called
unix.tar
to the course account and not step on each other. It also
means that, next time, when Ron is working with Harry on a different
assignment, Harry can drop the work to Ron and it'll go in the
hpotter
subfolder of Ron's drop folder.
Again, the subfolders are named for the sender.
You'll also notice, above, that the unix.tar
file in Ron's drop
folder is owned by gdome (Ron), not by Hermione. The drop
command
has transferred ownership.
One consequence of this is that Hermione can't delete the file after she has dropped it. If she needs to drop it again, either Ron has to delete the earlier one (since he's the owner) or Hermione needs to rename the file and drop that:
mv unix.tar unix-revised.tar
drop rweasely unix-revised.tar
That's it!
Summary¶
- Ron (once) creates a
~/drop/
folder - Ron's partners can drop files to him.
- The files go in subfolders named for the partner (sender)
Revising a Dropped Folder¶
Sometimes, you submit code that has an error in it, and I ask you to fix it and re-submit. Or maybe you realize the error before I ask, and you need to re-submit. Or maybe you're dropping code to your partner for a second time. If those situations arise, you can learn how to do that here.
First, and this is really confusing to people: there's a difference between the files and folders inside the tarfile, and the tarfile itself. Let's take a concrete example. Suppose you and your partner are working on the "Forms" assignment, and you create the following files:
forms/ app.py templates/ myform.html
Now, you go to the folder that contains the forms
folder and you create a tarfile:
forms.tar forms/ app.py templates/ myform.html
That tarfile contains the two folders and two files listed above, including their names.
Suppose you rename the tarfile, like this:
mv forms.tar forms-v1.tar
The folders and files inside the tarfile are not renamed! You named
the original file forms.tar
to remind you of what was in it, but
it has no other functional role. You could just as easily have named
it my_first_tarfile
or anything else.
If you drop the forms-v1.tar
file to the CS304 course account, it
becomes my file. When I un-tar it, it will contain the files and
folders listed above:
forms/ app.py templates/ myform.html
though they will now be in the CS 304 drop folder structure, in a subfolder named with your username.
Suppose there's an error. You can fix the original files, keeping
their names the same, and create a new tarfile, but you should give it
a different name, because you can't drop it again using the
forms-v1.tar
name, because there's already a file of that name in
your drop folder. You can do that in two ways.
One way is to create the tarfile with a different name from the start:
tar cf forms-v2.tar forms/
drop cs304 forms-v2.tar
Notice that the tar
command asks you for both the name of the folder
to pack up, and the name of the file to put the folder in.
The second way is to create the tarfile the same way you always do, and just rename it before dropping it:
tar cf forms.tar forms/
mv forms.tar forms-v2.tar
drop cs304 forms-v2.tar
Either of these is fine.
Corollary: do not change the name of the forms
folder, because
that's what I look for when I'm grading. Don't do the following:
mv forms forms-v2
tar cf forms-v2.tar forms-v2
drop cs304 forms-v2.tar
Because when I grade, I'll get confused.
The flip side of this difference between the tarfile's name and its
contents is that if your partner drops you a tarfile that contains
folder foo
and you untar it in someplace where there already is a
folder named foo
, the contents of the tarfile will replace the
current folder. Often, that's what you want (as when you drop a folder
for grading), but if you don't expect it, you'll be confused.