fix(push): push folder and return error when tcp fail

This commit is contained in:
grimhilt 2024-03-01 17:56:52 +01:00
parent d8b2116aeb
commit 06bb51476b
5 changed files with 36 additions and 23 deletions

View File

@ -40,9 +40,11 @@ pub fn push() {
let mut whitelist: Option<PathBuf> = None;
for obj in staged_objs {
dbg!(obj.clone());
if obj.otype == String::from("tree") {
let push_factory = PushFactory.new_dir(obj.clone());
let res = push_factory.can_push(&mut whitelist);
dbg!(&res);
match res {
PushState::Valid => {
match push_factory.push() {

View File

@ -1,3 +1,4 @@
use std::error::Error;
use std::path::PathBuf;
use std::io;
use crate::commands::status::{State, LocalObj};

View File

@ -5,6 +5,7 @@ use crypto::sha1::Sha1;
use colored::Colorize;
use crate::utils::path::{self, path_buf_to_string};
use crate::store::object::blob::Blob;
use crate::store::object::object::Obj;
use crate::store::object::tree::Tree;
use crate::utils::read::read_folder;
use crate::store::index;
@ -159,20 +160,15 @@ pub struct LocalObj {
}
pub fn get_all_staged() -> Vec<LocalObj> {
let mut lines: Vec<String> = vec![];
if let Ok(entries) = index::read_line() {
for entry in entries {
lines.push(entry.unwrap());
}
}
let mut staged_objs = vec![];
for line in lines {
let obj = Blob::from_path(line).get_local_obj();
if obj.state != State::Default {
staged_objs.push(obj);
if let Ok(entries) = index::read_line() {
for line in entries {
let obj = Obj::from_path(line.unwrap()).get_local_obj();
if obj.state != State::Default {
staged_objs.push(obj);
}
}
}
@ -264,7 +260,7 @@ fn get_diff() -> (HashMap<String, LocalObj>, HashMap<String, LocalObj>, Vec<Stri
read_tree_to_hashmap(&mut Tree::from_path(cur_obj.clone()), &mut hashes, dist_path.clone());
//let mut tree = Tree::from_path(cur_obj.clone());
//if let Some(lines) = tree.get_children() {
//add_to_hashmap(lines, &mut hashes, cur_path.clone());
//add_to_hashmap(lines, &mut hashes, cur_path.clone());
//}
// read physical tree

View File

@ -1,9 +1,10 @@
use std::error::Error;
use lazy_static::lazy_static;
use std::sync::Mutex;
use reqwest::Client;
use reqwest::RequestBuilder;
use reqwest::multipart::Form;
use reqwest::{Response, Error, Method};
use reqwest::{Response, Method};
use reqwest::header::{HeaderValue, CONTENT_TYPE, HeaderMap, IntoHeaderName};
use crate::utils::api::ApiProps;
use crate::commands::config;
@ -184,7 +185,7 @@ impl ApiBuilder {
self.set_request_manager();
}
let res = tokio::runtime::Runtime::new().unwrap().block_on(async {
let res_req = tokio::runtime::Runtime::new().unwrap().block_on(async {
match self.request.take() {
None => {
eprintln!("fatal: incorrect request");
@ -199,7 +200,16 @@ impl ApiBuilder {
}
},
}
}).map_err(ApiError::RequestError)?;
});
// handle request error
let res = match res_req {
Err(err) => {
eprintln!("fatal: {}", err.source().unwrap());
std::process::exit(1);
},
Ok(res) => res,
};
if res.status().is_success() {
if need_text {
@ -215,7 +225,7 @@ impl ApiBuilder {
}
}
pub async fn old_send(&mut self) -> Result<Response, Error> {
pub async fn old_send(&mut self) -> Result<Response, reqwest::Error> {
let mut request_manager = get_request_manager().lock().unwrap();
let request_manager = request_manager.as_mut().unwrap();
if !self.host.is_none()
@ -237,9 +247,9 @@ impl ApiBuilder {
Some(req) => {
if let Some(headers) = &self.headers {
req.headers(headers.clone())
.send().await.map_err(Error::from)
.send().await.map_err(reqwest::Error::from)
} else {
req.send().await.map_err(Error::from)
req.send().await.map_err(reqwest::Error::from)
}
},
}

View File

@ -6,6 +6,7 @@ use crate::store::head;
use crate::store::object::{add_node, rm_node};
use crypto::sha1::Sha1;
use crypto::digest::Digest;
use crate::utils::into::IntoPathBuf;
use crate::store::object::{blob::Blob, tree::Tree};
use crate::commands::status::{State, LocalObj};
@ -257,7 +258,8 @@ impl Obj {
}
}
pub fn from_path(path: PathBuf) -> Self {
pub fn from_path<S>(path: S) -> Obj where S: IntoPathBuf {
let path = path.into();
let mut hasher = Sha1::new();
hasher.input_str(path.to_str().unwrap());
let hash = hasher.result_str();
@ -287,6 +289,8 @@ impl Obj {
hash_path: hash,
}
}
/// load from the information line stored in the object
pub fn from_line(line: String, base_dir: Option<PathBuf>) -> Box<dyn ObjMethods> {
let mut split = line.rsplit(' ');
if split.clone().count() != 3 {