def monitor()
@fam = Fam::Connection.new(@session.name)
@fam.no_exists()
File::open(@lock, "w") do |f|
f.puts(Process::pid)
end
@fam.file(@lock)
@roots.each { |d| monitor_directory(d) }
Process::kill("SIGUSR1", Process::ppid)
loop do
ev = @fam.next_event
if ev.file == @lock
if ev.code == Fam::Event::DELETED
break
else
next
end
end
dir = @bases[ev.req]
if dir.nil?
$stderr.puts "No basedir for request #{ev.req} and file #{ev.file}"
next
end
path = File::expand_path(ev.file, dir)
if ev.code == Fam::Event::CREATED
record(path, CREATED)
Cft::log("Created %s " % path)
monitor_directory(path)
elsif ev.code == Fam::Event::DELETED
Cft::log("Deleted %s" % path)
record(path, DELETED)
unmonitor_directory(path)
elsif ev.code == Fam::Event::CHANGED
Cft::log("Changed %s" % path)
record(path, CHANGED)
else
record(path, ev.code)
end
end
@log.close()
@fam.close()
preserve_changes
end