This commit is contained in:
Alan 2026-08-14 08:39:33 -05:00 committed by GitHub
commit 6c254b80de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -1484,6 +1484,16 @@ class ShellFileOperations(FileOperations):
total_lines = int(wc_output.strip())
except ValueError:
total_lines = 0
# wc -l counts newline characters, not lines. A file without a trailing
# newline has one more line of content than wc -l reports. Detect this
# by checking if the last byte of the file is 0a (\n).
if file_size > 0:
tail_cmd = f"tail -c 1 {self._escape_shell_arg(path)} | od -An -tx1 | tr -d ' '"
tail_result = self._exec(tail_cmd)
last_byte = tail_result.stdout.strip()
if last_byte and last_byte != "0a":
total_lines += 1
# Check if truncated
truncated = total_lines > end_line