From 3da439ccf62a4d1f54229590985b982475fa6bee Mon Sep 17 00:00:00 2001 From: grimhilt Date: Wed, 14 Jun 2023 11:16:19 +0200 Subject: [PATCH] add store --- src/commands/add.rs | 3 ++- src/commands/clone.rs | 2 +- src/commands/config.rs | 3 +-- src/commands/status.rs | 5 +++-- src/main.rs | 1 + src/store.rs | 3 +++ src/{utils => store}/head.rs | 0 src/{utils => store}/index.rs | 0 src/{utils => store}/object.rs | 3 ++- src/utils.rs | 3 --- src/utils/config.rs | 6 ------ 11 files changed, 13 insertions(+), 16 deletions(-) create mode 100644 src/store.rs rename src/{utils => store}/head.rs (100%) rename src/{utils => store}/index.rs (100%) rename src/{utils => store}/object.rs (98%) delete mode 100644 src/utils/config.rs diff --git a/src/commands/add.rs b/src/commands/add.rs index 989b45a..d75cac7 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -1,5 +1,6 @@ use clap::Values; use crate::utils; +use crate::store; use std::path::Path; use std::io::Write; @@ -14,7 +15,7 @@ pub fn add(files: Values<'_>) { let mut index_path = root.clone(); index_path.push(".nextsync"); - let mut index_file = utils::index::open(index_path); + let mut index_file = store::index::open(index_path); // todo avoid duplicate // ./folder ./folder/file diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 9c5a6b3..d998bc6 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -9,7 +9,7 @@ use xml::reader::{EventReader, XmlEvent}; use crate::services::api::ApiError; use crate::services::list_folders::ListFolders; use crate::services::download_files::DownloadFiles; -use crate::utils::object; +use crate::store::object; use crate::commands; use crate::global::global::{DIR_PATH, set_dir_path}; diff --git a/src/commands/config.rs b/src/commands/config.rs index 0b17a12..ce7c466 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -1,5 +1,4 @@ -use crate::utils::path; -use crate::utils::read; +use crate::utils::{path, read}; use std::fs::OpenOptions; use std::io::{self, Write}; diff --git a/src/commands/status.rs b/src/commands/status.rs index 0bd5979..9d13eda 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -5,7 +5,8 @@ use std::collections::HashMap; use colored::Colorize; use std::path::PathBuf; use std::io::{self, Lines, BufReader}; -use crate::utils::{self, object}; +use crate::utils; +use crate::store::{self, object}; #[derive(PartialEq)] enum RemoveSide { @@ -80,7 +81,7 @@ pub fn get_diff() -> (Vec, Vec, Vec) { } - if let Ok(entries) = utils::index::read_line(nextsync_path.clone()) { + if let Ok(entries) = store::index::read_line(nextsync_path.clone()) { for entry in entries { // todo hash this staged_objs.push(String::from(entry.unwrap())); diff --git a/src/main.rs b/src/main.rs index db6822d..420885f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod commands; mod utils; mod services; mod global; +mod store; fn main() { let matches = App::new("NextSync") diff --git a/src/store.rs b/src/store.rs new file mode 100644 index 0000000..551c27c --- /dev/null +++ b/src/store.rs @@ -0,0 +1,3 @@ +pub mod index; +pub mod head; +pub mod object; diff --git a/src/utils/head.rs b/src/store/head.rs similarity index 100% rename from src/utils/head.rs rename to src/store/head.rs diff --git a/src/utils/index.rs b/src/store/index.rs similarity index 100% rename from src/utils/index.rs rename to src/store/index.rs diff --git a/src/utils/object.rs b/src/store/object.rs similarity index 98% rename from src/utils/object.rs rename to src/store/object.rs index 19bf0e5..3792897 100644 --- a/src/utils/object.rs +++ b/src/store/object.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; -use crate::utils::{read, head, path}; +use crate::utils::{read, path}; +use crate::store::head; use crypto::sha1::Sha1; use crypto::digest::Digest; use std::fs::{OpenOptions, self}; diff --git a/src/utils.rs b/src/utils.rs index c803f36..f47ce16 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,2 @@ pub mod path; -pub mod index; -pub mod head; pub mod read; -pub mod object; diff --git a/src/utils/config.rs b/src/utils/config.rs deleted file mode 100644 index 945593b..0000000 --- a/src/utils/config.rs +++ /dev/null @@ -1,6 +0,0 @@ - - -src/utils/object.rs -todo -src/utils/head.rs -src/utils/read.rs