mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-11 09:55:24 +03:00
Merge branch 'develop' into wg/app-store-http
This commit is contained in:
commit
f488d88ae3
205
modules/terminal/m/Cargo.lock
generated
205
modules/terminal/m/Cargo.lock
generated
@ -2,6 +2,63 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.79"
|
||||
@ -35,6 +92,39 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
@ -166,12 +256,20 @@ name = "m"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"kinode_process_lib",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
@ -248,6 +346,35 @@ dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.16"
|
||||
@ -306,6 +433,12 @@ dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.48"
|
||||
@ -405,6 +538,12 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
@ -472,6 +611,72 @@ dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.16.0"
|
||||
|
@ -10,7 +10,9 @@ lto = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
clap = "4.4.18"
|
||||
kinode_process_lib = { git = "https://github.com/uqbar-dao/process_lib.git", rev = "329c7a8" }
|
||||
regex = "1.10.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
|
||||
|
@ -1,4 +1,6 @@
|
||||
use clap::{Arg, Command};
|
||||
use kinode_process_lib::{await_next_request_body, call_init, println, Address, Request};
|
||||
use regex::Regex;
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "../../../wit",
|
||||
@ -11,32 +13,75 @@ wit_bindgen::generate!({
|
||||
call_init!(init);
|
||||
|
||||
fn init(_our: Address) {
|
||||
let Ok(args) = await_next_request_body() else {
|
||||
let Ok(body) = await_next_request_body() else {
|
||||
println!("m: failed to get args, aborting");
|
||||
return;
|
||||
};
|
||||
let body_string = String::from_utf8(body).unwrap();
|
||||
|
||||
let tail = String::from_utf8(args).unwrap();
|
||||
|
||||
let (target, body) = match tail.split_once(" ") {
|
||||
Some((a, p)) => (a, p),
|
||||
None => {
|
||||
println!("m: invalid command, please provide an address and json message");
|
||||
return;
|
||||
let re = Regex::new(r#"'[^']*'|\S+"#).unwrap();
|
||||
let mut args: Vec<String> = re
|
||||
.find_iter(body_string.as_str())
|
||||
.map(|mat| {
|
||||
let match_str = mat.as_str();
|
||||
// Remove the surrounding single quotes for the JSON string
|
||||
if match_str.starts_with('\'') && match_str.ends_with('\'') {
|
||||
match_str[1..match_str.len() - 1].to_string()
|
||||
} else {
|
||||
match_str.to_string()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
args.insert(0, "m".to_string());
|
||||
|
||||
let Ok(parsed) = Command::new("m")
|
||||
.disable_help_flag(true)
|
||||
.arg(Arg::new("target").index(1).required(true))
|
||||
.arg(Arg::new("body").index(2).required(true))
|
||||
.arg(
|
||||
Arg::new("await")
|
||||
.short('a')
|
||||
.long("await")
|
||||
.value_parser(clap::value_parser!(u64)),
|
||||
)
|
||||
.try_get_matches_from(args)
|
||||
else {
|
||||
println!("m: failed to parse args");
|
||||
return;
|
||||
};
|
||||
// TODO aliasing logic...maybe we can read from terminal state since we have root?
|
||||
let target = match target.parse::<Address>() {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
|
||||
let Some(target) = parsed.get_one::<String>("target") else {
|
||||
println!("m: no target");
|
||||
return;
|
||||
};
|
||||
|
||||
let Ok(target) = target.parse::<Address>() else {
|
||||
println!("invalid address: \"{target}\"");
|
||||
return;
|
||||
} // match state.aliases.get(target) {
|
||||
// Some(pid) => Address::new("our", pid.clone()),
|
||||
// None => {
|
||||
// return Err(anyhow!("invalid address: \"{target}\""));
|
||||
// }
|
||||
// },
|
||||
};
|
||||
let _ = Request::new().target(target).body(body).send().unwrap();
|
||||
|
||||
let Some(body) = parsed.get_one::<String>("body") else {
|
||||
println!("m: no body");
|
||||
return;
|
||||
};
|
||||
|
||||
let req = Request::new().target(target).body(body.as_bytes().to_vec());
|
||||
|
||||
match parsed.get_one::<u64>("await") {
|
||||
Some(s) => {
|
||||
println!("m: awaiting response for {}s", s);
|
||||
match req.send_and_await_response(*s).unwrap() {
|
||||
Ok(res) => {
|
||||
println!("m: {:?}", res);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("m: SendError: {:?}", e.kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let _ = req.send().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use tokio::fs;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::types::*;
|
||||
@ -421,6 +422,12 @@ async fn bootstrap(
|
||||
|
||||
let drive_path = format!("/{}/pkg", &our_drive_name);
|
||||
|
||||
// save the zip itself inside pkg folder, for sharing with others
|
||||
let mut zip_file =
|
||||
fs::File::create(format!("{}/{}.zip", &pkg_path, &our_drive_name)).await?;
|
||||
let package_zip_bytes = package.clone().into_inner().into_inner();
|
||||
zip_file.write_all(package_zip_bytes).await?;
|
||||
|
||||
// for each file in package.zip, write to vfs folder
|
||||
for i in 0..package.len() {
|
||||
let mut file = match package.by_index(i) {
|
||||
|
@ -1118,7 +1118,7 @@ pub struct VfsRequest {
|
||||
pub action: VfsAction,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum VfsAction {
|
||||
CreateDrive,
|
||||
CreateDir,
|
||||
@ -1148,7 +1148,7 @@ pub enum VfsAction {
|
||||
Hash,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum SeekFrom {
|
||||
Start(u64),
|
||||
End(i64),
|
||||
|
68
src/vfs.rs
68
src/vfs.rs
@ -122,6 +122,74 @@ async fn handle_request(
|
||||
}
|
||||
};
|
||||
|
||||
// special case for root reading list of all drives.
|
||||
if request.action == VfsAction::ReadDir && request.path == "/" {
|
||||
// check if src has root
|
||||
let (send_cap_bool, recv_cap_bool) = tokio::sync::oneshot::channel();
|
||||
send_to_caps_oracle
|
||||
.send(CapMessage::Has {
|
||||
on: source.process.clone(),
|
||||
cap: Capability {
|
||||
issuer: Address {
|
||||
node: our_node.clone(),
|
||||
process: VFS_PROCESS_ID.clone(),
|
||||
},
|
||||
params: serde_json::to_string(&serde_json::json!({
|
||||
"root": true,
|
||||
}))
|
||||
.unwrap(),
|
||||
},
|
||||
responder: send_cap_bool,
|
||||
})
|
||||
.await?;
|
||||
let has_root_cap = recv_cap_bool.await?;
|
||||
if has_root_cap {
|
||||
let mut dir = fs::read_dir(vfs_path.clone()).await?;
|
||||
let mut entries = Vec::new();
|
||||
while let Some(entry) = dir.next_entry().await? {
|
||||
let entry_path = entry.path();
|
||||
let relative_path = entry_path.strip_prefix(&vfs_path).unwrap_or(&entry_path);
|
||||
|
||||
let metadata = entry.metadata().await?;
|
||||
let file_type = get_file_type(&metadata);
|
||||
let dir_entry = DirEntry {
|
||||
path: relative_path.display().to_string(),
|
||||
file_type,
|
||||
};
|
||||
entries.push(dir_entry);
|
||||
}
|
||||
|
||||
let response = KernelMessage {
|
||||
id,
|
||||
source: Address {
|
||||
node: our_node.clone(),
|
||||
process: VFS_PROCESS_ID.clone(),
|
||||
},
|
||||
target: source,
|
||||
rsvp: None,
|
||||
message: Message::Response((
|
||||
Response {
|
||||
inherit: false,
|
||||
body: serde_json::to_vec(&VfsResponse::ReadDir(entries)).unwrap(),
|
||||
metadata,
|
||||
capabilities: vec![],
|
||||
},
|
||||
None,
|
||||
)),
|
||||
lazy_load_blob: None,
|
||||
};
|
||||
|
||||
let _ = send_to_loop.send(response).await;
|
||||
return Ok(());
|
||||
} else {
|
||||
let no_cap_error = VfsError::NoCap {
|
||||
action: request.action.to_string(),
|
||||
path: request.path.clone(),
|
||||
};
|
||||
return Err(no_cap_error);
|
||||
}
|
||||
}
|
||||
|
||||
// current prepend to filepaths needs to be: /package_id/drive/path
|
||||
let (package_id, drive, rest) = parse_package_and_drive(&request.path).await?;
|
||||
let drive = format!("/{}/{}", package_id, drive);
|
||||
|
Loading…
Reference in New Issue
Block a user