From 7cacb3c303eb857d3d0572a8c69570116d848d55 Mon Sep 17 00:00:00 2001 From: Song <35002409+jingangdidi@users.noreply.github.com> Date: Tue, 2 Dec 2025 16:02:37 +0800 Subject: [PATCH 1/2] Update tail_file.rs: read from the ending not beginning --- src/tools/tail_file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tail_file.rs b/src/tools/tail_file.rs index bc40e55..f5816d7 100644 --- a/src/tools/tail_file.rs +++ b/src/tools/tail_file.rs @@ -24,7 +24,7 @@ use crate::fs_service::FileSystemService; pub struct TailFile { /// The path of the file to get information for. pub path: String, - /// The number of lines to read from the beginning of the file. + /// The number of lines to read from the ending of the file. pub lines: u64, } From 80aee1963c47c9b6b5c327ab15762c1a11e551e5 Mon Sep 17 00:00:00 2001 From: Song <35002409+jingangdidi@users.noreply.github.com> Date: Tue, 2 Dec 2025 17:06:35 +0800 Subject: [PATCH 2/2] fix: `tail_file` return the first n lines, not last n lines `newline_positions` is already in reverse order --- src/fs_service/io/read.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fs_service/io/read.rs b/src/fs_service/io/read.rs index 575d5b9..45616e2 100644 --- a/src/fs_service/io/read.rs +++ b/src/fs_service/io/read.rs @@ -116,7 +116,7 @@ impl FileSystemService { let start_pos = if line_count <= n { 0 // Read from start if fewer than n lines } else { - *newline_positions.get(line_count - n).unwrap_or(&0) + 1 + *newline_positions.get(n).unwrap_or(&0) + 1 }; // Read forward from start_pos