Skip to content

Commit

Permalink
Fix crashes when run with littlefs assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jun 23, 2023
1 parent ec304b8 commit 8eb6b4e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,11 +1287,15 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> {
pub fn write_chunk(&self, path: &Path, contents: &[u8], pos: OpenSeekFrom) -> Result<()> {
#[cfg(test)]
println!("writing {:?}", path);
File::open_and_then(self, path, |file| {
use io::Write;
file.seek(pos.into())?;
file.write_all(contents)
})?;
OpenOptions::new()
.read(true)
.write(true)
.truncate(false)
.open_and_then(self, path, |file| {
use io::Write;
file.seek(pos.into())?;
file.write_all(contents)
})?;
Ok(())
}
}
Expand Down Expand Up @@ -1540,11 +1544,11 @@ mod tests {
})?;

let mut a1 = File::allocate();
let f1 = unsafe { File::open(fs, &mut a1, b"a.txt\0".try_into().unwrap())? };
let f1 = unsafe { File::create(fs, &mut a1, b"a.txt\0".try_into().unwrap())? };
f1.write(b"some text")?;

let mut a2 = File::allocate();
let f2 = unsafe { File::open(fs, &mut a2, b"b.txt\0".try_into().unwrap())? };
let f2 = unsafe { File::create(fs, &mut a2, b"b.txt\0".try_into().unwrap())? };
f2.write(b"more text")?;

unsafe { f1.close()? }; // program hangs here
Expand Down

0 comments on commit 8eb6b4e

Please sign in to comment.