vfs: use sha256, remove blake3 dep

This commit is contained in:
dr-frmr 2024-06-11 22:00:43 -06:00
parent 926e5744f7
commit dac4a2e526
No known key found for this signature in database
3 changed files with 15 additions and 35 deletions

20
Cargo.lock generated
View File

@ -883,12 +883,6 @@ dependencies = [
"rand 0.8.5",
]
[[package]]
name = "arrayref"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
[[package]]
name = "arrayvec"
version = "0.7.4"
@ -1093,19 +1087,6 @@ dependencies = [
"digest 0.10.7",
]
[[package]]
name = "blake3"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52"
dependencies = [
"arrayref",
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq 0.3.0",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
@ -3190,7 +3171,6 @@ dependencies = [
"async-trait",
"base64 0.22.0",
"bincode",
"blake3",
"bytes",
"chacha20poly1305",
"chrono",

View File

@ -48,7 +48,6 @@ anyhow = "1.0.71"
async-trait = "0.1.71"
base64 = "0.22.0"
bincode = "1.3.3"
blake3 = "1.4.1"
bytes = "1.4.0"
chacha20poly1305 = "0.10.1"
chrono = "0.4.31"

View File

@ -69,7 +69,7 @@ pub async fn vfs(
if let Err(e) = handle_request(
&our_node,
km,
open_files.clone(),
open_files,
&send_to_loop,
&send_to_terminal,
&send_to_caps_oracle,
@ -230,13 +230,13 @@ async fn handle_request(
VfsAction::CreateFile => {
// create truncates any file that might've existed before
open_files.remove(&path);
let _file = open_file(open_files.clone(), path, true, true).await?;
let _file = open_file(open_files, path, true, true).await?;
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
}
VfsAction::OpenFile { create } => {
// open file opens an existing file, or creates a new one if create is true
let file = open_file(open_files.clone(), path, create, false).await?;
let file = open_file(open_files, path, create, false).await?;
let mut file = file.lock().await;
// extra in the case file was just created, todo refactor out.
file.seek(SeekFrom::Start(0)).await?;
@ -255,7 +255,7 @@ async fn handle_request(
error: "blob needs to exist for WriteAll".into(),
});
};
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let mut file = file.lock().await;
file.write_all(&blob.bytes).await?;
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
@ -275,7 +275,7 @@ async fn handle_request(
error: "blob needs to exist for Append".into(),
});
};
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let mut file = file.lock().await;
file.seek(SeekFrom::End(0)).await?;
file.write_all(&blob.bytes).await?;
@ -283,7 +283,7 @@ async fn handle_request(
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
}
VfsAction::SyncAll => {
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let file = file.lock().await;
file.sync_all().await?;
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
@ -297,7 +297,7 @@ async fn handle_request(
)
}
VfsAction::ReadToEnd => {
let file = open_file(open_files.clone(), path.clone(), false, false).await?;
let file = open_file(open_files, path.clone(), false, false).await?;
let mut file = file.lock().await;
let mut contents = Vec::new();
@ -309,7 +309,7 @@ async fn handle_request(
)
}
VfsAction::ReadExact(length) => {
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let mut file = file.lock().await;
let mut contents = vec![0; length as usize];
file.read_exact(&mut contents).await?;
@ -339,7 +339,7 @@ async fn handle_request(
)
}
VfsAction::ReadToString => {
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let mut file = file.lock().await;
let mut contents = String::new();
file.read_to_string(&mut contents).await?;
@ -349,7 +349,7 @@ async fn handle_request(
)
}
VfsAction::Seek { seek_from } => {
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let mut file = file.lock().await;
// same type, rust tingz
let seek_from = match seek_from {
@ -401,22 +401,23 @@ async fn handle_request(
)
}
VfsAction::Len => {
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let file = file.lock().await;
let len = file.metadata().await?.len();
(serde_json::to_vec(&VfsResponse::Len(len)).unwrap(), None)
}
VfsAction::SetLen(len) => {
let file = open_file(open_files.clone(), path, false, false).await?;
let file = open_file(open_files, path, false, false).await?;
let file = file.lock().await;
file.set_len(len).await?;
(serde_json::to_vec(&VfsResponse::Ok).unwrap(), None)
}
VfsAction::Hash => {
let file = open_file(open_files.clone(), path, false, false).await?;
use sha2::{Digest, Sha256};
let file = open_file(open_files, path, false, false).await?;
let mut file = file.lock().await;
file.seek(SeekFrom::Start(0)).await?;
let mut hasher = blake3::Hasher::new();
let mut hasher = Sha256::new();
let mut buffer = [0; 1024];
loop {
let bytes_read = file.read(&mut buffer).await?;