Iteration stops on an empty file
szszszsz opened this issue · 2 comments
szszszsz commented
Iterating over files can stop prematurally, when an empty (0-sized) file is encountered.
Perhaps the sys package misses that case, or interprets it wrongly.
Littlefs read call:
trussed/src/store/filestore.rs
Lines 368 to 379 in 8e347ab
robin-nitrokey commented
Can you share some example code? I cannot reproduce the issue with this minimal test:
#![cfg(feature = "virt")]
use heapless_bytes::Bytes;
use trussed::{client::FilesystemClient, types::{Location, PathBuf}, syscall};
mod client;
#[test]
fn iterate_empty_file() {
client::get(|client| {
let l = Location::Internal;
let n = 100;
for i in 0..n {
let path = PathBuf::from(format!("test{i}").as_str());
let data = if i % 2 == 0 {
Bytes::new()
} else {
Bytes::from_slice(&[0xde, 0xad, 0xbe, 0xef]).unwrap()
};
syscall!(client.write_file(l, path, data, None));
}
let mut msg = syscall!(client.read_dir_files_first(l, PathBuf::new(), None)).data;
let mut count = 0;
while msg.is_some() {
count += 1;
msg = syscall!(client.read_dir_files_next()).data;
}
assert_eq!(count, n);
})
}
robin-nitrokey commented
Please re-open if you can reproduce the problem.