Skip to content

Conversation

@jingangdidi
Copy link
Contributor

@jingangdidi jingangdidi commented Dec 2, 2025

📌 Summary

  1. tail_file.rs: read from the ending of file not beginning.
  2. read.rs: tail_file return the first n lines, not last n lines, newline_positions is already in reverse order.

✨ Changes Made

change beginning to ending in TailFile struct.
change get(line_count - n) to get(n) in tail_file

Copy link
Member

@hashemix hashemix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jingangdidi , thanks for the contribution.

The change in the logic is incorrect, if you revert that change we can merge the other change to the code doc

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an invalid change breaking the functionality of the TailFile.

For instance, if a file has 10 lines, and we want to get tail 2 , we need to return lines , starting from line index 8 , which is (line_count - n) = 10 - 2 = 8

If you run the tests on your branch, you will see the tests that will fail:

cargo test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I know what you mean.

The newline_positions is reversed, so index 8 will get the eighth to last line, this will return line 3 and line 4, not line 9 and line10.

5 is a special number, so it can pass the test_tail_file_normal test, I add a new line.

/// 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.
Copy link
Member

@hashemix hashemix Jan 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid change, thanks 👍

5 is a special number, so it can pass the `test_tail_file_normal` test, I add a new line
Copy link
Member

@hashemix hashemix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks

@hashemix hashemix changed the title fix tail_file.rs: read from the ending not beginning fix: tail_file read from the ending not beginning Jan 2, 2026
@hashemix hashemix merged commit 8656d9f into rust-mcp-stack:main Jan 3, 2026
10 of 12 checks passed
@hashemix hashemix mentioned this pull request Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants