diff --git a/.env b/.env new file mode 100644 index 0000000..92ce722 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DATABASE_URL=$PWD/db/fdb.sqlite diff --git a/Cargo.lock b/Cargo.lock index 8c17222..061245a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,18 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "anstream" version = "0.6.18" @@ -69,6 +57,15 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "cc" +version = "1.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13208fcbb66eaeffe09b99fffbe1af420f00a7b35aa99ad683dfc1aa76145229" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -124,6 +121,83 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "diesel" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf1bedf64cdb9643204a36dd15b19a6ce8e7aa7f7b105868e9f1fad5ffa7d12" +dependencies = [ + "diesel_derives", + "libsqlite3-sys", + "time", +] + +[[package]] +name = "diesel_derives" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f2c3de51e2ba6bf2a648285696137aaf0f5f487bcbea93972fe8a364e131a4" +dependencies = [ + "diesel_table_macro_syntax", + "dsl_auto_type", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "diesel_table_macro_syntax" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" +dependencies = [ + "syn", +] + [[package]] name = "dirs" version = "5.0.1" @@ -145,6 +219,32 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "dsl_auto_type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5d9abe6314103864cc2d8901b7ae224e0ab1a103a0a416661b4097b0779b607" +dependencies = [ + "darling", + "either", + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "errno" version = "0.3.10" @@ -155,24 +255,18 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "fallible-iterator" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" - -[[package]] -name = "fallible-streaming-iterator" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" - [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "getrandom" version = "0.2.15" @@ -184,36 +278,30 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", -] - -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown", -] - [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" + [[package]] name = "lazy_static" version = "1.5.0" @@ -242,6 +330,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ + "cc", "pkg-config", "vcpkg", ] @@ -268,13 +357,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "nytefdb" version = "0.1.0" dependencies = [ "clap", + "diesel", "dirs", - "rusqlite", + "dotenvy", + "libsqlite3-sys", "tempfile", "thiserror 2.0.11", "tracing", @@ -311,6 +408,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.92" @@ -340,20 +443,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "rusqlite" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e" -dependencies = [ - "bitflags", - "fallible-iterator", - "fallible-streaming-iterator", - "hashlink", - "libsqlite3-sys", - "smallvec", -] - [[package]] name = "rustix" version = "0.38.43" @@ -367,6 +456,26 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "serde" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.217" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -376,6 +485,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "smallvec" version = "1.13.2" @@ -473,6 +588,37 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tracing" version = "0.1.41" @@ -566,12 +712,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -738,23 +878,3 @@ name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/Cargo.toml b/Cargo.toml index 7195abb..f9cc016 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,11 @@ edition = "2021" dirs = "5.0" tracing = "0.1" tracing-subscriber = "0.3" -rusqlite = "0.32" clap = { version = "4.5.24", features = ["derive", "unstable-doc"] } thiserror = "2.0.11" +libsqlite3-sys = { version = "0.30", features = ["bundled"] } +diesel = { version = "2.2.6", features = ["sqlite"] } +dotenvy = "0.15.7" [dev-dependencies] tempfile = "3" diff --git a/db/fdb.sqlite b/db/fdb.sqlite new file mode 100644 index 0000000..444ad7c Binary files /dev/null and b/db/fdb.sqlite differ diff --git a/diesel.toml b/diesel.toml new file mode 100644 index 0000000..18d62e3 --- /dev/null +++ b/diesel.toml @@ -0,0 +1,9 @@ +# For documentation on how to configure this file, +# see https://diesel.rs/guides/configuring-diesel-cli + +[print_schema] +file = "src/schema.rs" +custom_type_derives = ["diesel::query_builder::QueryId", "Clone"] + +[migrations_directory] +dir = "/home/aargonian/Projects/Programming/nytefdb/migrations" diff --git a/migrations/.keep b/migrations/.keep new file mode 100644 index 0000000..e69de29 diff --git a/migrations/2025-01-30-043603_create_files/down.sql b/migrations/2025-01-30-043603_create_files/down.sql new file mode 100644 index 0000000..0ad9df9 --- /dev/null +++ b/migrations/2025-01-30-043603_create_files/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE files; diff --git a/migrations/2025-01-30-043603_create_files/up.sql b/migrations/2025-01-30-043603_create_files/up.sql new file mode 100644 index 0000000..a39e224 --- /dev/null +++ b/migrations/2025-01-30-043603_create_files/up.sql @@ -0,0 +1,15 @@ +CREATE TABLE files ( + sha256_hash TEXT NOT NULL, + file_path TEXT NOT NULL, + basename TEXT NOT NULL, + size INTEGER NOT NULL, + extension TEXT, + file_type TEXT NOT NULL CHECK (file_type IN ('File', 'Symlink', 'Directory', 'Other')), + mime_type TEXT, + creation_time INTEGER NOT NULL, + last_modified_time INTEGER NOT NULL, + access_time INTEGER NOT NULL, + owner TEXT NOT NULL, + permissions INTEGER NOT NULL, + PRIMARY KEY (sha256_hash, file_path) +); diff --git a/src/filewalker.rs b/src/filewalker.rs new file mode 100644 index 0000000..1641682 --- /dev/null +++ b/src/filewalker.rs @@ -0,0 +1,22 @@ +/** + * FileWalker represents the process of actually walking the tree of files we will be processing. + * It enables a structure not only for actually walking the tree, but for injecting hooks into the + * walking process. + */ +//TODO: Implement "IntoIterator" for FileWalker +//TODO: Implement "Iterator?" for FileWalker +//Desired Iterator Featuers: +// - Collect to do eager evaluation of the whole tree +struct FileWalker { + current_dir: Option<&Path>, + current_item: Option<&Path>, +} + +impl <'a> Iterator for FileWalker<'a> { + type Item = &'a Path; + + fn next(&mut self) -> Option { + let current_dir: &Path = self.current_dir?; + return 3; + } +} diff --git a/src/lib.rs b/src/lib.rs index e69de29..8b13789 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -0,0 +1 @@ + diff --git a/src/nytedb/main.rs b/src/nytedb/main.rs index 1464cd4..7164669 100644 --- a/src/nytedb/main.rs +++ b/src/nytedb/main.rs @@ -4,12 +4,14 @@ // Expose everything from common mod common; +use std::path::PathBuf; + pub use common::*; pub mod database; use clap::{Parser, Subcommand}; -use tracing::{info, Level}; +use tracing::{error, info, Level}; use tracing_subscriber::FmtSubscriber; use crate::database::find_database; @@ -18,8 +20,10 @@ use crate::database::find_database; #[command(version, about, long_about = None)] #[command(propagate_version = true)] struct Args { - #[command(subcommand)] - command: Commands, + // #[command(subcommand)] + // command: Option, + + path: PathBuf, } #[derive(Subcommand)] @@ -33,7 +37,7 @@ enum Commands { Standalone { path: String }, } -fn main() { +fn main() -> Result<(), isize> { let subscriber = FmtSubscriber::builder() .with_max_level(Level::TRACE) .finish(); @@ -44,15 +48,19 @@ fn main() { info!("Beginning NyteFDB Initialization"); // Initialize Clap - let _args = Args::parse(); + let args = Args::parse(); // TODO: Parse Command Line Arguments - let path = None; + let path = args.path; + if !path.exists() { + error!("The provided path does not exist: {:?}", path); + return Err(-1); + } // TODO: Open Existing Database - let _database = find_database(false, true, path); + let _database = find_database(false, true, Some(&path)); - // TODO: Verify Database + /* TODO: Verify Database // info!("NyteFDB Initialization Complete"); // @@ -127,4 +135,6 @@ fn main() { // // at the passed directory. // _ => unimplemented!(), // } + */ + Ok(()) } diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..e3d839b --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,18 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + files (sha256_hash, file_path) { + sha256_hash -> Text, + file_path -> Text, + basename -> Text, + size -> Integer, + extension -> Nullable, + file_type -> Text, + mime_type -> Nullable, + creation_time -> Integer, + last_modified_time -> Integer, + access_time -> Integer, + owner -> Text, + permissions -> Integer, + } +}