create IntoPathBuf
This commit is contained in:
parent
d323ae3070
commit
aced8b992a
@ -27,6 +27,12 @@ pub fn push() {
|
|||||||
|
|
||||||
let staged_objs = status::get_all_staged();
|
let staged_objs = status::get_all_staged();
|
||||||
|
|
||||||
|
// exit if there is nothing to push
|
||||||
|
if staged_objs.len() == 0 {
|
||||||
|
println!("Everything up-to-date");
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
// path that certify that all its children can be push whithout hesistation
|
// path that certify that all its children can be push whithout hesistation
|
||||||
// (e.g. if remote dir has no changes since last sync all children
|
// (e.g. if remote dir has no changes since last sync all children
|
||||||
// can be pushed without verification)
|
// can be pushed without verification)
|
||||||
|
@ -14,16 +14,16 @@ pub fn remote_diff() {
|
|||||||
let (folders, files) = get_diff(relative_p);
|
let (folders, files) = get_diff(relative_p);
|
||||||
|
|
||||||
for folder in folders {
|
for folder in folders {
|
||||||
println!("should pull {}", folder.clone().relative_s.unwrap());
|
println!("should pull {}", folder.clone().relative_s.unwrap());
|
||||||
}
|
}
|
||||||
for file in files {
|
for file in files {
|
||||||
println!("should pull {}", file.clone().relative_s.unwrap());
|
println!("should pull {}", file.clone().relative_s.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_diff(path: PathBuf) -> (Vec<ObjProps>, Vec<ObjProps>) {
|
pub fn get_diff(path: PathBuf) -> (Vec<ObjProps>, Vec<ObjProps>) {
|
||||||
|
|
||||||
let depth = "2"; // todo
|
let depth = "2"; // todo opti
|
||||||
let api_props = get_api_props();
|
let api_props = get_api_props();
|
||||||
|
|
||||||
enumerate_remote(
|
enumerate_remote(
|
||||||
|
@ -145,7 +145,7 @@ pub fn get_all_staged() -> Vec<LocalObj> {
|
|||||||
let mut staged_objs = vec![];
|
let mut staged_objs = vec![];
|
||||||
|
|
||||||
for line in lines {
|
for line in lines {
|
||||||
let obj = Blob::new(PathBuf::from(line)).get_local_obj();
|
let obj = Blob::new(line).get_local_obj();
|
||||||
if obj.state != State::Default {
|
if obj.state != State::Default {
|
||||||
staged_objs.push(obj);
|
staged_objs.push(obj);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ use std::time::SystemTime;
|
|||||||
use crypto::sha1::Sha1;
|
use crypto::sha1::Sha1;
|
||||||
use crypto::digest::Digest;
|
use crypto::digest::Digest;
|
||||||
use crate::commands::status::{LocalObj, State};
|
use crate::commands::status::{LocalObj, State};
|
||||||
|
use crate::utils::into::IntoPathBuf;
|
||||||
use crate::utils::path::path_buf_to_string;
|
use crate::utils::path::path_buf_to_string;
|
||||||
use crate::utils::{path, read};
|
use crate::utils::{path, read};
|
||||||
use crate::store::head;
|
use crate::store::head;
|
||||||
@ -24,7 +25,8 @@ pub struct Blob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Blob {
|
impl Blob {
|
||||||
pub fn new(r_path: PathBuf) -> Blob {
|
pub fn new<S>(r_path: S) -> Blob where S: IntoPathBuf {
|
||||||
|
let r_path = r_path.into();
|
||||||
let mut hasher = Sha1::new();
|
let mut hasher = Sha1::new();
|
||||||
hasher.input_str(r_path.to_str().unwrap());
|
hasher.input_str(r_path.to_str().unwrap());
|
||||||
let hash = hasher.result_str();
|
let hash = hasher.result_str();
|
||||||
@ -351,7 +353,7 @@ impl Blob {
|
|||||||
} else if !has_obj_ref && blob_exists {
|
} else if !has_obj_ref && blob_exists {
|
||||||
let identical_blobs = self.get_all_identical_blobs();
|
let identical_blobs = self.get_all_identical_blobs();
|
||||||
if identical_blobs.len() != 0 {
|
if identical_blobs.len() != 0 {
|
||||||
let identical_blob = Blob::new(identical_blobs[0].clone().into())
|
let identical_blob = Blob::new(identical_blobs[0].clone())
|
||||||
.get_local_obj();
|
.get_local_obj();
|
||||||
if identical_blob.state == State::Deleted {
|
if identical_blob.state == State::Deleted {
|
||||||
path_from = Some(identical_blob.path);
|
path_from = Some(identical_blob.path);
|
||||||
|
@ -4,3 +4,4 @@ pub mod nextsyncignore;
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod remote;
|
pub mod remote;
|
||||||
|
pub mod into;
|
||||||
|
18
src/utils/into.rs
Normal file
18
src/utils/into.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub trait IntoPathBuf {
|
||||||
|
fn into(self) -> PathBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoPathBuf for PathBuf {
|
||||||
|
fn into(self) -> PathBuf {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoPathBuf for String {
|
||||||
|
fn into(self) -> PathBuf {
|
||||||
|
PathBuf::from(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user