new file will be created when sd card is empty

This commit is contained in:
Philipp_EndevourOS
2025-10-01 18:58:08 +02:00
parent c91f290c31
commit db7e22f45d
2 changed files with 13 additions and 10 deletions

View File

@@ -42,13 +42,16 @@ impl Persistence for SDCardPersistence {
async fn load_day(&mut self, day: crate::store::Date) -> Option<AttendanceDay> {
let mut vol_0 = self.vol_mgr.open_volume(VolumeIdx(0)).unwrap();
let mut root_dir = vol_0.open_root_dir().unwrap();
let mut file = root_dir
.open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly)
.unwrap();
let mut file = root_dir.open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly);
if let Err(e) = file {
return None;
}
let mut open_file = file.unwrap();
let mut read_buffer: [u8; 1024] = [0; 1024];
let read = file.read(&mut read_buffer).unwrap();
file.close().unwrap();
let read = open_file.read(&mut read_buffer).unwrap();
open_file.close().unwrap();
let day: AttendanceDay = serde_json::from_slice(&read_buffer[..read]).unwrap();