state & vfs: erroring

This commit is contained in:
bitful-pannul 2023-12-18 17:33:26 -03:00
parent 2e9156a9b5
commit 01803cdbfb
2 changed files with 24 additions and 21 deletions

View File

@ -170,7 +170,11 @@ async fn handle_request(
});
};
db.put(key, &payload.bytes)?;
db.put(key, &payload.bytes).map_err(|e| StateError::RocksDBError {
action: "SetState".into(),
error: e.to_string(),
})?;
(serde_json::to_vec(&StateResponse::SetState).unwrap(), None)
}
StateAction::GetState(process_id) => {
@ -643,20 +647,3 @@ fn make_error_message(our_name: String, km: &KernelMessage, error: StateError) -
fn process_to_vec(process: ProcessId) -> Vec<u8> {
process.to_string().as_bytes().to_vec()
}
impl From<std::io::Error> for VfsError {
fn from(err: std::io::Error) -> Self {
VfsError::IOError {
error: err.to_string(),
path: "".to_string(),
} // replace with appropriate VfsError variant and fields
}
}
impl From<rocksdb::Error> for StateError {
fn from(error: rocksdb::Error) -> Self {
StateError::RocksDBError {
action: "ass".into(),
error: error.to_string(),
}
}
}

View File

@ -506,6 +506,9 @@ async fn check_caps(
package_id: PackageId,
vfs_dir_path: String,
) -> Result<(), VfsError> {
let src_package_id =
PackageId::new(source.process.package(), source.process.publisher());
let (send_cap_bool, recv_cap_bool) = tokio::sync::oneshot::channel();
match &request.action {
VfsAction::CreateDir
@ -524,6 +527,9 @@ async fn check_caps(
| VfsAction::Rename(_)
| VfsAction::AddZip
| VfsAction::SetLen(_) => {
if src_package_id == package_id {
return Ok(());
}
send_to_caps_oracle
.send(CapMessage::Has {
on: source.process.clone(),
@ -557,6 +563,9 @@ async fn check_caps(
| VfsAction::Seek(_)
| VfsAction::Hash
| VfsAction::Len => {
if src_package_id == package_id {
return Ok(());
}
send_to_caps_oracle
.send(CapMessage::Has {
on: source.process.clone(),
@ -584,9 +593,6 @@ async fn check_caps(
Ok(())
}
VfsAction::CreateDrive => {
// TODO add helper to types.rs?
let src_package_id =
PackageId::new(source.process.package(), source.process.publisher());
if src_package_id != package_id {
// might have root caps
send_to_caps_oracle
@ -701,6 +707,16 @@ impl From<tokio::sync::mpsc::error::SendError<CapMessage>> for VfsError {
}
}
impl From<std::io::Error> for VfsError {
fn from(err: std::io::Error) -> Self {
VfsError::IOError {
path: "".into(),
error: err.to_string(),
}
}
}
impl std::fmt::Display for VfsAction {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)