mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-23 03:44:04 +03:00
app_store: use new fixed vfs processlib
This commit is contained in:
parent
24ee4376d5
commit
b7dd971646
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -2609,7 +2609,7 @@ version = "0.2.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"kinode_process_lib 0.9.0",
|
||||
"kinode_process_lib 0.9.1",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@ -3636,7 +3636,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "kinode_process_lib"
|
||||
version = "0.9.1"
|
||||
source = "git+https://github.com/kinode-dao/process_lib?rev=631d346#631d346ccf879b854ebc9b47f4c2cd71cf2f1771"
|
||||
source = "git+https://github.com/kinode-dao/process_lib?rev=1c495ad#1c495ad8687dd580aa2aa2222f8e7958679220a6"
|
||||
dependencies = [
|
||||
"alloy 0.1.4",
|
||||
"alloy-primitives",
|
||||
|
@ -8,7 +8,7 @@ simulation-mode = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "631d346" }
|
||||
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "1c495ad" }
|
||||
rand = "0.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -14,7 +14,7 @@ use kinode_process_lib::{
|
||||
await_message, call_init, get_blob, get_state,
|
||||
http::client,
|
||||
print_to_terminal, println, set_state,
|
||||
vfs::{self, Directory, File},
|
||||
vfs::{self, Directory},
|
||||
Address, Message, PackageId, ProcessId, Request, Response,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -74,8 +74,8 @@ fn init(our: Address) {
|
||||
.expect("could not create /downloads drive");
|
||||
|
||||
let mut downloads =
|
||||
open_or_create_dir("/app_store:sys/downloads").expect("could not open downloads");
|
||||
let mut tmp = open_or_create_dir("/app_store:sys/downloads/tmp").expect("could not open tmp");
|
||||
vfs::open_dir("/app_store:sys/downloads", true, None).expect("could not open downloads");
|
||||
let mut tmp = vfs::open_dir("/app_store:sys/downloads/tmp", true, None).expect("could not open tmp");
|
||||
|
||||
let mut auto_updates: HashSet<(PackageId, String)> = HashSet::new();
|
||||
|
||||
@ -291,7 +291,7 @@ fn handle_message(
|
||||
downloads.path,
|
||||
add_req.package_id.clone().to_process_lib().to_string()
|
||||
);
|
||||
let _ = open_or_create_dir(&package_dir)?;
|
||||
let _ = vfs::open_dir(&package_dir, true, None)?;
|
||||
|
||||
// Write the zip file
|
||||
let zip_path = format!("{}/{}.zip", package_dir, add_req.version_hash);
|
||||
@ -439,7 +439,7 @@ fn handle_receive_http_download(
|
||||
let bytes = get_blob().ok_or(DownloadError::BlobNotFound)?.bytes;
|
||||
|
||||
let package_dir = format!("{}/{}", "/app_store:sys/downloads", package_id.to_string());
|
||||
let _ = open_or_create_dir(&package_dir).map_err(|_| DownloadError::VfsError)?;
|
||||
let _ = vfs::open_dir(&package_dir, true, None).map_err(|_| DownloadError::VfsError)?;
|
||||
|
||||
let calculated_hash = format!("{:x}", Sha256::digest(&bytes));
|
||||
if calculated_hash != version_hash {
|
||||
@ -519,7 +519,7 @@ fn extract_and_write_manifest(file_contents: &[u8], manifest_path: &str) -> anyh
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
|
||||
let manifest_file = open_or_create_file(&manifest_path)?;
|
||||
let manifest_file = vfs::open_file(&manifest_path, true, None)?;
|
||||
manifest_file.write(contents.as_bytes())?;
|
||||
|
||||
print_to_terminal(1, &format!("Extracted and wrote manifest.json"));
|
||||
@ -540,28 +540,6 @@ fn get_manifest_hash(package_id: PackageId, version_hash: String) -> anyhow::Res
|
||||
Ok(manifest_hash)
|
||||
}
|
||||
|
||||
/// helper function for vfs files, open if exists, if not create
|
||||
fn open_or_create_file(path: &str) -> anyhow::Result<File> {
|
||||
match vfs::open_file(path, false, None) {
|
||||
Ok(file) => Ok(file),
|
||||
Err(_) => match vfs::open_file(path, true, None) {
|
||||
Ok(file) => Ok(file),
|
||||
Err(_) => Err(anyhow::anyhow!("could not create file")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// helper function for vfs directories, open if exists, if not create
|
||||
fn open_or_create_dir(path: &str) -> anyhow::Result<Directory> {
|
||||
match vfs::open_dir(path, false, None) {
|
||||
Ok(dir) => Ok(dir),
|
||||
Err(_) => match vfs::open_dir(path, true, None) {
|
||||
Ok(dir) => Ok(dir),
|
||||
Err(_) => Err(anyhow::anyhow!("could not create dir")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// generate a Keccak-256 hash string (with 0x prefix) of the metadata bytes
|
||||
pub fn keccak_256_hash(bytes: &[u8]) -> String {
|
||||
use sha3::{Digest, Keccak256};
|
||||
|
@ -9,7 +9,7 @@ simulation-mode = []
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
bincode = "1.3.3"
|
||||
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "631d346" }
|
||||
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "1c495ad" }
|
||||
rand = "0.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
@ -5,7 +5,7 @@ use crate::kinode::process::downloads::{
|
||||
use kinode_process_lib::*;
|
||||
use kinode_process_lib::{
|
||||
print_to_terminal, println, timer,
|
||||
vfs::{open_dir, open_file, Directory, File, SeekFrom},
|
||||
vfs::{File, SeekFrom},
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::io::Read;
|
||||
@ -102,7 +102,7 @@ fn handle_sender(worker: &str, package_id: &PackageId, version_hash: &str) -> an
|
||||
package_id.package_name, package_id.publisher_node, version_hash
|
||||
);
|
||||
|
||||
let mut file = open_file(&filename, false, None)?;
|
||||
let mut file = vfs::open_file(&filename, false, None)?;
|
||||
let size = file.metadata()?.len;
|
||||
let num_chunks = (size as f64 / CHUNK_SIZE as f64).ceil() as u64;
|
||||
|
||||
@ -129,15 +129,15 @@ fn handle_receiver(
|
||||
) -> anyhow::Result<()> {
|
||||
// TODO: write to a temporary location first, then check hash as we go, then rename to final location.
|
||||
|
||||
let package_dir = open_or_create_dir(&format!(
|
||||
let package_dir = vfs::open_dir(&format!(
|
||||
"/app_store:sys/downloads/{}:{}/",
|
||||
package_id.package_name,
|
||||
package_id.publisher(),
|
||||
))?;
|
||||
), true, None)?;
|
||||
|
||||
let timer_address = Address::from_str("our@timer:distro:sys")?;
|
||||
|
||||
let mut file = open_or_create_file(&format!("{}{}.zip", &package_dir.path, version_hash))?;
|
||||
let mut file = vfs::open_file(&format!("{}{}.zip", &package_dir.path, version_hash), true, None)?;
|
||||
let mut size: Option<u64> = None;
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
@ -289,7 +289,7 @@ fn extract_and_write_manifest(file_contents: &[u8], manifest_path: &str) -> anyh
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
|
||||
let manifest_file = open_or_create_file(&manifest_path)?;
|
||||
let manifest_file = vfs::open_file(&manifest_path, true, None)?;
|
||||
manifest_file.write(contents.as_bytes())?;
|
||||
|
||||
print_to_terminal(1, "Extracted and wrote manifest.json");
|
||||
@ -300,28 +300,6 @@ fn extract_and_write_manifest(file_contents: &[u8], manifest_path: &str) -> anyh
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// helper function for vfs files, open if exists, if not create
|
||||
fn open_or_create_file(path: &str) -> anyhow::Result<File> {
|
||||
match open_file(path, false, None) {
|
||||
Ok(file) => Ok(file),
|
||||
Err(_) => match open_file(path, true, None) {
|
||||
Ok(file) => Ok(file),
|
||||
Err(_) => Err(anyhow::anyhow!("could not create file")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// helper function for vfs directories, open if exists, if not create
|
||||
fn open_or_create_dir(path: &str) -> anyhow::Result<Directory> {
|
||||
match vfs::open_dir(path, false, None) {
|
||||
Ok(dir) => Ok(dir),
|
||||
Err(_) => match vfs::open_dir(path, true, None) {
|
||||
Ok(dir) => Ok(dir),
|
||||
Err(_) => Err(anyhow::anyhow!("could not create dir")),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::kinode::process::main::PackageId {
|
||||
pub fn to_process_lib(&self) -> kinode_process_lib::PackageId {
|
||||
kinode_process_lib::PackageId::new(&self.package_name, &self.publisher_node)
|
||||
|
Loading…
Reference in New Issue
Block a user