nex3/rb-inotify — pull request #27 by philou (2013-08-21 04:37:14+00:00)
Title: Fix crash when creating new files with utf8 specific characters on utf8 filesystems

On my utf8 filesystem, I got the following error while running guard cucumber :+1:

/home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:193:in `join': incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:193:in `block in watch'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:192:in `each'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:192:in `watch'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:204:in `block in watch'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/watcher.rb:41:in `[]'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/watcher.rb:41:in `callback!'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/event.rb:128:in `callback!'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:234:in `block in process'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:234:in `each'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:234:in `process'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/rb-inotify-0.9.0/lib/rb-inotify/notifier.rb:217:in `run'
from /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/vendor/bundle/gems/listen-1.2.2/lib/listen/adapters/linux.rb:76:in `block in start_worker'

Details on the failing join :

Path.join(path, base)
path (ASCII-8BIT): /home/philou/Dropbox/mes-courses.fr/Code/WIP/mes-courses-dev/tmp/dummy-store/www.dummy-store.com/Marché
base (UTF-8): Légumes

When the "Marché" directory was created, the native event's bytes are stored inside an ASCII-8BIT chain (standard encoding for readpartial result), but when cleanedup in Event.initialize, the encoding is kept whatever the real filesystem encoding. This only worked as long as the file name contains only ascii-8bit compatible characters.

There is no force_encoding method on ruby 1.8.x, I know my patch is not ruby 1.8 compatible. I don't know if this is an issue.