[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

inotify subdirectories

Jay2 Fernando

1/24/2007 12:51:00 AM

i have been able to successfully use the inotify
(http://raa.ruby-lang.org/project/rub...) to monitor a directory,
and monitor subdirectories when they are created.

However, when a file is created in a newly monitored subdirectory, I
cannot figure out how I can get the full path to that file. to make this
clear, say i am monitoring the directory "/tmp/monitor", the script will
detect that a subdirectory "subdir" is created and will monitor that.
however, when a file (say "test") is created under "subdir", I do not
know how to get to that file, i.e. how can i get the full path
"/tmp/monitor/subdir/test".

i hope that was clear. can anyone help?

(i erroneously posted this message earlier at RForum. sorry for the
cross-post)

--
Posted via http://www.ruby-....

7 Answers

Martin DeMello

1/24/2007 7:25:00 AM

0

On 1/24/07, Jay2 Fernando <j2f@mailinator.com> wrote:
> i have been able to successfully use the inotify
> (http://raa.ruby-lang.org/project/rub...) to monitor a directory,
> and monitor subdirectories when they are created.
>
> However, when a file is created in a newly monitored subdirectory, I
> cannot figure out how I can get the full path to that file. to make this
> clear, say i am monitoring the directory "/tmp/monitor", the script will
> detect that a subdirectory "subdir" is created and will monitor that.
> however, when a file (say "test") is created under "subdir", I do not
> know how to get to that file, i.e. how can i get the full path
> "/tmp/monitor/subdir/test".

You need to maintain a hash of inotify watch descriptors to actual paths. e.g.

require 'inotify'
require 'find'

EVENTS = { 256 => "created", 512 => "deleted", 128 => "moved" }
watches = {}
i = Inotify.new

Dir["/home/*"].each {|userdir|
begin
wd = i.add_watch(userdir, Inotify::ALL_EVENTS)
watches[wd] = userdir
rescue
puts "Skipping #{userdir}: #{$!}"
end
}

t = Thread.new {
i.each_event {|ev|
unless ev.name =~ /^\./
puts "File #{ev.name} #{EVENTS[ev.mask]} in #{watches[ev.wd]}"
end
}
}

t.join

Jay2 Fernando

1/24/2007 1:05:00 PM

0

Martin DeMello wrote:
> On 1/24/07, Jay2 Fernando <j2f@mailinator.com> wrote:
>> "/tmp/monitor/subdir/test".
> You need to maintain a hash of inotify watch descriptors to actual
> paths. e.g.
>
> require 'inotify'
> require 'find'
>
> EVENTS = { 256 => "created", 512 => "deleted", 128 => "moved" }
> watches = {}
> i = Inotify.new
>
> Dir["/home/*"].each {|userdir|
> begin
> wd = i.add_watch(userdir, Inotify::ALL_EVENTS)
> watches[wd] = userdir
> rescue
> puts "Skipping #{userdir}: #{$!}"
> end
> }
>
> t = Thread.new {
> i.each_event {|ev|
> unless ev.name =~ /^\./
> puts "File #{ev.name} #{EVENTS[ev.mask]} in #{watches[ev.wd]}"
> end
> }
> }
>
> t.join

I tried this code but I get the following error:

undefined method `wd' for <Inotify::Event:0xDEADBEEF name=FIXME
mask=FIXME>:Inotify::Event (NoMethodError)

I got the source code from the URL above. I read the inotify header file
and saw the "wd" event. what could be the problem?

--
Posted via http://www.ruby-....

Martin DeMello

1/24/2007 1:20:00 PM

0

On 1/24/07, Jay2 Fernando <j2f@mailinator.com> wrote:
>
> I tried this code but I get the following error:
>
> undefined method `wd' for <Inotify::Event:0xDEADBEEF name=FIXME
> mask=FIXME>:Inotify::Event (NoMethodError)
>
> I got the source code from the URL above. I read the inotify header file
> and saw the "wd" event. what could be the problem?

You've got an old version of the inotify code - get it from here:
http://nbtsc.org/~aredridel/projects/ruby/rub...

martin

Jay2 Fernando

1/24/2007 2:16:00 PM

0

Martin DeMello wrote:
> On 1/24/07, Jay2 Fernando <j2f@mailinator.com> wrote:
>>
>> I tried this code but I get the following error:
>>
>> undefined method `wd' for <Inotify::Event:0xDEADBEEF name=FIXME
>> mask=FIXME>:Inotify::Event (NoMethodError)
>>
>> I got the source code from the URL above. I read the inotify header file
>> and saw the "wd" event. what could be the problem?
>
> You've got an old version of the inotify code - get it from here:
> http://nbtsc.org/~aredridel/projects/ruby/rub...
>
> martin

aha... ok. thanks for pointing me to correct source.


--
Posted via http://www.ruby-....

Werner

10/8/2010 7:43:00 PM

0

On Oct 8, 3:27 pm, Phlip <phlip2...@gmail.com> wrote:
> On Oct 8, 10:46 am, jane <jane.pla...@gmail.com> wrote:
>
> > You used to give us regular updates every time the price of crude oil
> > went up. What happened; why did you stop?
>
> > Is it because you are a partisan hack?
>
> Someone in the news recently said, if Obama were Republican, we'd hear
> an endless drumbeat of stories about how the markets are voting for
> him.


The Dow is up because the Fed will print lots more paper to look like
money. Obama has as little to do with the economy as Bush did.

http://www....

5872 Dead, 1015 since 1/20/09

10/8/2010 9:05:00 PM

0

On Fri, 8 Oct 2010 12:43:28 -0700 (PDT), Werner <whetzner@mac.com>
wrote:

>On Oct 8, 3:27?pm, Phlip <phlip2...@gmail.com> wrote:
>> On Oct 8, 10:46?am, jane <jane.pla...@gmail.com> wrote:
>>
>> > You used to give us regular updates every time the price of crude oil
>> > went up. What happened; why did you stop?
>>
>> > Is it because you are a partisan hack?
>>
>> Someone in the news recently said, if Obama were Republican, we'd hear
>> an endless drumbeat of stories about how the markets are voting for
>> him.
>
>
>The Dow is up because the Fed will print lots more paper to look like
>money. Obama has as little to do with the economy as Bush did.

The Dow is up because of inflation that hasn't happened?

How does that work, bubbles?
>
> http://www....

Werner

10/8/2010 11:54:00 PM

0

On Oct 8, 5:04 pm, "5732 Dead, 875 since 1/20/09" <dead@dead> wrote:
> On Fri, 8 Oct 2010 12:43:28 -0700 (PDT), Werner <whetz...@mac.com>
> wrote:
>
> >On Oct 8, 3:27 pm, Phlip <phlip2...@gmail.com> wrote:
> >> On Oct 8, 10:46 am, jane <jane.pla...@gmail.com> wrote:
>
> >> > You used to give us regular updates every time the price of crude oil
> >> > went up. What happened; why did you stop?
>
> >> > Is it because you are a partisan hack?
>
> >> Someone in the news recently said, if Obama were Republican, we'd hear
> >> an endless drumbeat of stories about how the markets are voting for
> >> him.
>
> >The Dow is up because the Fed will print lots more paper to look like
> >money. Obama has as little to do with the economy as Bush did.
>
> The Dow is up because of inflation that hasn't happened?
>
> How does that work, bubbles?
>
>

Markets, currencies, jobs, Fed, foreclosures
http://www.youtube.com/watch?v=Y...
Jim Rogers Markets Soaring But the World Is Worse Off
http://www.youtube.com/watch?v=U...





>
>
>
> >http://www....