Forum: Ruby Check Flock Status on File

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E29eac7a986dbe96d7542d4bf0630be1?d=identicon&s=25 Matt (Guest)
on 2007-07-15 21:31
(Received via mailing list)
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?
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 ara.t.howard (Guest)
on 2007-07-16 17:23
(Received via mailing list)
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/post/5891548





-a
2f5c0f4501526070f1df8a01b210b6b5?d=identicon&s=25 barjunk (Guest)
on 2007-07-16 21:28
(Received via mailing list)
On Jul 16, 6:38 am, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
>
> fcntl/posix (see posixlock gem) locks export that information but
> flock, afaik, does not.  this seems workable though
>
> http://drawohara.tumblr.com/post/5891548
>
> -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.
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 ara.t.howard (Guest)
on 2007-07-16 23:22
(Received via mailing list)
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://drawohara.com/
2f5c0f4501526070f1df8a01b210b6b5?d=identicon&s=25 barjunk (Guest)
on 2007-07-16 23:41
(Received via mailing list)
On Jul 16, 1:17 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> > 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.
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 ara.t.howard (Guest)
on 2007-07-17 01:21
(Received via mailing list)
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://drawohara.com/
1bac2e65d64faf472cf2ebc94f0f5ee0?d=identicon&s=25 ara.t.howard (Guest)
on 2007-09-25 23:03
(Received via mailing list)
On Jul 16, 2007, at 9:23 AM, Matt Williams wrote:

> Matt
>

cool.  i had pasted the wrong code btw - the right stuff is up there
now...

cheers.


>> http://drawohara.tumblr.com/post/5891548
>

a @ http://drawohara.com/
This topic is locked and can not be replied to.