|
|
@@ -993,22 +993,17 @@ class WebServer: |
|
|
|
out = [] |
|
|
|
size = 0 |
|
|
|
incomplete = False |
|
|
|
while True: |
|
|
|
buf = await proc.stdout.read(1024) |
|
|
|
if not buf: |
|
|
|
break |
|
|
|
while (buf := await proc.stdout.read(1024)): |
|
|
|
self.logger.debug(f'Request {id(request)} grep stdout: {buf!r}') |
|
|
|
if size + len(buf) > self.config['web']['search']['maxSize']: |
|
|
|
self.logger.warning(f'Request {id(request)} grep output exceeds max size') |
|
|
|
bufLFPos = buf.rfind(b'\n', 0, self.config['web']['search']['maxSize'] - size) |
|
|
|
if bufLFPos > -1: |
|
|
|
if (bufLFPos := buf.rfind(b'\n', 0, self.config['web']['search']['maxSize'] - size)) > -1: |
|
|
|
# There's a LF in this buffer at the right position, keep everything up to it such that the total size is <= maxSize. |
|
|
|
out.append(buf[:bufLFPos + 1]) |
|
|
|
else: |
|
|
|
# Try to find the last LF in the previous buffers |
|
|
|
for i, prevBuf in enumerate(reversed(out)): |
|
|
|
lfPos = prevBuf.rfind(b'\n') |
|
|
|
if lfPos > -1: |
|
|
|
if (lfPos := prevBuf.rfind(b'\n')) > -1: |
|
|
|
out[i] = out[i][:lfPos + 1] |
|
|
|
out = out[:i + 1] |
|
|
|
break |
|
|
@@ -1024,10 +1019,7 @@ class WebServer: |
|
|
|
|
|
|
|
async def process_stderr(): |
|
|
|
buf = b'' |
|
|
|
while True: |
|
|
|
buf = buf + (await proc.stderr.read(64)) |
|
|
|
if not buf: |
|
|
|
break |
|
|
|
while (buf := buf + (await proc.stderr.read(64))): |
|
|
|
lines = buf.split(b'\n') |
|
|
|
buf = lines[-1] |
|
|
|
for line in lines[:-1]: |
|
|
|