[Tutor] Re: Checking a file size before moving it

Derrick 'dman' Hudson dman@dman.ddts.net
Sat Feb 1 23:38:01 2003


--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Jan 31, 2003 at 01:55:46PM -0000, alan.gauld@bt.com wrote:
| > I assume that there is no simple way to tell if a file is=20
| > being accessed.
|=20
| OK, I'm at work now with access to my Unix books...
|=20
| The fcntl function allows you to get a lock. If the file is already=20
| locked you get that lock back. Within the lock structure you can=20
| read the user and process IDs. If they aint your own then the file=20
| is already locked by another user 0- and you know which one!

First of all, fcntl won't tell you if a file is being accessed if it
isn't locked.  I'm also not sure how the fcntl() interface interacts
with the flock() interface on any system (but I know that different
Unices do it differently).  In any case the locking is merely advisory
and any program is free to disregard it.

On windows you can ascertain whether or not a file is being accessed
by trying to remove it (an error will occur if the file is "in use").
Unix doesn't have that problem (or feature, as you may perceive it
right now).

I can't think of any reliable way to determine whether or not a file
is currently open.  The only things I can think of involve assuming a
maximum time for the transfer operation -- for example you could look
at the create (or access) time for the file and only move it if that
time is more than X seconds in the past. =20

What method do people use to put the files in the directory?  If you
can control that, then perhaps you can build a better solution.  For
example, if you can specify that a certain command (instead of 'cp')
is to be used, that command can run the python script or set some
flags.  If you can require that the file copy is performed through a
web server or some such you can have the server-side handler do
whatever is necessary (run the script, set flags, etc.).

HTH,
-D

--=20
"GUIs normally make it simple to accomplish simple actions and
impossible to accomplish complex actions."
    --Doug Gwyn  (22/Jun/91 in comp.unix.wizards)
=20
http://dman.ddts.net/~dman/

--k+w/mQv8wyuph6w0
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj48oHcACgkQO8l8XBKTpRQ4oQCgnHHR233P7oy4tu2jATp3EhRG
hP0AoIcg2CTZvARpBaLRyLgJmns98X0G
=cLAM
-----END PGP SIGNATURE-----

--k+w/mQv8wyuph6w0--