check timestamp for conflicts with remote
This commit is contained in:
parent
2c593fb254
commit
675b650200
@ -7,7 +7,7 @@ use crate::global::global::{DIR_PATH, set_dir_path};
|
|||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
use crate::services::req_props::{ReqProps, ObjProps};
|
use crate::services::req_props::{ReqProps, ObjProps};
|
||||||
use crate::services::download_files::DownloadFiles;
|
use crate::services::download_files::DownloadFiles;
|
||||||
use crate::store::object::{self, add_blob, add_tree};
|
use crate::store::object::{tree, blob};
|
||||||
use crate::commands::init;
|
use crate::commands::init;
|
||||||
|
|
||||||
pub fn clone(remote: Values<'_>) {
|
pub fn clone(remote: Values<'_>) {
|
||||||
@ -93,7 +93,7 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
// add tree
|
// add tree
|
||||||
let path_folder = p.strip_prefix(ref_path.clone()).unwrap();
|
let path_folder = p.strip_prefix(ref_path.clone()).unwrap();
|
||||||
let lastmodified = folder.lastmodified.unwrap().timestamp_millis();
|
let lastmodified = folder.lastmodified.unwrap().timestamp_millis();
|
||||||
if let Err(err) = add_tree(&path_folder, &lastmodified.to_string()) {
|
if let Err(err) = tree::add(&path_folder, &lastmodified.to_string()) {
|
||||||
eprintln!("err: saving ref of {} ({})", path_folder.display(), err);
|
eprintln!("err: saving ref of {} ({})", path_folder.display(), err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ fn download_files(ref_p: PathBuf, files: Vec<ObjProps>, api_props: &ApiProps) {
|
|||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let relative_p = Path::new(&relative_s);
|
let relative_p = Path::new(&relative_s);
|
||||||
let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis();
|
let lastmodified = obj.clone().lastmodified.unwrap().timestamp_millis();
|
||||||
if let Err(err) = add_blob(relative_p, &lastmodified.to_string()) {
|
if let Err(err) = blob::add(relative_p, &lastmodified.to_string()) {
|
||||||
eprintln!("err: saving ref of {} ({})", relative_s.clone(), err);
|
eprintln!("err: saving ref of {} ({})", relative_s.clone(), err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,7 @@ use crate::services::upload_file::UploadFile;
|
|||||||
use crate::services::delete_path::DeletePath;
|
use crate::services::delete_path::DeletePath;
|
||||||
use crate::services::req_props::{ReqProps, ObjProps};
|
use crate::services::req_props::{ReqProps, ObjProps};
|
||||||
use crate::store::index;
|
use crate::store::index;
|
||||||
use crate::store::object::{add_blob, rm_blob};
|
use crate::store::object::blob;
|
||||||
use crate::commands::{status, config};
|
use crate::commands::{status, config};
|
||||||
use crate::commands::status::{State, LocalObj};
|
use crate::commands::status::{State, LocalObj};
|
||||||
use crate::commands::push::push_factory::{PushFactory, PushState};
|
use crate::commands::push::push_factory::{PushFactory, PushState};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
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::services::req_props::{ObjProps, ReqProps};
|
use crate::services::req_props::{ObjProps, 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;
|
||||||
@ -45,7 +46,7 @@ pub trait PushChange {
|
|||||||
.getlastmodified()
|
.getlastmodified()
|
||||||
.send_req_single();
|
.send_req_single();
|
||||||
|
|
||||||
let file_infos = match res {
|
let obj_data = match res {
|
||||||
Ok(obj) => Ok(Some(obj)),
|
Ok(obj) => Ok(Some(obj)),
|
||||||
Err(ApiError::IncorrectRequest(err)) => {
|
Err(ApiError::IncorrectRequest(err)) => {
|
||||||
if err.status() == 404 {
|
if err.status() == 404 {
|
||||||
@ -57,16 +58,21 @@ pub trait PushChange {
|
|||||||
Err(_) => Err(()),
|
Err(_) => Err(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let infos = match file_infos {
|
let obj_data = match obj_data {
|
||||||
Ok(Some(info)) => info,
|
Ok(Some(info)) => info,
|
||||||
Ok(None) => return PushFlowState::NotOnRemote,
|
Ok(None) => return PushFlowState::NotOnRemote,
|
||||||
Err(_) => return PushFlowState::Error,
|
Err(_) => return PushFlowState::Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if remote is newest
|
// check if remote is newest
|
||||||
// set timestamp from remote stuff
|
let last_sync_ts = object::get_timestamp(obj.path.to_str().unwrap().to_string()).unwrap();
|
||||||
// get from file
|
let remote_ts = obj_data.lastmodified.unwrap().timestamp_millis();
|
||||||
todo!()
|
|
||||||
|
if last_sync_ts < remote_ts {
|
||||||
|
PushFlowState::RemoteIsNewer
|
||||||
|
} else {
|
||||||
|
PushFlowState::LocalIsNewer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ use crypto::digest::Digest;
|
|||||||
use crypto::sha1::Sha1;
|
use crypto::sha1::Sha1;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
use crate::store::{self, object};
|
use crate::store::object::tree;
|
||||||
|
use crate::store::index;
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
enum RemoveSide {
|
enum RemoveSide {
|
||||||
@ -68,7 +69,7 @@ fn get_staged(objs: &mut Vec<LocalObj>) -> Vec<LocalObj> {
|
|||||||
let mut indexes = HashSet::new();
|
let mut indexes = HashSet::new();
|
||||||
let mut staged_objs: Vec<LocalObj> = vec![];
|
let mut staged_objs: Vec<LocalObj> = vec![];
|
||||||
|
|
||||||
if let Ok(entries) = store::index::read_line() {
|
if let Ok(entries) = index::read_line() {
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
indexes.insert(entry.unwrap());
|
indexes.insert(entry.unwrap());
|
||||||
}
|
}
|
||||||
@ -121,7 +122,7 @@ fn get_diff() -> (Vec<LocalObj>, Vec<LocalObj>) {
|
|||||||
let obj_path = root.clone().join(cur_path.clone());
|
let obj_path = root.clone().join(cur_path.clone());
|
||||||
|
|
||||||
if obj_path.is_dir() {
|
if obj_path.is_dir() {
|
||||||
if let Some((_, lines)) = object::read_tree(cur_obj.clone()) {
|
if let Some((_, lines)) = tree::read(cur_obj.clone()) {
|
||||||
add_to_hashmap(lines, &mut hashes, cur_path.clone());
|
add_to_hashmap(lines, &mut hashes, cur_path.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +172,7 @@ fn add_to_hashmap(lines: Lines<BufReader<File>>, hashes: &mut HashMap<String, Lo
|
|||||||
for line in lines {
|
for line in lines {
|
||||||
if let Ok(ip) = line {
|
if let Ok(ip) = line {
|
||||||
if ip.clone().len() > 5 {
|
if ip.clone().len() > 5 {
|
||||||
let (ftype, hash, name) = object::parse_line(ip);
|
let (ftype, hash, name) = tree::parse_line(ip);
|
||||||
let mut p = path.clone();
|
let mut p = path.clone();
|
||||||
p.push(name.clone());
|
p.push(name.clone());
|
||||||
hashes.insert(String::from(hash), LocalObj{
|
hashes.insert(String::from(hash), LocalObj{
|
||||||
|
@ -110,7 +110,7 @@ fn create_obj(name: String, content: &str) -> io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_timestamp(path_s: String) -> Option<String> {
|
pub fn get_timestamp(path_s: String) -> Option<i64> {
|
||||||
let mut obj_p = match path::objects() {
|
let mut obj_p = match path::objects() {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => todo!(),
|
None => todo!(),
|
||||||
@ -126,7 +126,7 @@ pub fn get_timestamp(path_s: String) -> Option<String> {
|
|||||||
Some(Ok(line)) => {
|
Some(Ok(line)) => {
|
||||||
let mut data = line.rsplit(' ');
|
let mut data = line.rsplit(' ');
|
||||||
if data.clone().count() >= 2 {
|
if data.clone().count() >= 2 {
|
||||||
Some(String::from(data.next().unwrap()))
|
Some(data.next().unwrap().parse::<i64>().unwrap())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user