Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: how to tell if a file is still being modified (use the filename as a communications channel)

by grinder (Bishop)
on Sep 15, 2003 at 20:08 UTC ( #291642=note: print w/replies, xml ) Need Help??

in reply to how to tell if a file is still being modified

In cases like these I use the name of the file itself as a channel to other processes to let them know whether they are allowed to play with it or not. This does, however, require that you have control over the process that is sending you the files.

All you have to do is to arrange for the sender to put files on your server according to a specific filename convention (e.g. PUT or PUT in ftp parlance).

After the transfer is complete, the sender then sends down another command to rename the file: RENAME or RENAME, respectively. Whatever works best for you. The trick is that the sender must do this, the receiver cannot.

As a receiver, you only have to search for files with the agreed-upon extension (.ready or whatever). You can even push the vice as far as renaming the file, on the receiving side (e.g. so that the sending side knows that the file has been processed, should the housekeeping be their responsibility.

This is also pretty robust in terms of sudden death reboots. It becomes trivial to determine if files need to be resent or reprocessed.

This is a language- and platform-agnostic technique. You can use it pretty much anywhere you can give names to things. If you can't rename, (sometimes not possible with anonymous ftp uploads) you can always create another file along the principal file (e.g. possibly with zero-length, possibly containing an MD5 checksum, to achieve a similar result.

The main point to remember is that you don't want to try and second-guess the sender on the receiving side. To try and do so will cause untold pain. Just get the sender to tell you.

  • Comment on Re: how to tell if a file is still being modified (use the filename as a communications channel)

Replies are listed 'Best First'.
Re2: how to tell if a file is still being modified (use the filename as a communications channel)
by dragonchild (Archbishop) on Sep 16, 2003 at 02:32 UTC
    This is the method we use in batch processing at one of the largest banks in the US. Another method is to poll the size of the file every so many seconds. After the file doesn't grow for N polls (usually 2), we can assume the file is done. -s isn't that expensive, especially in the batch world.

    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://291642]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-02-26 08:09 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (371 votes). Check out past polls.