mirror of
https://github.com/powerline/powerline.git
synced 2025-07-26 23:35:04 +02:00
Allow bytes paths in watchers
This commit is contained in:
parent
be7056fd7d
commit
7dd65a000b
@ -174,7 +174,7 @@ class INotify(object):
|
|||||||
pos += self.hdr.size
|
pos += self.hdr.size
|
||||||
name = None
|
name = None
|
||||||
if get_name:
|
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
|
pos += name_len
|
||||||
self.process_event(wd, mask, cookie, name)
|
self.process_event(wd, mask, cookie, name)
|
||||||
|
|
||||||
|
@ -247,6 +247,8 @@ class INotifyTreeWatcher(INotify):
|
|||||||
if mask & self.CREATE:
|
if mask & self.CREATE:
|
||||||
# A new sub-directory might have been created, monitor it.
|
# A new sub-directory might have been created, monitor it.
|
||||||
try:
|
try:
|
||||||
|
if not isinstance(path, bytes):
|
||||||
|
name = name.decode(self.fenc)
|
||||||
self.add_watch(os.path.join(path, name))
|
self.add_watch(os.path.join(path, name))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
@ -56,15 +57,24 @@ def start_uv_thread():
|
|||||||
return _uv_thread.uv_loop
|
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):
|
class UvWatcher(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
import_pyuv()
|
import_pyuv()
|
||||||
self.watches = {}
|
self.watches = {}
|
||||||
self.lock = RLock()
|
self.lock = RLock()
|
||||||
self.loop = start_uv_thread()
|
self.loop = start_uv_thread()
|
||||||
|
self.fenc = sys.getfilesystemencoding() or 'utf-8'
|
||||||
|
|
||||||
def watch(self, path):
|
def watch(self, path):
|
||||||
path = realpath(path)
|
path = normpath(path, self.fenc)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if path not in self.watches:
|
if path not in self.watches:
|
||||||
try:
|
try:
|
||||||
@ -82,7 +92,7 @@ class UvWatcher(object):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def unwatch(self, path):
|
def unwatch(self, path):
|
||||||
path = realpath(path)
|
path = normpath(path, self.fenc)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
try:
|
try:
|
||||||
watch = self.watches.pop(path)
|
watch = self.watches.pop(path)
|
||||||
@ -92,7 +102,7 @@ class UvWatcher(object):
|
|||||||
|
|
||||||
def is_watching(self, path):
|
def is_watching(self, path):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
return realpath(path) in self.watches
|
return normpath(path, self.fenc) in self.watches
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
try:
|
try:
|
||||||
@ -122,7 +132,7 @@ class UvFileWatcher(UvWatcher):
|
|||||||
self.events.pop(path, None)
|
self.events.pop(path, None)
|
||||||
|
|
||||||
def __call__(self, path):
|
def __call__(self, path):
|
||||||
path = realpath(path)
|
path = normpath(path, self.fenc)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
events = self.events.pop(path, None)
|
events = self.events.pop(path, None)
|
||||||
if events:
|
if events:
|
||||||
@ -139,12 +149,12 @@ class UvTreeWatcher(UvWatcher):
|
|||||||
def __init__(self, basedir, ignore_event=None):
|
def __init__(self, basedir, ignore_event=None):
|
||||||
super(UvTreeWatcher, self).__init__()
|
super(UvTreeWatcher, self).__init__()
|
||||||
self.ignore_event = ignore_event or (lambda path, name: False)
|
self.ignore_event = ignore_event or (lambda path, name: False)
|
||||||
self.basedir = realpath(basedir)
|
self.basedir = normpath(basedir, self.fenc)
|
||||||
self.modified = True
|
self.modified = True
|
||||||
self.watch_directory(self.basedir)
|
self.watch_directory(self.basedir)
|
||||||
|
|
||||||
def watch_directory(self, path):
|
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):
|
def watch_one_directory(self, arg, dirname, fnames):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user