summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-04-15 21:28:32 +0200
committermathieui <mathieui@mathieui.net>2021-04-15 21:28:32 +0200
commitb1052e149f96eb9f474a2b93a178c88128877486 (patch)
tree6088b764afe8c11b0c376dff98bfaf0dd03a4f30
parenta6489fb66ac10cc3114c4b24cd8aae36d9a89e94 (diff)
downloadpoezio-b1052e149f96eb9f474a2b93a178c88128877486.tar.gz
poezio-b1052e149f96eb9f474a2b93a178c88128877486.tar.bz2
poezio-b1052e149f96eb9f474a2b93a178c88128877486.tar.xz
poezio-b1052e149f96eb9f474a2b93a178c88128877486.zip
fix: handle single-line log files, and reentry into fd_busy
-rw-r--r--poezio/logger.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/poezio/logger.py b/poezio/logger.py
index d82ce9ee..e46be469 100644
--- a/poezio/logger.py
+++ b/poezio/logger.py
@@ -136,7 +136,8 @@ class Logger:
"""
jidstr = str(jid).replace('/', '\\')
self._busy_fds[jidstr] = True
- self._buffered_fds[jidstr] = []
+ if jidstr not in self._buffered_fds:
+ self._buffered_fds[jidstr] = []
def fd_available(self, jid: Union[str, JID]) -> None:
"""Signal to the logger that this logfile is no longer busy.
@@ -371,15 +372,19 @@ def iterate_messages_reverse(filepath: Path) -> Generator[LogDict, None, None]:
with mmap.mmap(fd.fileno(), 0, prot=mmap.PROT_READ) as m:
# start of messages begin with MI or MR, after a \n
pos = m.rfind(b"\nM") + 1
- lines = parse_log_lines(
- m[pos:-1].decode(errors='replace').splitlines()
- )
+ if pos != -1:
+ lines = parse_log_lines(
+ m[pos:-1].decode(errors='replace').splitlines()
+ )
+ elif m[0:1] == b'M':
+ # Handle the case of a single message present in the log
+ # file, hence no newline.
+ lines = parse_log_lines(
+ m[:].decode(errors='replace').splitlines()
+ )
if lines:
yield lines[0]
- # number of message found so far
- count = 0
while pos > 0:
- count += 1
old_pos = pos
pos = m.rfind(b"\nM", 0, pos) + 1
lines = parse_log_lines(