In article <Se********************@comcast.com>,
"Chung Leong" <ch***********@hotmail.com> wrote:
"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42*********************@news6.xs4all.nl... Chung Leong <ch***********@hotmail.com> wrote:
Maybe an attempt to rename the file is a more reliable test?
That will also not work on unix type filesystem since only the name f
the inode will change.
My understanding of Unix is rather limited. So you are saying the rename
operation would succeed even when there's an open handle to the file? How
about delete? Surely you can't delete the file while it's still open, right?
If so, we can create a hard link to the file then try deleting it under the
original name and see what happens.
The actual data structure that describes the file is called an inode on
Unix filesystems. It has information on the file's size, blocksize,
access times, permissions, ownership and link count (more on that
later).
When you creat() a file, the number of an inode is entered into a
directory file along with the file's name and the various fields in the
inode are filled in. You can rename a file that's open if you have
write permission on the directory where it's located. This is because
you're changing the filename field in a directory file and not touching
the file's inode or data itself. The contents of the file rename
unchanged as the process that's accessing the file does so by inode.
When a process opens a file, it ultimately uses the inode as a
reference. There's no mandatory file locking mechanism built into a
Unix filesystem. All that locking stuff came later, IIRC. AFAIK, the
file locking API is advisory and it's up the the program to check that a
file is locked using the locking calls available from the OS (flock, et
al) or come up with it's own methodology.
It's completely possible to delete a file that's open for writing since
you're just removing an inode/filename entry in a directory file. The
space allocated by the file is not returned to the free space pool until
the file is closed by the program that's opened it. It's a frequent
newbie sysadmin mistake to delete a system log file that's filling a
filesystem without determining and killing the process that's got the
file open. Unless you already know what process is writing
/var/adm/log/system.log, you're only option at that point is to reboot
to recover the space.
An additional feature that Unix filesystems have is the ability to have
multiple directory entries all pointing to the same inode. These are
called 'hard links'. When you create a file, a inode is allocated and
the information specific to the file is inserted into the file. A
corresponding entry is made to a directory file for that inode. You can
create a link in another directory or the same directory with a
different name to the same inode. The "link count" is incremented
saying there are 2 directory entries for the file. When a file is
deleted, the inode's link count is decremented. If it's 0, the inode is
returned to the free pool to be reused. Note that each Unix filesystem
has it's own inode table. Hard links cannot span filesystems.
A hard link is not the same thing as a "shortcut" or "file alias" in
other OSes. "Soft links" were created to allow spanning filesystems.
They are simply entries in directories that point to a real file
anywhere in the Unix directory tree. When created, the ln command
checks for the files existence, but that's it. If you delete the
underlying real file, the soft link is still there and now "broken".
Now, to your problem. Unless you have some way of knowing the length of
the file being transferred or that the transfer is completed, I don't
see a way to do this sort of thing without writing your own protocol and
doing it yourself. There's curl, which can be built into php. I like
the idea of sending a file titled "999lastfile.txt" and checking for
that before the cron job proceeds.
--
DeeDee, don't press that button! DeeDee! NO! Dee...