commit 74faf8fcc9ab7fead3982f3e098741c8414428b1 Author: lily Date: Fri Mar 28 01:33:23 2025 -0400 add: base project files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f97022 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..15bbf0f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,14 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "consumer" +version = "0.1.0" +dependencies = [ + "kosmora", +] + +[[package]] +name = "kosmora" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1287152 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,22 @@ +[workspace] +resolver = "2" +members = ["consumer", "kosmora"] + +[profile.dev] +rpath = false +panic = "abort" +lto = "off" +opt-level = 0 +debug = true +overflow-checks = false +incremental = true +codegen-units = 128 + +strip = "symbols" +debug-assertions = true + +[profile.release] +debug-assertions = false +lto = true +codegen-units = 1 +panic = "abort" diff --git a/consumer/.gitignore b/consumer/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/consumer/.gitignore @@ -0,0 +1 @@ +/target diff --git a/consumer/Cargo.toml b/consumer/Cargo.toml new file mode 100644 index 0000000..f4f7e7f --- /dev/null +++ b/consumer/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "consumer" +version = "0.1.0" +edition = "2024" + +[dependencies] +kosmora = { path = "../kosmora" } \ No newline at end of file diff --git a/consumer/src/main.rs b/consumer/src/main.rs new file mode 100644 index 0000000..5d5e3b3 --- /dev/null +++ b/consumer/src/main.rs @@ -0,0 +1,9 @@ +use kosmora::{self, KosmoraINodeInteroperable}; +use std::path::Path; + +fn main() { + let vfs = kosmora::KosmoraVfs::new(); + let example_path: &Path = &std::path::Path::new("."); + example_path.to_kosmora_inode(); +} + \ No newline at end of file diff --git a/kosmora/.gitignore b/kosmora/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/kosmora/.gitignore @@ -0,0 +1 @@ +/target diff --git a/kosmora/Cargo.toml b/kosmora/Cargo.toml new file mode 100644 index 0000000..941c56a --- /dev/null +++ b/kosmora/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "kosmora" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/kosmora/src/lib.rs b/kosmora/src/lib.rs new file mode 100644 index 0000000..10dd003 --- /dev/null +++ b/kosmora/src/lib.rs @@ -0,0 +1,113 @@ +use std::boxed::Box; + +pub struct KosmoraVfs { + index: KosmoraIndex, + packages: Vec +} + +struct KosmoraIndex { + index: Vec +} +struct KosmoraPackage { + id: usize, + inode_index: KosmoraDirectory +} + +pub enum KosmoraINodeType { + File(KosmoraFile), + Directory(KosmoraDirectory) +} + +pub struct KosmoraFileMetadata { + name: String, + extension: Option, + size: usize, +} + +pub struct KosmoraFile { + metadata: KosmoraFileMetadata, + data: Vec +} + +pub struct KosmoraDirectory { + name: String, + parent: Option>, + children: Option> +} + +pub struct KosmoraINode { + inode: KosmoraINodeType +} + +impl KosmoraVfs { + pub fn new() -> Self { + KosmoraVfs { + index: KosmoraIndex { index: Vec::new() }, + packages: Vec::new() + } + } + + pub fn create_directory(virtual_path: &str) {} + pub fn add_directory(real_path: &str, virtual_path: &str) {} + pub fn add_file(real_path: &str, virtual_path: &str) {} +} + +pub trait KosmoraINodeInteroperable { + fn collect_directory_children(&self) -> KosmoraINode; + fn to_kosmora_inode(&self) -> KosmoraINode; +} + +impl KosmoraINodeInteroperable for std::path::Path { + fn collect_directory_children(&self) -> KosmoraINode { + if !self.exists() || !self.is_dir() { + panic!("nuh uh that isnt allowed") + } + + dbg!(self); + match std::fs::File::open(&self) { + Ok(file) => { + todo!() + }, + Err(e) => { + eprintln!("{e}"); + todo!() + } + } + } + + fn to_kosmora_inode(&self) -> KosmoraINode { + if !self.exists() { + panic!("Path does not exist"); + } + + if self.is_dir() { + let dir = KosmoraDirectory { + name: self.components().last().unwrap().as_os_str().to_string_lossy().into(), + parent: None, + children: Some(Box::new(self.collect_directory_children())), + }; + return KosmoraINode { inode: KosmoraINodeType::Directory(dir) }; + } + + if self.is_file() { + let meta = self.metadata() + .map_err(|_| panic!("Failed to get metadata")) + .ok() + .expect("Failed to get metadata"); + + let file_metadata = KosmoraFileMetadata { + name: String::from(self.file_name().unwrap().to_str().unwrap().to_string()), + extension: Some(self.file_name().unwrap().to_str().unwrap().split(".").last().unwrap().to_string()), + size: meta.len() as usize, + }; + + let file = KosmoraFile { + metadata: file_metadata, + data: std::fs::read(self).unwrap(), + }; + + return KosmoraINode { inode: KosmoraINodeType::File(file) } + } + panic!("Unsupported path type"); + } +} \ No newline at end of file