cleaning all warnings
This commit is contained in:
parent
ddf2169950
commit
f56dcd30b8
@ -9,7 +9,8 @@ pub mod rm_dir;
|
||||
pub mod deleted;
|
||||
|
||||
pub fn push() {
|
||||
let remote = match config::get("remote") {
|
||||
// todo
|
||||
let _remote = match config::get("remote") {
|
||||
Some(r) => r,
|
||||
None => {
|
||||
eprintln!("fatal: no remote set in configuration");
|
||||
@ -27,11 +28,17 @@ pub fn push() {
|
||||
|
||||
for obj in staged_objs {
|
||||
if obj.otype == String::from("tree") {
|
||||
dbg!(("folder", obj.clone()));
|
||||
let push_factory = PushFactory.new_dir(obj.clone());
|
||||
let res = push_factory.can_push(&mut whitelist);
|
||||
match res {
|
||||
PushState::Valid => push_factory.push(),
|
||||
PushState::Valid => {
|
||||
match push_factory.push() {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
eprintln!("err: pushing {}: {}", obj.name, err);
|
||||
}
|
||||
}
|
||||
},
|
||||
PushState::Done => (),
|
||||
PushState::Conflict => {
|
||||
println!("CONFLICT: {}", obj.clone().name);
|
||||
@ -40,10 +47,16 @@ pub fn push() {
|
||||
};
|
||||
|
||||
} else {
|
||||
dbg!(("file", obj.clone()));
|
||||
let push_factory = PushFactory.new(obj.clone());
|
||||
match push_factory.can_push(&mut whitelist) {
|
||||
PushState::Valid => push_factory.push(),
|
||||
PushState::Valid => {
|
||||
match push_factory.push() {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
eprintln!("err: pushing {}: {}", obj.name, err);
|
||||
}
|
||||
}
|
||||
},
|
||||
PushState::Done => (),
|
||||
PushState::Conflict => {
|
||||
// download file
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::services::delete_path::DeletePath;
|
||||
use crate::store::index;
|
||||
use crate::store::object::blob;
|
||||
@ -22,7 +22,7 @@ impl PushChange for Deleted {
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self) {
|
||||
fn push(&self) -> io::Result<()> {
|
||||
let obj = &self.obj;
|
||||
let res = DeletePath::new()
|
||||
.set_url(obj.path.to_str().unwrap())
|
||||
@ -41,9 +41,13 @@ impl PushChange for Deleted {
|
||||
}
|
||||
|
||||
// update tree
|
||||
blob::rm(obj.path.clone());
|
||||
// todo date
|
||||
blob::rm(obj.path.clone())?;
|
||||
|
||||
// remove index
|
||||
index::rm_line(obj.path.to_str().unwrap());
|
||||
index::rm_line(obj.path.to_str().unwrap())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn conflict(&self) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::req_props::{ReqProps, ObjProps};
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::services::upload_file::UploadFile;
|
||||
use crate::store::index;
|
||||
use crate::store::object::blob;
|
||||
@ -22,7 +23,7 @@ impl PushChange for New {
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self) {
|
||||
fn push(&self) -> io::Result<()> {
|
||||
let obj = &self.obj;
|
||||
let res = UploadFile::new()
|
||||
.set_url(obj.path.to_str().unwrap())
|
||||
@ -67,10 +68,12 @@ impl PushChange for New {
|
||||
let lastmodified = prop.lastmodified.unwrap().timestamp_millis();
|
||||
|
||||
// update blob
|
||||
blob::add(obj.path.clone(), &lastmodified.to_string());
|
||||
blob::add(obj.path.clone(), &lastmodified.to_string())?;
|
||||
|
||||
// remove index
|
||||
index::rm_line(obj.path.to_str().unwrap());
|
||||
index::rm_line(obj.path.to_str().unwrap())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// download file with .distant at the end
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::req_props::{ReqProps, ObjProps};
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::services::create_folder::CreateFolder;
|
||||
use crate::store::index;
|
||||
use crate::store::object::tree;
|
||||
@ -28,7 +29,7 @@ impl PushChange for NewDir {
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self) {
|
||||
fn push(&self) -> io::Result<()> {
|
||||
let obj = &self.obj;
|
||||
let res = CreateFolder::new()
|
||||
.set_url(obj.path.to_str().unwrap())
|
||||
@ -71,13 +72,14 @@ impl PushChange for NewDir {
|
||||
};
|
||||
|
||||
let lastmodified = prop.lastmodified.unwrap().timestamp_millis();
|
||||
dbg!(lastmodified);
|
||||
|
||||
// update tree
|
||||
tree::add(obj.path.clone(), &lastmodified.to_string());
|
||||
tree::add(obj.path.clone(), &lastmodified.to_string())?;
|
||||
|
||||
// remove index
|
||||
index::rm_line(obj.path.to_str().unwrap());
|
||||
index::rm_line(obj.path.to_str().unwrap())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn conflict(&self) {}
|
||||
|
@ -1,8 +1,9 @@
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
use crate::commands::status::{State, LocalObj};
|
||||
use crate::services::api::ApiError;
|
||||
use crate::store::object;
|
||||
use crate::services::req_props::{ObjProps, ReqProps};
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::commands::push::new::New;
|
||||
use crate::commands::push::new_dir::NewDir;
|
||||
use crate::commands::push::rm_dir::RmDir;
|
||||
@ -26,18 +27,9 @@ pub enum PushFlowState {
|
||||
|
||||
pub trait PushChange {
|
||||
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState;
|
||||
fn push(&self);
|
||||
fn push(&self) -> io::Result<()>;
|
||||
fn conflict(&self);
|
||||
|
||||
fn try_push(&self, whitelist: &mut Option<PathBuf>) {
|
||||
match self.can_push(whitelist) {
|
||||
PushState::Valid => self.push(),
|
||||
PushState::Conflict => self.conflict(),
|
||||
PushState::Done => (),
|
||||
PushState::Error => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_whitelisted(&self, obj: &LocalObj, path: Option<PathBuf>) -> bool {
|
||||
match path {
|
||||
Some(p) => obj.path.starts_with(p),
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::path::PathBuf;
|
||||
use std::io;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::delete_path::DeletePath;
|
||||
use crate::store::index;
|
||||
@ -27,7 +28,7 @@ impl PushChange for RmDir {
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self) {
|
||||
fn push(&self) -> io::Result<()> {
|
||||
let obj = &self.obj;
|
||||
let res = DeletePath::new()
|
||||
.set_url(obj.path.to_str().unwrap())
|
||||
@ -47,9 +48,12 @@ impl PushChange for RmDir {
|
||||
|
||||
// update tree
|
||||
// todo update date
|
||||
tree::rm(obj.path.clone());
|
||||
tree::rm(obj.path.clone())?;
|
||||
|
||||
// remove index
|
||||
index::rm_line(obj.path.to_str().unwrap());
|
||||
index::rm_line(obj.path.to_str().unwrap())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn conflict(&self) {}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::io::{self, Lines, BufReader};
|
||||
use std::collections::{HashSet, HashMap};
|
||||
use std::collections::HashMap;
|
||||
use crypto::digest::Digest;
|
||||
use crypto::sha1::Sha1;
|
||||
use colored::Colorize;
|
||||
@ -31,7 +31,7 @@ pub enum State {
|
||||
pub fn status() {
|
||||
let (mut new_objs_hashes, mut del_objs_hashes) = get_diff();
|
||||
// get copy, modified
|
||||
let mut staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes);
|
||||
let staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes);
|
||||
|
||||
let mut objs: Vec<LocalObj> = del_objs_hashes.iter().map(|x| {
|
||||
x.1.clone()
|
||||
@ -41,8 +41,6 @@ pub fn status() {
|
||||
objs.push(elt.clone());
|
||||
}
|
||||
|
||||
dbg!(objs.clone());
|
||||
dbg!(staged_objs.clone());
|
||||
print_status(staged_objs, objs);
|
||||
}
|
||||
|
||||
@ -57,7 +55,7 @@ pub struct LocalObj {
|
||||
pub fn get_all_staged() -> Vec<LocalObj> {
|
||||
let (mut new_objs_hashes, mut del_objs_hashes) = get_diff();
|
||||
// get copy, modified
|
||||
let mut staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes);
|
||||
let staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes);
|
||||
|
||||
staged_objs.clone()
|
||||
// todo opti getting staged and then finding differences ?
|
||||
|
@ -73,7 +73,7 @@ impl ReqProps {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn getcontentlenght(&mut self) -> &mut ReqProps {
|
||||
pub fn _getcontentlenght(&mut self) -> &mut ReqProps {
|
||||
self.xml_balises.push(String::from("getcontentlength"));
|
||||
self.xml_payload.push_str(r#"<d:getcontentlength/>"#);
|
||||
self
|
||||
|
@ -87,17 +87,19 @@ fn add_node(path: &Path, node: &str) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_dates(mut path: PathBuf, date: &str) {
|
||||
fn update_dates(mut path: PathBuf, date: &str) -> io::Result<()> {
|
||||
let mut obj_p = path::objects();
|
||||
|
||||
while path.pop() {
|
||||
let (dir, res) = hash_obj(path.to_str().unwrap());
|
||||
obj_p.push(dir);
|
||||
obj_p.push(res);
|
||||
update_date(obj_p.clone(), date.clone());
|
||||
update_date(obj_p.clone(), date.clone())?;
|
||||
obj_p.pop();
|
||||
obj_p.pop();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_date(path: PathBuf, date: &str) -> io::Result<()> {
|
||||
@ -151,7 +153,6 @@ pub fn get_timestamp(path_s: String) -> Option<i64> {
|
||||
let mut obj_p = path::objects();
|
||||
|
||||
let (dir, res) = hash_obj(&path_s);
|
||||
dbg!((dir.clone(), res.clone()));
|
||||
obj_p.push(dir);
|
||||
obj_p.push(res);
|
||||
|
||||
|
@ -22,7 +22,7 @@ pub fn add(path: PathBuf, date: &str) -> io::Result<()> {
|
||||
create_obj(hash, &content)?;
|
||||
|
||||
// update date for all parent
|
||||
update_dates(path, date);
|
||||
update_dates(path, date)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ pub fn add(path: PathBuf, date: &str) -> io::Result<()> {
|
||||
create_obj(hash, &content)?;
|
||||
|
||||
// update date for all parent
|
||||
update_dates(path, date);
|
||||
update_dates(path, date)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -34,13 +34,13 @@ pub fn rm(path: PathBuf) -> io::Result<()> {
|
||||
if ftype == String::from("blob") {
|
||||
object::rm(&hash)?;
|
||||
} else {
|
||||
rm_hash(hash);
|
||||
rm_hash(hash)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rm_hash(hash: String) {
|
||||
fn rm_hash(hash: String) -> io::Result<()> {
|
||||
let mut obj_p = path::objects();
|
||||
let (dir, res) = hash.split_at(2);
|
||||
obj_p.push(dir);
|
||||
@ -52,9 +52,9 @@ fn rm_hash(hash: String) {
|
||||
for line in reader {
|
||||
let (ftype, hash, _) = parse_line(line.unwrap());
|
||||
if ftype == String::from("blob") {
|
||||
object::rm(&hash);
|
||||
object::rm(&hash)?;
|
||||
} else {
|
||||
rm_hash(hash);
|
||||
rm_hash(hash)?;
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -62,6 +62,7 @@ fn rm_hash(hash: String) {
|
||||
eprintln!("error reading tree: {}", err);
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read(tree: String) -> Option<(String, io::Lines<io::BufReader<File>>)> {
|
||||
|
Loading…
Reference in New Issue
Block a user