guard / rb-inotify

A thorough inotify wrapper for Ruby using FFI.
MIT License
312 stars 64 forks source link

Fix crash when creating new files with utf8 specific characters on utf8 filesystems #27

Closed philou closed 11 years ago

philou commented 11 years ago

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

/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.

nex3 commented 11 years ago

This does need to be 1.8-compatible.

philou commented 11 years ago

Did you have the time to review my pull request ? Let me know if there is anything left I can do so that you can merge it. Thanks.

nex3 commented 11 years ago

Sorry, GitHub didn't send me a notification that you'd added another commit.