add: base project files
This commit is contained in:
commit
74faf8fcc9
9 changed files with 174 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target/
|
14
Cargo.lock
generated
Normal file
14
Cargo.lock
generated
Normal file
|
@ -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"
|
22
Cargo.toml
Normal file
22
Cargo.toml
Normal file
|
@ -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"
|
1
consumer/.gitignore
vendored
Normal file
1
consumer/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
7
consumer/Cargo.toml
Normal file
7
consumer/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "consumer"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
kosmora = { path = "../kosmora" }
|
9
consumer/src/main.rs
Normal file
9
consumer/src/main.rs
Normal file
|
@ -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();
|
||||
}
|
||||
|
1
kosmora/.gitignore
vendored
Normal file
1
kosmora/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
6
kosmora/Cargo.toml
Normal file
6
kosmora/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "kosmora"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
113
kosmora/src/lib.rs
Normal file
113
kosmora/src/lib.rs
Normal file
|
@ -0,0 +1,113 @@
|
|||
use std::boxed::Box;
|
||||
|
||||
pub struct KosmoraVfs {
|
||||
index: KosmoraIndex,
|
||||
packages: Vec<KosmoraPackage>
|
||||
}
|
||||
|
||||
struct KosmoraIndex {
|
||||
index: Vec<KosmoraPackage>
|
||||
}
|
||||
struct KosmoraPackage {
|
||||
id: usize,
|
||||
inode_index: KosmoraDirectory
|
||||
}
|
||||
|
||||
pub enum KosmoraINodeType {
|
||||
File(KosmoraFile),
|
||||
Directory(KosmoraDirectory)
|
||||
}
|
||||
|
||||
pub struct KosmoraFileMetadata {
|
||||
name: String,
|
||||
extension: Option<String>,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
pub struct KosmoraFile {
|
||||
metadata: KosmoraFileMetadata,
|
||||
data: Vec<u8>
|
||||
}
|
||||
|
||||
pub struct KosmoraDirectory {
|
||||
name: String,
|
||||
parent: Option<Box<KosmoraDirectory>>,
|
||||
children: Option<Box<KosmoraINode>>
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue