minor cleaning
This commit is contained in:
parent
7cfd572ad0
commit
eabf707844
@ -7,7 +7,7 @@ use crate::services::list_folders::ListFolders;
|
|||||||
use crate::services::download_files::DownloadFiles;
|
use crate::services::download_files::DownloadFiles;
|
||||||
use crate::store::object;
|
use crate::store::object;
|
||||||
use crate::commands;
|
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};
|
use crate::global::global::{DIR_PATH, set_dir_path};
|
||||||
|
|
||||||
pub fn clone(remote: Values<'_>) {
|
pub fn clone(remote: Values<'_>) {
|
||||||
@ -27,7 +27,6 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
username: username.to_string(),
|
username: username.to_string(),
|
||||||
root: dist_path_str.to_string(),
|
root: dist_path_str.to_string(),
|
||||||
};
|
};
|
||||||
dbg!(dist_path_str.clone());
|
|
||||||
|
|
||||||
let ref_path = match d.clone() {
|
let ref_path = match d.clone() {
|
||||||
Some(dir) => Path::new(&dir).to_owned(),
|
Some(dir) => Path::new(&dir).to_owned(),
|
||||||
@ -49,7 +48,6 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
// request folder content
|
// request folder content
|
||||||
let mut objs = vec![];
|
let mut objs = vec![];
|
||||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||||
dbg!(folder.clone());
|
|
||||||
let res = ListFolders::new()
|
let res = ListFolders::new()
|
||||||
.set_request(folder.as_str(), &api_props)
|
.set_request(folder.as_str(), &api_props)
|
||||||
.gethref()
|
.gethref()
|
||||||
@ -100,7 +98,6 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
let mut iter = objs.iter();
|
let mut iter = objs.iter();
|
||||||
iter.next(); // jump first element which is the folder cloned
|
iter.next(); // jump first element which is the folder cloned
|
||||||
for object in iter {
|
for object in iter {
|
||||||
dbg!(object.clone());
|
|
||||||
if object.href.clone().unwrap().chars().last().unwrap() == '/' {
|
if object.href.clone().unwrap().chars().last().unwrap() == '/' {
|
||||||
folders.push(object.relative_s.clone().unwrap().to_string());
|
folders.push(object.relative_s.clone().unwrap().to_string());
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,7 +40,6 @@ pub fn get(var: &str) -> Option<String> {
|
|||||||
if let Ok(lines) = read::read_lines(root) {
|
if let Ok(lines) = read::read_lines(root) {
|
||||||
for line in lines {
|
for line in lines {
|
||||||
if let Ok(l) = line {
|
if let Ok(l) = line {
|
||||||
dbg!(l.clone());
|
|
||||||
if l.starts_with(var.clone()) {
|
if l.starts_with(var.clone()) {
|
||||||
let (_, val) = l.split_once(" ").unwrap();
|
let (_, val) = l.split_once(" ").unwrap();
|
||||||
return Some(val.to_owned());
|
return Some(val.to_owned());
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -58,10 +58,9 @@ pub fn get_all_staged() -> Vec<Obj> {
|
|||||||
staged_objs
|
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
|
// get hash of all new obj, compare to hash of all del
|
||||||
let renamed_objs = vec![];
|
let renamed_objs = vec![];
|
||||||
|
|
||||||
renamed_objs
|
renamed_objs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::services::api::{ApiBuilder, ApiError};
|
use crate::services::api::{ApiBuilder, ApiError};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use reqwest::{Method, Response, Error};
|
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::fs::OpenOptions;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
@ -53,7 +53,6 @@ impl DownloadFiles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn write_file(path: PathBuf, content: &Vec<u8>) -> io::Result<()> {
|
fn write_file(path: PathBuf, content: &Vec<u8>) -> io::Result<()> {
|
||||||
dbg!(path.clone());
|
|
||||||
let mut f = OpenOptions::new()
|
let mut f = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
|
@ -133,7 +133,6 @@ pub fn read_tree(tree: String) -> Option<(String, io::Lines<io::BufReader<File>>
|
|||||||
obj_p.push(dir);
|
obj_p.push(dir);
|
||||||
obj_p.push(res);
|
obj_p.push(res);
|
||||||
|
|
||||||
|
|
||||||
match read::read_lines(obj_p) {
|
match read::read_lines(obj_p) {
|
||||||
Ok(mut reader) => {
|
Ok(mut reader) => {
|
||||||
let name = match reader.next() {
|
let name = match reader.next() {
|
||||||
@ -147,7 +146,6 @@ pub fn read_tree(tree: String) -> Option<(String, io::Lines<io::BufReader<File>>
|
|||||||
None
|
None
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rm_node(path: &Path, node: &str) -> io::Result<()> {
|
fn rm_node(path: &Path, node: &str) -> io::Result<()> {
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
use std::path::{PathBuf, Path};
|
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ApiProps {
|
pub struct ApiProps {
|
||||||
pub host: String, // nextcloud.example.com
|
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 = final_p.strip_prefix("/").unwrap().to_string();
|
||||||
final_p
|
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()
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user