[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Check Flock Status on File

Matt

7/15/2007 7:26:00 PM

I have a daemon that is checking files as they are uploaded by FTP and
processing them accordingly.
I noticed that occasionally the files are truncated, and have put this
down to the file currently being written by the FTP server as im
reading it.
I would like to check the lock status on the file, so I will only
process the file if it is not write-locked.
How can I check the lock status on a given filename?

5 Answers

ara.t.howard

7/16/2007 2:39:00 PM

0


On Jul 15, 2007, at 1:30 PM, Matt wrote:

> I have a daemon that is checking files as they are uploaded by FTP and
> processing them accordingly.
> I noticed that occasionally the files are truncated, and have put this
> down to the file currently being written by the FTP server as im
> reading it.
> I would like to check the lock status on the file, so I will only
> process the file if it is not write-locked.
> How can I check the lock status on a given filename?
>
>

fcntl/posix (see posixlock gem) locks export that information but
flock, afaik, does not. this seems workable though

http://drawohara.tumblr.com/po...





-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




barjunk

7/16/2007 7:24:00 PM

0

On Jul 16, 6:38 am, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> On Jul 15, 2007, at 1:30 PM, Matt wrote:
>
> > I have a daemon that is checking files as they are uploaded by FTP and
> > processing them accordingly.
> > I noticed that occasionally the files are truncated, and have put this
> > down to the file currently being written by the FTP server as im
> > reading it.
> > I would like to check the lock status on the file, so I will only
> > process the file if it is not write-locked.
> > How can I check the lock status on a given filename?
>
> fcntl/posix (see posixlock gem) locks export that information but
> flock, afaik, does not. this seems workable though
>
> http://drawohara.tumblr.com/po...
>
> -a
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama


So the code above modifies the File class so that an instance will
include a flocked? method, right?

Is it a good assumption that something like this would eventually make
it into File?

Mike B.

ara.t.howard

7/16/2007 9:17:00 PM

0


On Jul 16, 2007, at 1:25 PM, barjunk wrote:

> So the code above modifies the File class so that an instance will
> include a flocked? method, right?

indeed.

>
> Is it a good assumption that something like this would eventually make
> it into File?

hmmm. i wouldn't hold my breath - but you could put in an rcr ;-)

a @ http://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




barjunk

7/16/2007 9:39:00 PM

0

On Jul 16, 1:17 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> On Jul 16, 2007, at 1:25 PM, barjunk wrote:
>
> > So the code above modifies the File class so that an instance will
> > include a flocked? method, right?
>
> indeed.
>
>
>
> > Is it a good assumption that something like this would eventually make
> > it into File?
>
> hmmm. i wouldn't hold my breath - but you could put in an rcr ;-)
>

OK. I'll keep it lying about then, cause it seems very usefull.

One last thing. So I assume then, that multiple process as well as
multiple threads will maintain the lock properly.

Mike B.

ara.t.howard

7/16/2007 10:41:00 PM

0


On Jul 16, 2007, at 3:39 PM, barjunk wrote:

> One last thing. So I assume then, that multiple process as well as
> multiple threads will maintain the lock properly.

no - just processes. it's easy to extend ruby's flock to support
processes though: just keep state in thread local vars - i think i
actually have code lying around that does just that.... (goes
hunting...)

a @ http://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama