minor cleaning

This commit is contained in:
grimhilt 2023-06-17 15:54:09 +02:00
parent 7cfd572ad0
commit eabf707844
7 changed files with 3 additions and 71 deletions

View File

@ -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 {

View File

@ -40,7 +40,6 @@ pub fn get(var: &str) -> Option<String> {
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());

View File

@ -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
}
}

View File

@ -58,10 +58,9 @@ pub fn get_all_staged() -> Vec<Obj> {
staged_objs
}
fn get_renamed(new_obj: &mut Vec<Obj>, del_obj: &mut Vec<Obj>) -> Vec<Obj> {
fn get_renamed(_new_obj: &mut Vec<Obj>, _del_obj: &mut Vec<Obj>) -> Vec<Obj> {
// get hash of all new obj, compare to hash of all del
let renamed_objs = vec![];
renamed_objs
}

View File

@ -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<u8>) -> io::Result<()> {
dbg!(path.clone());
let mut f = OpenOptions::new()
.write(true)
.create(true)

View File

@ -132,7 +132,6 @@ pub fn read_tree(tree: String) -> Option<(String, io::Lines<io::BufReader<File>>
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<io::BufReader<File>>
None
},
}
}
fn rm_node(path: &Path, node: &str) -> io::Result<()> {

View File

@ -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()
}