rb-fsevent 0.9.2 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +3 -0
  4. data/Guardfile +8 -0
  5. data/{LICENSE → LICENSE.txt} +3 -1
  6. data/README.md +260 -0
  7. data/Rakefile +33 -0
  8. data/bin/fsevent_watch +0 -0
  9. data/ext/{fsevent_watch/LICENSE → LICENSE} +1 -1
  10. data/ext/fsevent_watch/FSEventsFix.c +626 -0
  11. data/ext/fsevent_watch/FSEventsFix.h +105 -0
  12. data/ext/fsevent_watch/{fsevent_watch/TSICTString.c → TSICTString.c} +34 -55
  13. data/ext/fsevent_watch/{fsevent_watch/TSICTString.h → TSICTString.h} +0 -0
  14. data/ext/fsevent_watch/{fsevent_watch/cli.c → cli.c} +48 -7
  15. data/ext/fsevent_watch/{fsevent_watch/cli.h → cli.h} +3 -3
  16. data/ext/fsevent_watch/{fsevent_watch/common.h → common.h} +1 -13
  17. data/ext/fsevent_watch/compat.c +41 -0
  18. data/ext/fsevent_watch/compat.h +100 -0
  19. data/ext/fsevent_watch/defines.h +42 -0
  20. data/ext/fsevent_watch/{fsevent_watch/main.c → main.c} +101 -62
  21. data/ext/fsevent_watch/signal_handlers.c +66 -0
  22. data/ext/fsevent_watch/signal_handlers.h +16 -0
  23. data/ext/rakefile.rb +225 -41
  24. data/lib/otnetstring.rb +85 -0
  25. data/lib/rb-fsevent/fsevent.rb +53 -7
  26. data/lib/rb-fsevent/version.rb +3 -1
  27. data/lib/rb-fsevent.rb +2 -1
  28. data/rb-fsevent.gemspec +26 -0
  29. metadata +53 -56
  30. data/README.rdoc +0 -255
  31. data/ext/fsevent_watch/Info.plist +0 -38
  32. data/ext/fsevent_watch/fsevent_watch/compat.c +0 -20
  33. data/ext/fsevent_watch/fsevent_watch/compat.h +0 -40
  34. data/ext/fsevent_watch/fsevent_watch.xcodeproj/project.pbxproj +0 -254
  35. data/ext/fsevent_watch/xcconfig/Common.xcconfig +0 -82
  36. data/ext/fsevent_watch/xcconfig/Debug.xcconfig +0 -19
  37. data/ext/fsevent_watch/xcconfig/Release.xcconfig +0 -23
  38. data/ext/fsevent_watch/xcconfig/fsevent_watch.xcconfig +0 -17
  39. data/ext/rb-fsevent.xcconfig +0 -33
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 699dcebd7c8e1b99dbd7eeae0b82b8e588e211104a67a549d412630db567ef3e
4
+ data.tar.gz: cff9f4532ae72dbc2e19d7025b211dc82444f10572079f0abac227f6a8f770f3
5
+ SHA512:
6
+ metadata.gz: c21fe63b0ed15e92c8cc5cc908b4c1c9fa93a882211cd21bb5a974d349697a896b0326ed4c721bb6b267fc4de70fffe357a31c17cdf0f932fcc1c9851868a695
7
+ data.tar.gz: 126114099b0302f935453f402b0817626e5fe2f8b1acc2c7316aed7263b2077d0db2f0fa6af907a61a752e03de18bc8ada50916609341c646421e1e7a61e1467
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ .DS_Store
3
+ .Trashes
4
+ .bundle
5
+ .com.apple.timemachine.supported
6
+ .fseventsd
7
+ .idea
8
+ .rbx
9
+ /ext/build
10
+ Desktop DB
11
+ Desktop DF
12
+ Gemfile.lock
13
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at http://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r(^spec/(.*)_spec.rb))
6
+ watch(%r(^lib/(.*)\.rb)) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { 'spec' }
8
+ end
@@ -1,4 +1,6 @@
1
- Copyright (c) 2010-2012 Thibaud Guillaume-Gentil & Travis Tilley
1
+ Copyright (c) 2010-2014 Thibaud Guillaume-Gentil & Travis Tilley
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,260 @@
1
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/thibaudgg/rb-fsevent)
2
+ [![endorse](https://api.coderwall.com/ttilley/endorsecount.png)](https://coderwall.com/ttilley)
3
+
4
+ # rb-fsevent
5
+
6
+ Very simple & usable Mac OSX FSEvents API
7
+
8
+ * Signals are working (really)
9
+ * Tested on MRI 2.4.1, RBX 3.72, JRuby 1.7.26 and 9.1.8.0
10
+ * Tested on 10.8
11
+
12
+ ## HFS+ filename corruption bug
13
+
14
+ There is a _very_ long-standing (since 2011) OSX bug where sometimes the filename metadata for HFS+ filesystems will get corrupted, resulting in some APIs returning one case for a file, and other APIs returning another. The result is that sometimes, _for no visible reason to the user_, fsevents would simply not work. As of rb-fsevent 0.9.5 this issue is properly detected and an insanely hacky (but effective) workaround is used that replaces the system `realpath()` with a custom implementation that should almost always return the same value as the kernel reporting (thus fixing fsevents). The major flaw in the workaround is that it may return the wrong path for hard links.
15
+
16
+ Please note that this doesn't repair the underlying issue on disk. Other apps and libraries using fsevents will continue to break with no warning. There may be other issues unrelated to fsevents.
17
+
18
+ __This bug is resolved in MacOS 10.12 and all users are strongly encouraged to upgrade.__
19
+
20
+ ## Install
21
+
22
+ gem install rb-fsevent
23
+
24
+ ### re-compilation
25
+
26
+ rb-fsevent comes with a pre-compiled fsevent\_watch binary supporting x86\_64 on 10.9 and above. The binary is codesigned with my (Travis Tilley) Developer ID as an extra precaution when distributing pre-compiled code and contains an embedded plist describing its build environment. This should be sufficient for most users, but if you need to use rb-fsevent on 10.8 or lower then recompilation is necessary. This can be done by entering the installed gem's ext directory and running:
27
+
28
+ MACOSX_DEPLOYMENT_TARGET="10.7" rake replace_exe
29
+
30
+ The following ENV vars are recognized:
31
+
32
+ * CC
33
+ * CFLAGS
34
+ * ARCHFLAGS
35
+ * MACOSX\_DEPLOYMENT\_TARGET
36
+ * FWDEBUG (enables debug mode, printing an obscene number of informational
37
+ messages to STDERR)
38
+
39
+ ### embedded plist
40
+
41
+ You can retrieve the values in the embedded plist via the CLI:
42
+
43
+ fsevent_watch --show-plist
44
+
45
+ The output is essentially formatted as `"#{key}:\n #{value}\n"` to make it easier to read than plist style xml. The result looks like this:
46
+
47
+ DTSDKName:
48
+ macosx10.5
49
+ FSEWBuildTriple:
50
+ i386-apple-darwin10.8.0
51
+ FSEWCC:
52
+ /usr/bin/gcc-4.2
53
+ DTSDKPath:
54
+ /Developer/SDKs/MacOSX10.5.sdk
55
+ FSEWCCVersion:
56
+ i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
57
+ FSEWCFLAGS:
58
+ -fconstant-cfstrings -fno-strict-aliasing -Wall -mmacosx-version-min=10.5 -O3
59
+
60
+ If, for some perverse reason, you prefer to look at the xml... it can be retrieved via:
61
+
62
+ otool -s __TEXT __info_plist ./bin/fsevent_watch | grep ^0 | xxd -r -
63
+
64
+ ### codesign
65
+
66
+ You can verify code signing information for a specific fsevent\_watch via:
67
+
68
+ codesign -d -vvv ./bin/fsevent_watch
69
+
70
+ If you're using the pre-compiled binary, then the output should contain something to the effect of:
71
+
72
+ Authority=Developer ID Application: Travis Tilley
73
+ Authority=Developer ID Certification Authority
74
+ Authority=Apple Root CA
75
+ Timestamp=Dec 31, 2012 12:49:13 PM
76
+
77
+ ## Usage
78
+
79
+ ### Singular path
80
+
81
+ ```ruby
82
+ require 'rb-fsevent'
83
+
84
+ fsevent = FSEvent.new
85
+ fsevent.watch Dir.pwd do |directories|
86
+ puts "Detected change inside: #{directories.inspect}"
87
+ end
88
+ fsevent.run
89
+ ```
90
+
91
+ ### Multiple paths
92
+
93
+ ```ruby
94
+ require 'rb-fsevent'
95
+
96
+ paths = ['/tmp/path/one', '/tmp/path/two', Dir.pwd]
97
+
98
+ fsevent = FSEvent.new
99
+ fsevent.watch paths do |directories|
100
+ puts "Detected change inside: #{directories.inspect}"
101
+ end
102
+ fsevent.run
103
+ ```
104
+
105
+ ### Multiple paths and additional options as a Hash
106
+
107
+ ```ruby
108
+ require 'rb-fsevent'
109
+
110
+ paths = ['/tmp/path/one', '/tmp/path/two', Dir.pwd]
111
+ options = {:latency => 1.5, :no_defer => true }
112
+
113
+ fsevent = FSEvent.new
114
+ fsevent.watch paths, options do |directories|
115
+ puts "Detected change inside: #{directories.inspect}"
116
+ end
117
+ fsevent.run
118
+ ```
119
+
120
+ ### Multiple paths and additional options as an Array
121
+
122
+ ```ruby
123
+ require 'rb-fsevent'
124
+
125
+ paths = ['/tmp/path/one', '/tmp/path/two', Dir.pwd]
126
+ options = ['--latency', 1.5, '--no-defer']
127
+
128
+ fsevent = FSEvent.new
129
+ fsevent.watch paths, options do |directories|
130
+ puts "Detected change inside: #{directories.inspect}"
131
+ end
132
+ fsevent.run
133
+ ```
134
+
135
+ ### Using _full_ event information
136
+
137
+ ```ruby
138
+ require 'rb-fsevent'
139
+ fsevent = FSEvent.new
140
+ fsevent.watch Dir.pwd do |paths, event_meta|
141
+ event_meta['events'].each do |event|
142
+ puts "event ID: #{event['id']}"
143
+ puts "path: #{event['path']}"
144
+ puts "c flags: #{event['cflags']}"
145
+ puts "named flags: #{event['flags'].join(', ')}"
146
+ # named flags will include strings such as `ItemInodeMetaMod` or `OwnEvent`
147
+ end
148
+ end
149
+ fsevent.run
150
+ ```
151
+
152
+ ## Options
153
+
154
+ When defining options using a hash or hash-like object, it gets checked for validity and converted to the appropriate fsevent\_watch commandline arguments array when the FSEvent class is instantiated. This is obviously the safest and preferred method of passing in options.
155
+
156
+ You may, however, choose to pass in an array of commandline arguments as your options value and it will be passed on, unmodified, to the fsevent\_watch binary when called.
157
+
158
+ So far, the following options are supported:
159
+
160
+ * :latency => 0.5 # in seconds
161
+ * :no\_defer => true
162
+ * :watch\_root => true
163
+ * :since\_when => 18446744073709551615 # an FSEventStreamEventId
164
+ * :file\_events => true
165
+
166
+ ### Latency
167
+
168
+ The :latency parameter determines how long the service should wait after the first event before passing that information along to the client. If your latency is set to 4 seconds, and 300 changes occur in the first three, then the callback will be fired only once. If latency is set to 0.1 in the exact same scenario, you will see that callback fire somewhere closer to between 25 and 30 times.
169
+
170
+ Setting a higher latency value allows for more effective temporal coalescing, resulting in fewer callbacks and greater overall efficiency... at the cost of apparent responsiveness. Setting this to a reasonably high value (and NOT setting :no\_defer) is particularly well suited for background, daemon, or batch processing applications.
171
+
172
+ Implementation note: It appears that FSEvents will only coalesce events from a maximum of 32 distinct subpaths, making the above completely accurate only when events are to fewer than 32 subpaths. Creating 300 files in one directory, for example, or 30 files in 10 subdirectories, but not 300 files within 300 subdirectories. In the latter case, you may receive 31 callbacks in one go after the latency period. As this appears to be an implementation detail, the number could potentially differ across OS revisions. It is entirely possible that this number is somehow configurable, but I have not yet discovered an accepted method of doing so.
173
+
174
+ ### NoDefer
175
+
176
+ The :no\_defer option changes the behavior of the latency parameter completely. Rather than waiting for $latency period of time before sending along events in an attempt to coalesce a potential deluge ahead of time, that first event is sent along to the client immediately and is followed by a $latency period of silence before sending along any additional events that occurred within that period.
177
+
178
+ This behavior is particularly useful for interactive applications where that feeling of apparent responsiveness is most important, but you still don't want to get overwhelmed by a series of events that occur in rapid succession.
179
+
180
+ ### WatchRoot
181
+
182
+ The :watch\_root option allows for catching the scenario where you start watching "~/src/demo\_project" and either it is later renamed to "~/src/awesome\_sauce\_3000" or the path changes in such a manner that the original directory is now at "~/clients/foo/iteration4/demo\_project".
183
+
184
+ Unfortunately, while this behavior is somewhat supported in the fsevent\_watch binary built as part of this project, support for passing across detailed metadata is not (yet). As a result, you would not receive the appropriate RootChanged event and be able to react appropriately. Also, since the C code doesn't open watched directories and retain that file descriptor as part of path-specific callback metadata, we are unable to issue an F\_GETPATH fcntl() to determine the directory's new path.
185
+
186
+ Please do not use this option until proper support is added (or, even better, add it and submit a pull request).
187
+
188
+ ### SinceWhen
189
+
190
+ The FSEventStreamEventId passed in to :since\_when is used as a base for reacting to historic events. Unfortunately, not only is the metadata for transitioning from historic to live events not currently passed along, but it is incorrectly passed as a change event on the root path, and only per-host event streams are currently supported. When using per-host event streams, the event IDs are not guaranteed to be unique or contiguous when shared volumes (firewire/USB/net/etc) are used on multiple macs.
191
+
192
+ Please do not use this option until proper support is added, unless it's acceptable for you to receive that one fake event that's handled incorrectly when events transition from historical to live. Even in that scenario, there's no metadata available for determining the FSEventStreamEventId of the last received event.
193
+
194
+ WARNING: passing in 0 as the parameter to :since\_when will return events for every directory modified since "the beginning of time".
195
+
196
+ ### FileEvents ###
197
+
198
+ Prepare yourself for an obscene number of callbacks. Realistically, an "Atomic Save" could easily fire maybe 6 events for the combination of creating the new file, changing metadata/permissions, writing content, swapping out the old file for the new may itself result in multiple events being fired, and so forth. By the time you get the event for the temporary file being created as part of the atomic save, it will already be gone and swapped with the original file. This and issues of a similar nature have prevented me from adding the option to the ruby code despite the fsevent\_watch binary supporting file level events for quite some time now. Mountain Lion seems to be better at coalescing needless events, but that might just be my imagination.
199
+
200
+ ## Debugging output
201
+
202
+ If the gem is re-compiled with the environment variable FWDEBUG set, then fsevent\_watch will be built with its various DEBUG sections defined, and the output to STDERR is truly verbose (and hopefully helpful in debugging your application and not just fsevent\_watch itself). If enough people find this to be directly useful when developing code that makes use of rb-fsevent, then it wouldn't be hard to clean this up and make it a feature enabled by a commandline argument instead. Until somebody files an issue, however, I will assume otherwise.
203
+
204
+ append_path called for: /tmp/moo/cow/
205
+ resolved path to: /private/tmp/moo/cow
206
+
207
+ config.sinceWhen 18446744073709551615
208
+ config.latency 0.300000
209
+ config.flags 00000000
210
+ config.paths
211
+ /private/tmp/moo/cow
212
+
213
+ FSEventStreamRef @ 0x100108540:
214
+ allocator = 0x7fff705a4ee0
215
+ callback = 0x10000151e
216
+ context = {0, 0x0, 0x0, 0x0, 0x0}
217
+ numPathsToWatch = 1
218
+ pathsToWatch = 0x7fff705a4ee0
219
+ pathsToWatch[0] = '/private/tmp/moo/cow'
220
+ latestEventId = -1
221
+ latency = 300000 (microseconds)
222
+ flags = 0x00000000
223
+ runLoop = 0x0
224
+ runLoopMode = 0x0
225
+
226
+ FSEventStreamCallback fired!
227
+ numEvents: 32
228
+ event path: /private/tmp/moo/cow/1/a/
229
+ event flags: 00000000
230
+ event ID: 1023767
231
+ event path: /private/tmp/moo/cow/1/b/
232
+ event flags: 00000000
233
+ event ID: 1023782
234
+ event path: /private/tmp/moo/cow/1/c/
235
+ event flags: 00000000
236
+ event ID: 1023797
237
+ event path: /private/tmp/moo/cow/1/d/
238
+ event flags: 00000000
239
+ event ID: 1023812
240
+ [etc]
241
+
242
+
243
+ ## Development
244
+
245
+ * Source hosted at [GitHub](http://github.com/thibaudgg/rb-fsevent)
246
+ * Report issues/Questions/Feature requests on [GitHub Issues](http://github.com/thibaudgg/rb-fsevent/issues)
247
+
248
+ Pull requests are quite welcome! Please ensure that your commits are in a topic branch for each individual changeset that can be reasonably isolated. It is also important to ensure that your changes are well tested... whether that means new tests, modified tests, or fixing a scenario where the existing tests currently fail. If you have rbenv and ruby-build, we have a helper task for running the testsuite in all of them:
249
+
250
+ rake spec:portability
251
+
252
+ The list of tested targets is currently:
253
+
254
+ %w[2.4.1 rbx-3.72 jruby-1.7.26 jruby-9.1.8.0]
255
+
256
+ ## Authors
257
+
258
+ * [Travis Tilley](http://github.com/ttilley)
259
+ * [Thibaud Guillaume-Gentil](http://github.com/thibaudgg)
260
+ * [Andrey Tarantsov](https://github.com/andreyvit)
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
8
+
9
+ namespace(:spec) do
10
+ desc "Run all specs on multiple ruby versions"
11
+ task(:portability) do
12
+ versions = %w[2.4.1 rbx-3.72 jruby-1.7.26 jruby-9.1.8.0]
13
+ versions.each do |version|
14
+ # system <<-BASH
15
+ # bash -c 'source ~/.rvm/scripts/rvm;
16
+ # rvm #{version};
17
+ # echo "--------- version #{version} ----------\n";
18
+ # bundle install;
19
+ # rake spec'
20
+ # BASH
21
+ system <<-BASH
22
+ bash -c 'export PATH="$HOME/.rbenv/bin:$PATH";
23
+ [[ `which rbenv` ]] && eval "$(rbenv init -)";
24
+ [[ ! -a $HOME/.rbenv/versions/#{version} ]] && rbenv install #{version};
25
+ rbenv shell #{version};
26
+ rbenv which bundle 2> /dev/null || gem install bundler;
27
+ rm Gemfile.lock;
28
+ bundle install;
29
+ rake spec;'
30
+ BASH
31
+ end
32
+ end
33
+ end
data/bin/fsevent_watch CHANGED
Binary file
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Travis Tilley
1
+ Copyright (c) 2011-2013 Travis Tilley
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the