diff --git a/src/fs_service/io/read.rs b/src/fs_service/io/read.rs index 575d5b9..4f33e71 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-1).unwrap_or(&0) + 1 }; // Read forward from start_pos 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, } diff --git a/tests/test_fs_service.rs b/tests/test_fs_service.rs index df67283..f42836c 100644 --- a/tests/test_fs_service.rs +++ b/tests/test_fs_service.rs @@ -1213,13 +1213,13 @@ async fn test_tail_file_normal() { let file_path = create_test_file_with_line_ending( &temp_dir.to_path_buf(), "dir1/test.txt", - vec!["line1", "line2", "line3", "line4", "line5"], + vec!["line1", "line2", "line3", "line4", "line5", "line6"], "\n", ) .await; let result = service.tail_file(&file_path, 3).await.unwrap(); - assert_eq!(result, "line3\nline4\nline5"); // No trailing newline + assert_eq!(result, "line4\nline5\nline6"); // No trailing newline } #[tokio::test]