New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
./rust code update and ./dss/raft description update #301
Conversation
Because TempDir will delete the folder when it is in Drop.
If the file written in append mode is not an empty file, the return value of `seek(SeekFrom::Current(0))` is not the current write position but the beginning of the file before executing a `write`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
PTAL @sticnarf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! But I think when creating BufWriterWithPos
and BufReaderWithPos
, it shoudn't have extra semantics about where its cursor should be. SeekFrom::Current(0)
is just to update the internal pos to be the same as the actual one.
The rest LGTM.
I agree. So can I think that the return value of |
Why? The return value of |
use std::fs;
use std::io::{BufWriter, Seek, SeekFrom, Write};
fn main() {
let fs = fs::OpenOptions::new()
.write(true)
.append(true)
.open("./temp")
.unwrap(); // Non-empty file, assuming 5 bytes
let mut buf = BufWriter::new(fs);
let pos1 = buf.seek(SeekFrom::Current(0)).unwrap();
let slice = vec![126];
buf.write(&slice).unwrap();
buf.flush().unwrap();
let pos2 = buf.seek(SeekFrom::Current(0)).unwrap();
println!("first pos: {}, next pos: {}.", pos1, pos2);
// output: first pos: 0, next pos: 6.
} In the implementation of my homework, I specified it externally. I set impl<W: Write> BufWriterWithPos<W> {
pub fn new(inner: W, pos: u64) -> Self {
Self {
writer: BufWriter::new(inner),
pos,
}
}
} |
@HunDunDM I see. It's just implementation related. The reference implementation doesn't write to an existing file with content, so the position is always right. If I need to append to an existing file with content, I should seek manually to the end of the file then the position is correct. I think it's incorrect to seek to the end when initializing |
@sticnarf You are right, it should be sought to the end before I rolled back the relevant code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
BufReaderWithPos
and.BufWriterWithPos
Temp_dir
is dropped during the test.