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();

View File

@ -41,10 +41,10 @@ pub struct IDStore<T: Persistence> {
impl<T: Persistence> IDStore<T> {
pub async fn new_from_storage(mut persistence_layer: T) -> Self {
let mapping = match persistence_layer.load_mapping().await {
Some(map) => map,
None => IDMapping::new(),
};
// let mapping = match persistence_layer.load_mapping().await {
// Some(map) => map,
// None => IDMapping::new(),
// };
let current_date: Date = 1;
@ -55,7 +55,7 @@ impl<T: Persistence> IDStore<T> {
Self {
current_day: day,
mapping,
mapping: IDMapping::new(),
persistence_layer,
}
}