diff --git a/Cargo.lock b/Cargo.lock index d015c5e..f286174 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,6 +234,7 @@ dependencies = [ "extendr-api", "file-owner", "memmap2", + "path-absolutize", "rayon", "serde", "serde_json", @@ -405,6 +406,24 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "path-absolutize" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4af381fe79fa195b4909485d99f73a80792331df0625188e707854f0b3383f5" +dependencies = [ + "path-dedot", +] + +[[package]] +name = "path-dedot" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07ba0ad7e047712414213ff67533e6dd477af0a4e1d14fb52343e53d30ea9397" +dependencies = [ + "once_cell", +] + [[package]] name = "proc-macro2" version = "1.0.79" diff --git a/Cargo.toml b/Cargo.toml index 8c1eb25..da083f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,4 +16,5 @@ memmap2 = "0.7.1" rayon = "1.7.0" file-owner = "0.1.2" chrono = "0.4.37" -walkdir = "2.4.0" \ No newline at end of file +walkdir = "2.4.0" +path-absolutize = "3.1.1" \ No newline at end of file diff --git a/src/cmd/status_cmd.rs b/src/cmd/status_cmd.rs index 50903f8..2d607cf 100644 --- a/src/cmd/status_cmd.rs +++ b/src/cmd/status_cmd.rs @@ -2,8 +2,7 @@ use std::path::PathBuf; use crate::internal::config::config; use crate::internal::file::hash; -use crate::internal::git::{self, repo}; -use crate::internal::log::json; +use crate::internal::git::repo; use crate::internal::meta::{file, parse}; #[derive(Debug)] @@ -17,28 +16,13 @@ pub struct JsonFileResult { pub message: String } -// struct JsonResult { -// files: Vec, -// errors:Vec -// } - -// impl JsonResult { -// fn add_file(&mut self, file_result: JsonFileResult) { -// self.files.push(file_result); -// } - -// fn add_error(&mut self, json_issue: json::JsonIssue) { -// self.errors.push(json_issue); -// } -// } // impl - pub fn run_status_cmd(files: &Vec) -> Result, std::io::Error> { let mut json_logger: Vec = Vec::new(); let mut meta_paths: Vec = Vec::new(); - //iIf no arguments are provided, get the status of all files in the current git repository + // if no arguments are provided, get the status of all files in the current git repository if files.is_empty() { // Get git root let git_repo = match repo::get_nearest_repo_dir(&PathBuf::from(".")) { diff --git a/src/internal/git/repo.rs b/src/internal/git/repo.rs index 0a0ae32..e5acb76 100644 --- a/src/internal/git/repo.rs +++ b/src/internal/git/repo.rs @@ -1,18 +1,18 @@ use std::path::{PathBuf, Path}; use std::fs; +use path_absolutize::*; pub fn get_relative_path(root_dir: &PathBuf, file_path: &PathBuf) -> Result { - // let abs_file_path = match file_path.canonicalize() { - // Ok(path) => path, - // Err(e) => return Err(e), - // }; + let abs_file_string = file_path.absolutize().unwrap().to_str().unwrap().to_string(); + let abs_file_path = PathBuf::from(abs_file_string); + let abs_root_dir = match root_dir.canonicalize() { Ok(path) => path, Err(e) => return Err(e), }; - match file_path.strip_prefix(abs_root_dir) { + match abs_file_path.strip_prefix(abs_root_dir) { Ok(path) => return Ok(path.to_path_buf()), Err(_) => return Err(std::io::Error::other("paths not relative")), } diff --git a/src/internal/log/json.rs b/src/internal/log/json.rs deleted file mode 100644 index a3b6547..0000000 --- a/src/internal/log/json.rs +++ /dev/null @@ -1,31 +0,0 @@ -use serde::{Deserialize, Serialize}; -use serde_json::Result; - -#[derive(Serialize, Deserialize)] -pub struct JsonAction { - pub action: String, - pub path: String -} - -#[derive(Serialize, Deserialize)] -pub struct JsonFile { - pub status: String -} - -#[derive(Serialize, Deserialize)] -pub struct JsonIssue { - pub severity: String, - pub message: String, - pub location: String -} - -#[derive(Serialize, Deserialize)] -pub struct JsonLog { - pub actions: Vec, - pub issues: Vec -} - -pub static JSON_LOGGING: bool = false; - - - diff --git a/src/internal/log/mod.rs b/src/internal/log/mod.rs deleted file mode 100644 index 73720cb..0000000 --- a/src/internal/log/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod json; -pub mod pretty; \ No newline at end of file diff --git a/src/internal/log/pretty.rs b/src/internal/log/pretty.rs deleted file mode 100644 index f744c50..0000000 --- a/src/internal/log/pretty.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::internal::log::json; - -pub fn print(string: String) { - if json::JSON_LOGGING {return} - - println!("{}", string) -} \ No newline at end of file diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 4a2ca4d..632ee21 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -1,7 +1,6 @@ pub mod config; pub mod file; pub mod git; -pub mod log; pub mod meta; pub mod migrate; pub mod storage; diff --git a/src/main.rs b/src/main.rs index 23bbbd4..76d50d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,13 +30,14 @@ fn main() -> io::Result<()> { //add_cmd::run_add_cmd(&files, &message)?; //fs::remove_file(PathBuf::from("src/test_directory/test1.txt"))?; -// fs::remove_file(PathBuf::from("src/test_directory/test2.txt"))?; + // fs::remove_file(PathBuf::from("src/test_directory/test2.txt"))?; // dvs get src/test_directory/test1.txt src/test_directory/test2.txt //get_cmd::run_get_cmd(&files)?; let empty_vec: Vec = Vec::new(); - let vec = status_cmd::run_status_cmd(&empty_vec)?; + let one_path = vec![String::from("src/test_directory/test2.txt")]; + let vec = status_cmd::run_status_cmd(&one_path)?; println!("{:?}", vec); Ok(()) }