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