begin working on file indexing
This commit is contained in:
parent
30613f8cb4
commit
bf12b9e864
1 changed files with 32 additions and 5 deletions
37
src/main.rs
37
src/main.rs
|
|
@ -1,4 +1,4 @@
|
|||
use std::fs;
|
||||
use std::{fs::{self, DirEntry}, path::Path};
|
||||
use clap::{Parser, Subcommand};
|
||||
use rusqlite::Connection;
|
||||
|
||||
|
|
@ -22,19 +22,46 @@ struct Args {
|
|||
command: Command
|
||||
}
|
||||
|
||||
fn index(path: &String) {
|
||||
fn index(db: Connection, path: &String) {
|
||||
// iterate resume files
|
||||
let entries: Vec<DirEntry> = fs::read_dir(Path::new(path).join("resume"))
|
||||
.unwrap()
|
||||
.filter_map(|f| f.ok())
|
||||
.collect();
|
||||
for entry in entries {
|
||||
let file_type = match entry.file_type() {
|
||||
Ok(file_type) => file_type,
|
||||
Err(_) => continue
|
||||
};
|
||||
if !file_type.is_file() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let hash = match Path::new(&entry.file_name()).file_stem() {
|
||||
Some(stem) => match stem.to_os_string().into_string() {
|
||||
Ok(str) => str,
|
||||
Err(os_str) => {
|
||||
eprintln!("failed to convert file name for {:#?}", os_str);
|
||||
continue;
|
||||
}
|
||||
},
|
||||
None => {
|
||||
eprintln!("file {:#?} has no extension or conversion failed", entry.file_name());
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
println!("{}", hash);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let db = Connection::open(args.db_path).unwrap();
|
||||
db.execute("INSERT INTO `test` (test) VALUES (?1)", (1337,)).unwrap();
|
||||
|
||||
match &args.command {
|
||||
Command::Index { path } => {
|
||||
index(path);
|
||||
index(db, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue