Merge b3198c04a7 into c896c09c42
This commit is contained in:
commit
6c254b80de
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue