Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kinode/packages/app_store/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ alloy-primitives = "0.7.6"
alloy-sol-types = "0.7.6"
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", branch = "develop" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.9.0" }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/app_store/downloads/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ simulation-mode = []

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", branch = "develop" }
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"
Expand Down
35 changes: 7 additions & 28 deletions kinode/packages/app_store/downloads/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -74,8 +74,9 @@ 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();

Expand Down Expand Up @@ -291,7 +292,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);
Expand Down Expand Up @@ -439,7 +440,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 {
Expand Down Expand Up @@ -519,7 +520,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"));
Expand All @@ -540,28 +541,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, true, None) {
Ok(dir) => Ok(dir),
Err(_) => match vfs::open_dir(path, false, 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};
Expand Down
2 changes: 1 addition & 1 deletion kinode/packages/app_store/ft_worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", tag = "v0.9.0" }
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"
Expand Down
Loading