Merge branch 'main' into jf/invite

This commit is contained in:
realisation 2023-10-23 11:17:19 -04:00
commit 283c900a76
5 changed files with 67 additions and 45 deletions

View File

@ -288,7 +288,7 @@ impl Guest for Component {
print_to_terminal(1, "chess: parsed ipc JSON");
if source.process.to_string() == "chess:sys:uqbar" {
if source.process.to_string() == "chess:chess:uqbar" {
let action = message_json["action"].as_str().unwrap_or("");
let game_id = source.node.clone();
@ -567,7 +567,7 @@ impl Guest for Component {
let response = send_and_await_response(
&Address {
node: game_id.clone(),
process: ProcessId::from_str("chess:sys:uqbar")
process: ProcessId::from_str("chess:chess:uqbar")
.unwrap(),
},
&Request {
@ -720,7 +720,7 @@ impl Guest for Component {
&Address {
node: game_id.clone(),
process: ProcessId::from_str(
"chess:sys:uqbar",
"chess:chess:uqbar",
)
.unwrap(),
},
@ -871,7 +871,7 @@ impl Guest for Component {
let response = send_and_await_response(
&Address {
node: game_id.clone(),
process: ProcessId::from_str("chess:sys:uqbar")
process: ProcessId::from_str("chess:chess:uqbar")
.unwrap(),
},
&Request {

View File

@ -518,6 +518,7 @@ impl Manifest {
let cipher = &self.cipher;
let mut data = Vec::new();
let mut total_bytes_read = 0;
// filter chunks based on start and length if they are defined
let filtered_chunks = if let (Some(start), Some(length)) = (start, length) {
@ -619,10 +620,11 @@ impl Manifest {
}
}
if let Some(length) = length {
let end = start.unwrap_or(0) + length;
if end < start_chunk + len {
chunk_data.truncate((end - start_chunk) as usize);
let remaining_length = length.saturating_sub(total_bytes_read);
if remaining_length < chunk_data.len() as u64 {
chunk_data.truncate(remaining_length as usize);
}
total_bytes_read += chunk_data.len() as u64;
}
data.append(&mut chunk_data);
@ -643,6 +645,7 @@ impl Manifest {
let cipher = &self.cipher;
let mut data = Vec::new();
let mut total_bytes_read = 0;
// filter chunks based on start and length if they are defined
let filtered_chunks = if let (Some(start), Some(length)) = (start, length) {
@ -745,10 +748,11 @@ impl Manifest {
}
}
if let Some(length) = length {
let end = start.unwrap_or(0) + length;
if end < start_chunk + len {
chunk_data.truncate((end - start_chunk) as usize);
let remaining_length = length.saturating_sub(total_bytes_read);
if remaining_length < chunk_data.len() as u64 {
chunk_data.truncate(remaining_length as usize);
}
total_bytes_read += chunk_data.len() as u64;
}
data.append(&mut chunk_data);

View File

@ -535,15 +535,17 @@ async fn handle_request(
// println!("got action! {:?}", action);
let (ipc, bytes) = match action {
FsAction::Write => {
FsAction::Write(maybe_file_id) => {
let Some(ref payload) = payload else {
return Err(FsError::BadBytes {
action: "Write".into(),
});
};
// println!("fs: got write from {:?} with len {:?}", source.process, &payload.bytes.len());
let file_uuid = match maybe_file_id {
Some(id) => FileIdentifier::UUID(id),
None => FileIdentifier::new_uuid(),
};
let file_uuid = FileIdentifier::new_uuid();
match manifest.write(&file_uuid, &payload.bytes).await {
Ok(_) => (),
Err(e) => {
@ -606,26 +608,6 @@ async fn handle_request(
Ok(bytes) => (FsResponse::Read(req.file), Some(bytes)),
}
}
FsAction::Replace(old_file_uuid) => {
let Some(ref payload) = payload else {
return Err(FsError::BadBytes {
action: "Write".into(),
});
};
let file = FileIdentifier::UUID(old_file_uuid);
match manifest.write(&file, &payload.bytes).await {
Ok(_) => (),
Err(e) => {
return Err(FsError::WriteFailed {
file: old_file_uuid,
error: format!("replace error: {}", e),
})
}
}
(FsResponse::Write(old_file_uuid), None)
}
FsAction::Delete(del) => {
let file = FileIdentifier::UUID(del);
manifest.delete(&file).await?;

View File

@ -447,8 +447,7 @@ pub struct PackageManifestEntry {
#[derive(Serialize, Deserialize, Debug)]
pub enum FsAction {
Write,
Replace(u128),
Write(Option<u128>),
WriteOffset((u128, u64)),
Append(Option<u128>),
Read(u128),

View File

@ -782,9 +782,11 @@ async fn match_request(
panic!("empty path");
};
{
let hash = {
let mut vfs = vfs.lock().await;
if vfs.path_to_key.contains_key(&full_path) {
if !vfs.path_to_key.contains_key(&full_path) {
None
} else {
send_to_terminal
.send(Printout {
verbosity: 1,
@ -792,12 +794,18 @@ async fn match_request(
})
.await
.unwrap();
let Some(old_key) = vfs.path_to_key.remove(&full_path) else {
panic!("");
};
vfs.key_to_entry.remove(&old_key);
};
}
match vfs.path_to_key.remove(&full_path) {
None => None,
Some(key) => {
let Key::File { id: hash } = key else {
panic!("");
};
Some(hash)
}
}
// vfs.key_to_entry.remove(&old_key);
}
};
let _ = send_to_loop
.send(KernelMessage {
@ -814,7 +822,7 @@ async fn match_request(
message: Message::Request(Request {
inherit: true,
expects_response: Some(5), // TODO evaluate
ipc: Some(serde_json::to_string(&FsAction::Write).unwrap()),
ipc: Some(serde_json::to_string(&FsAction::Write(hash)).unwrap()),
metadata: None,
}),
payload,
@ -826,6 +834,7 @@ async fn match_request(
let Message::Response((Response { ipc, .. }, None)) = message else {
panic!("");
};
let Some(ipc) = ipc else {
panic!("");
};
@ -840,9 +849,11 @@ async fn match_request(
let Some(parent_key) = vfs.path_to_key.remove(&parent_path) else {
panic!("");
};
let Some(mut parent_entry) = vfs.key_to_entry.remove(&parent_key) else {
panic!("");
};
let EntryType::Dir {
children: ref mut parent_children,
..
@ -961,6 +972,30 @@ async fn match_request(
(is_file, is_dir, full_path, file_contents)
};
if is_file {
let hash = {
let vfs = vfs.lock().await;
if !vfs.path_to_key.contains_key(&full_path) {
None
} else {
send_to_terminal
.send(Printout {
verbosity: 1,
content: format!("vfs: overwriting file {}", full_path),
})
.await
.unwrap();
match vfs.path_to_key.get(&full_path) {
None => None,
Some(key) => {
let Key::File { id: hash } = key else {
panic!("");
};
Some(*hash)
}
}
// vfs.key_to_entry.remove(&old_key);
}
};
let _ = send_to_loop
.send(KernelMessage {
id,
@ -976,7 +1011,9 @@ async fn match_request(
message: Message::Request(Request {
inherit: true,
expects_response: Some(5), // TODO evaluate
ipc: Some(serde_json::to_string(&FsAction::Write).unwrap()),
ipc: Some(
serde_json::to_string(&FsAction::Write(hash)).unwrap(),
),
metadata: None,
}),
payload: Some(Payload {