inotify: Correctly parse multiple structs at once
When multiple events arrive together, the `Inotify.read()` method parsed them incorrectly and emitted the same `Event` for each one. This commit corrects this behavior by appropriately parsing each struct.master
parent
533071b981
commit
485fa1c558
|
@ -173,16 +173,21 @@ class Inotify(object):
|
|||
|
||||
buf = memoryview(os.read(self.__fd, self.BUFSIZE))
|
||||
nread = len(buf)
|
||||
i = 0
|
||||
while i < nread:
|
||||
wd, mask, cookie, sz = self._unpack(buf)
|
||||
i = begin = 0
|
||||
end = self.STRUCT_SIZE
|
||||
while end < nread and buf[end:end + 1] != b'\x00':
|
||||
end += 1
|
||||
name = buf[self.STRUCT_SIZE:end].tobytes()
|
||||
while i < nread:
|
||||
wd, mask, cookie, sz = self._unpack(buf[begin:end])
|
||||
begin = end
|
||||
end += sz
|
||||
x = begin
|
||||
while buf[x:x + 1] != b'\x00':
|
||||
x += 1
|
||||
name = buf[begin:x].tobytes()
|
||||
pathname = self.__watches[wd]
|
||||
i += self.STRUCT_SIZE + sz
|
||||
i += end
|
||||
yield Event(wd, mask, cookie, name, pathname)
|
||||
begin = end
|
||||
end += self.STRUCT_SIZE
|
||||
|
||||
def close(self):
|
||||
'''Close all watch descriptors and the inotify descriptor'''
|
||||
|
|
Loading…
Reference in New Issue