Check Flock Status on File

M

Matt

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?
 
A

ara.t.howard

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
 
B

barjunk

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


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.
 
A

ara.t.howard

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/
 
B

barjunk

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.
 
A

ara.t.howard

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top