diff --git a/powerline/lib/inotify.py b/powerline/lib/inotify.py index 2ef5aa78..821401e3 100644 --- a/powerline/lib/inotify.py +++ b/powerline/lib/inotify.py @@ -174,7 +174,7 @@ class INotify(object): pos += self.hdr.size name = None if get_name: - name = raw[pos:pos + name_len].rstrip(b'\0').decode(self.fenc) + name = raw[pos:pos + name_len].rstrip(b'\0') pos += name_len self.process_event(wd, mask, cookie, name) diff --git a/powerline/lib/watcher/inotify.py b/powerline/lib/watcher/inotify.py index 6708b21e..4a134e8d 100644 --- a/powerline/lib/watcher/inotify.py +++ b/powerline/lib/watcher/inotify.py @@ -247,6 +247,8 @@ class INotifyTreeWatcher(INotify): if mask & self.CREATE: # A new sub-directory might have been created, monitor it. try: + if not isinstance(path, bytes): + name = name.decode(self.fenc) self.add_watch(os.path.join(path, name)) except OSError as e: if e.errno == errno.ENOENT: diff --git a/powerline/lib/watcher/uv.py b/powerline/lib/watcher/uv.py index 6268580a..6fe03138 100644 --- a/powerline/lib/watcher/uv.py +++ b/powerline/lib/watcher/uv.py @@ -2,6 +2,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_function) import os +import sys from collections import defaultdict from threading import RLock @@ -56,15 +57,24 @@ def start_uv_thread(): return _uv_thread.uv_loop +def normpath(path, fenc): + path = realpath(path) + if isinstance(path, bytes): + return path.decode(fenc) + else: + return path + + class UvWatcher(object): def __init__(self): import_pyuv() self.watches = {} self.lock = RLock() self.loop = start_uv_thread() + self.fenc = sys.getfilesystemencoding() or 'utf-8' def watch(self, path): - path = realpath(path) + path = normpath(path, self.fenc) with self.lock: if path not in self.watches: try: @@ -82,7 +92,7 @@ class UvWatcher(object): raise def unwatch(self, path): - path = realpath(path) + path = normpath(path, self.fenc) with self.lock: try: watch = self.watches.pop(path) @@ -92,7 +102,7 @@ class UvWatcher(object): def is_watching(self, path): with self.lock: - return realpath(path) in self.watches + return normpath(path, self.fenc) in self.watches def __del__(self): try: @@ -122,7 +132,7 @@ class UvFileWatcher(UvWatcher): self.events.pop(path, None) def __call__(self, path): - path = realpath(path) + path = normpath(path, self.fenc) with self.lock: events = self.events.pop(path, None) if events: @@ -139,12 +149,12 @@ class UvTreeWatcher(UvWatcher): def __init__(self, basedir, ignore_event=None): super(UvTreeWatcher, self).__init__() self.ignore_event = ignore_event or (lambda path, name: False) - self.basedir = realpath(basedir) + self.basedir = normpath(basedir, self.fenc) self.modified = True self.watch_directory(self.basedir) def watch_directory(self, path): - os.path.walk(realpath(path), self.watch_one_directory, None) + os.path.walk(normpath(path, self.fenc), self.watch_one_directory, None) def watch_one_directory(self, arg, dirname, fnames): try: