From eabf7078447e7398e1a0b249efcdb434c175eb1c Mon Sep 17 00:00:00 2001 From: grimhilt Date: Sat, 17 Jun 2023 15:54:09 +0200 Subject: [PATCH] minor cleaning --- src/commands/clone.rs | 5 +---- src/commands/config.rs | 1 - src/commands/push.rs | 36 ---------------------------------- src/commands/status.rs | 3 +-- src/services/download_files.rs | 3 +-- src/store/object.rs | 2 -- src/utils/api.rs | 24 ----------------------- 7 files changed, 3 insertions(+), 71 deletions(-) diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 76bf13e..1620534 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -7,7 +7,7 @@ use crate::services::list_folders::ListFolders; use crate::services::download_files::DownloadFiles; use crate::store::object; use crate::commands; -use crate::utils::api::{get_local_path_t, ApiProps}; +use crate::utils::api::ApiProps; use crate::global::global::{DIR_PATH, set_dir_path}; pub fn clone(remote: Values<'_>) { @@ -27,7 +27,6 @@ pub fn clone(remote: Values<'_>) { username: username.to_string(), root: dist_path_str.to_string(), }; - dbg!(dist_path_str.clone()); let ref_path = match d.clone() { Some(dir) => Path::new(&dir).to_owned(), @@ -49,7 +48,6 @@ pub fn clone(remote: Values<'_>) { // request folder content let mut objs = vec![]; tokio::runtime::Runtime::new().unwrap().block_on(async { - dbg!(folder.clone()); let res = ListFolders::new() .set_request(folder.as_str(), &api_props) .gethref() @@ -100,7 +98,6 @@ pub fn clone(remote: Values<'_>) { let mut iter = objs.iter(); iter.next(); // jump first element which is the folder cloned for object in iter { - dbg!(object.clone()); if object.href.clone().unwrap().chars().last().unwrap() == '/' { folders.push(object.relative_s.clone().unwrap().to_string()); } else { diff --git a/src/commands/config.rs b/src/commands/config.rs index ce7c466..952b877 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -40,7 +40,6 @@ pub fn get(var: &str) -> Option { if let Ok(lines) = read::read_lines(root) { for line in lines { if let Ok(l) = line { - dbg!(l.clone()); if l.starts_with(var.clone()) { let (_, val) = l.split_once(" ").unwrap(); return Some(val.to_owned()); diff --git a/src/commands/push.rs b/src/commands/push.rs index 9f27214..7ec2215 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -202,39 +202,3 @@ impl PushFactory { } } } - -fn can_push_file(obj: Obj) -> PushState { - dbg!(obj.clone()); - // check if exist on server - let file_infos = tokio::runtime::Runtime::new().unwrap().block_on(async { - let res = ReqProps::new() - .set_url(obj.path.to_str().unwrap()) - .getlastmodified() - .send_with_err() - .await; - - match res { - Ok(data) => Ok(data), - Err(ApiError::IncorrectRequest(err)) => { - if err.status() == 404 { - Ok(vec![]) - } else { - Err(()) - } - }, - Err(_) => Err(()), - } - }); - - if let Ok(infos) = file_infos { - if infos.len() == 0 { - // file doesn't exist on remote - PushState::Valid - } else { - // check date - PushState::Conflict - } - } else { - PushState::Error - } -} diff --git a/src/commands/status.rs b/src/commands/status.rs index 082bb28..6dc843b 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -58,10 +58,9 @@ pub fn get_all_staged() -> Vec { staged_objs } -fn get_renamed(new_obj: &mut Vec, del_obj: &mut Vec) -> Vec { +fn get_renamed(_new_obj: &mut Vec, _del_obj: &mut Vec) -> Vec { // get hash of all new obj, compare to hash of all del let renamed_objs = vec![]; - renamed_objs } diff --git a/src/services/download_files.rs b/src/services/download_files.rs index 6007cae..43324bc 100644 --- a/src/services/download_files.rs +++ b/src/services/download_files.rs @@ -1,7 +1,7 @@ use crate::services::api::{ApiBuilder, ApiError}; use std::path::PathBuf; use reqwest::{Method, Response, Error}; -use crate::utils::api::{get_local_path_t, ApiProps}; +use crate::utils::api::ApiProps; use std::fs::OpenOptions; use std::io::{self, Write}; @@ -53,7 +53,6 @@ impl DownloadFiles { } fn write_file(path: PathBuf, content: &Vec) -> io::Result<()> { - dbg!(path.clone()); let mut f = OpenOptions::new() .write(true) .create(true) diff --git a/src/store/object.rs b/src/store/object.rs index 418e483..fdd8483 100644 --- a/src/store/object.rs +++ b/src/store/object.rs @@ -132,7 +132,6 @@ pub fn read_tree(tree: String) -> Option<(String, io::Lines> let (dir, res) = hash_obj(&tree); obj_p.push(dir); obj_p.push(res); - match read::read_lines(obj_p) { Ok(mut reader) => { @@ -147,7 +146,6 @@ pub fn read_tree(tree: String) -> Option<(String, io::Lines> None }, } - } fn rm_node(path: &Path, node: &str) -> io::Result<()> { diff --git a/src/utils/api.rs b/src/utils/api.rs index c2831de..9e70348 100644 --- a/src/utils/api.rs +++ b/src/utils/api.rs @@ -1,6 +1,3 @@ -use std::path::{PathBuf, Path}; -use std::env; - #[derive(Debug)] pub struct ApiProps { pub host: String, // nextcloud.example.com @@ -26,24 +23,3 @@ pub fn get_relative_s(p: String, api_props: &ApiProps) -> String { final_p = final_p.strip_prefix("/").unwrap().to_string(); final_p } - -pub fn get_local_path(p: String, local_p: PathBuf, username: &str, dist_p: &str) -> PathBuf { - let mut final_p = Path::new(p.as_str()); - final_p = final_p.strip_prefix("/remote.php/dav/files/").unwrap(); - final_p = final_p.strip_prefix(username.clone()).unwrap(); - let dist_p = Path::new(dist_p).strip_prefix("/"); - final_p = final_p.strip_prefix(dist_p.unwrap()).unwrap(); - local_p.clone().join(final_p.clone()) -} - -pub fn get_local_path_t(p: &str) -> String { - dbg!(p.clone()); - let username = env::var("USERNAME").unwrap(); - let root = env::var("ROOT").unwrap(); - let mut final_p = p; - final_p = final_p.strip_prefix("/remote.php/dav/files/").unwrap(); - final_p = final_p.strip_prefix(&username).unwrap(); - final_p = final_p.strip_prefix("/").unwrap(); - final_p = final_p.strip_prefix(&root).unwrap(); - final_p.to_string() -}