9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/captured/fs_events.rb', line 9
def run
callback = proc do |stream, ctx, numEvents, paths, marks, eventIDs|
paths.regard_as('*')
rpaths = []
numEvents.times { |i| rpaths << paths[i] }
yield(*rpaths)
end
allocator = OSX::KCFAllocatorDefault
context = nil
path = [@watch_dir]
sinceWhen = OSX::KFSEventStreamEventIdSinceNow
latency = 1.0
flags = 0
stream = OSX::FSEventStreamCreate(allocator, callback, context, path, sinceWhen, latency, flags)
unless stream
puts "Failed to create stream"
exit
end
OSX::FSEventStreamScheduleWithRunLoop(stream, OSX::CFRunLoopGetCurrent(), OSX::KCFRunLoopDefaultMode)
unless OSX::FSEventStreamStart(stream)
puts "Failed to start stream"
exit
end
puts "Watching #{path}"
OSX::CFRunLoopRun()
rescue Interrupt
OSX::FSEventStreamStop(stream)
OSX::FSEventStreamInvalidate(stream)
OSX::FSEventStreamRelease(stream)
end
|