Update to flushing streaming api

This commit is contained in:
Sosthène Guédon
2023-04-13 10:19:00 +02:00
parent bcb4b2ee79
commit e5fd7dfb9a
2 changed files with 29 additions and 7 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ log-warn = []
log-error = []
[patch.crates-io]
trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "25ae084251b76bacfa8919eb8"}
trussed = { git = "https://github.com/sosthene-nitrokey/trussed", rev = "3eeda2a21106cb31120e08f5ae67a490b3d47bd6" }
trussed-auth = { git = "https://github.com/trussed-dev/trussed-auth", tag = "v0.2.1"}
littlefs2 = { git = "https://github.com/Nitrokey/littlefs2", tag = "v0.3.2-nitrokey-2" }
+28 -6
View File
@@ -773,8 +773,8 @@ impl ContainerStorage {
}
}
pub fn save(
self,
fn save_inner(
&self,
client: &mut impl trussed::Client,
bytes: &[u8],
storage: Location,
@@ -789,10 +789,12 @@ impl ContainerStorage {
});
msg = chunks.next().unwrap_or_default();
let mut written = msg.len();
try_syscall!(client.write_file(storage, self.path(), msg, None)).map_err(|_err| {
error!("Failed to store data: {_err:?}");
Status::UnspecifiedNonpersistentExecutionError
})?;
try_syscall!(client.start_chunked_write(storage, self.path(), msg, None)).map_err(
|_err| {
error!("Failed to store data: {_err:?}");
Status::UnspecifiedNonpersistentExecutionError
},
)?;
for chunk in chunks {
let off = written;
written += chunk.len();
@@ -809,4 +811,24 @@ impl ContainerStorage {
}
Ok(())
}
pub fn save(
self,
client: &mut impl trussed::Client,
bytes: &[u8],
storage: Location,
) -> Result<(), Status> {
let res = self.save_inner(client, bytes, storage);
if res.is_ok() {
try_syscall!(client.flush_chunks(storage, self.path()))
.map(drop)
.map_err(|_err| {
error!("Failed to flush data: {_err:?}");
Status::UnspecifiedNonpersistentExecutionError
})
} else {
syscall!(client.abort_chunked_write(storage, self.path()));
res
}
}
}