You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{letmut f = fs.root_dir().create_file("test.log").await.unwrap();let hello = b"Hello world!";
f.write_all(hello).await.unwrap();
f.flush().await.unwrap();letmut buf = [0u8;12];
f.read_exact(&mut buf[..]).await.unwrap();
log::info!("Read from file: {}", core::str::from_utf8(&buf[..]).unwrap());}
read_exact currently returns UnexpectedEoF, but if you inspect the disk the size has been updated. To read a file you have just written to you have to re open it.
The text was updated successfully, but these errors were encountered:
Hmm, this appears to be more related to the block device adapters, when write_all is finished, the pointer in the file is at the end, so read begins from the end and fails. This is not the case for std impls. It's not clear how successive reads/writes are meant to happen without moving the seeked position... Need to investigate. Not true, turns out the write test weren't running 😅.
What you show is exactly the expected behavior I think.
On every filesystem I've ever tried, there is only one current position for both read and write, and only one seek() function to change the current position. Any read or write operation always move the current position to the end of the data that was read or written.
So after the write_all(), the current position is at the end of the file, and the next read_exact() has nothing to read.
If you add a
f.seek(SeekFrom::Start(0)).await.unwrap();
between the read and write, your example works as intended.
Consider this snippet:
read_exact currently returns UnexpectedEoF, but if you inspect the disk the size has been updated. To read a file you have just written to you have to re open it.
The text was updated successfully, but these errors were encountered: