push modification
This commit is contained in:
parent
f64d719b31
commit
498fada9ec
@ -6,6 +6,7 @@ use clap::Values;
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use crate::services::downloader::Downloader;
|
use crate::services::downloader::Downloader;
|
||||||
use crate::utils::api::ApiProps;
|
use crate::utils::api::ApiProps;
|
||||||
|
use crate::utils::path::path_buf_to_string;
|
||||||
use crate::utils::remote::{enumerate_remote, EnumerateOptions};
|
use crate::utils::remote::{enumerate_remote, EnumerateOptions};
|
||||||
use crate::global::global::{DIR_PATH, set_dir_path};
|
use crate::global::global::{DIR_PATH, set_dir_path};
|
||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
@ -46,7 +47,7 @@ pub fn clone(args: CloneArgs) {
|
|||||||
let iter = Path::new(dist_path_str).iter();
|
let iter = Path::new(dist_path_str).iter();
|
||||||
let dest_dir = iter.last().unwrap();
|
let dest_dir = iter.last().unwrap();
|
||||||
let lp = std::env::current_dir().unwrap().join(dest_dir);
|
let lp = std::env::current_dir().unwrap().join(dest_dir);
|
||||||
set_dir_path(lp.to_str().unwrap().to_string());
|
set_dir_path(path_buf_to_string(lp.clone()));
|
||||||
lp
|
lp
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -93,7 +94,7 @@ pub fn clone(args: CloneArgs) {
|
|||||||
let downloader = Downloader::new()
|
let downloader = Downloader::new()
|
||||||
.set_api_props(api_props.clone())
|
.set_api_props(api_props.clone())
|
||||||
.set_files(files)
|
.set_files(files)
|
||||||
.should_log()
|
//.should_log()
|
||||||
.download(ref_path.clone(), Some(&save_blob));
|
.download(ref_path.clone(), Some(&save_blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use crate::commands::{status, config};
|
use crate::commands::{status, config};
|
||||||
use crate::commands::push::push_factory::{PushFactory, PushState};
|
use crate::commands::push::push_factory::{PushFactory, PushState};
|
||||||
|
use crate::store::index;
|
||||||
|
|
||||||
|
use super::status::LocalObj;
|
||||||
|
|
||||||
pub mod push_factory;
|
pub mod push_factory;
|
||||||
pub mod new;
|
pub mod new;
|
||||||
pub mod new_dir;
|
pub mod new_dir;
|
||||||
pub mod rm_dir;
|
pub mod rm_dir;
|
||||||
pub mod deleted;
|
pub mod deleted;
|
||||||
|
pub mod modified;
|
||||||
|
|
||||||
pub fn push() {
|
pub fn push() {
|
||||||
// todo err when pushing new folder
|
// todo err when pushing new folder
|
||||||
@ -52,20 +56,24 @@ pub fn push() {
|
|||||||
match push_factory.can_push(&mut whitelist) {
|
match push_factory.can_push(&mut whitelist) {
|
||||||
PushState::Valid => {
|
PushState::Valid => {
|
||||||
match push_factory.push() {
|
match push_factory.push() {
|
||||||
Ok(()) => (),
|
Ok(()) => remove_obj_from_index(obj.clone()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("err: pushing {}: {}", obj.name, err);
|
eprintln!("err: pushing {}: {}", obj.name, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
PushState::Done => (),
|
PushState::Done => remove_obj_from_index(obj.clone()),
|
||||||
PushState::Conflict => {
|
PushState::Conflict => {
|
||||||
// download file
|
// download file
|
||||||
}
|
}
|
||||||
_ => todo!(),
|
PushState::Error => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// read index
|
}
|
||||||
// if dir upload dir
|
|
||||||
|
fn remove_obj_from_index(obj: LocalObj) {
|
||||||
|
if let Err(err) = index::rm_line(obj.path.to_str().unwrap()) {
|
||||||
|
eprintln!("err: removing {} from index: {}", obj.name, err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
79
src/commands/push/modified.rs
Normal file
79
src/commands/push/modified.rs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
use std::io;
|
||||||
|
use crate::services::api::ApiError;
|
||||||
|
use crate::services::req_props::ReqProps;
|
||||||
|
use crate::services::upload_file::UploadFile;
|
||||||
|
use crate::commands::status::LocalObj;
|
||||||
|
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
||||||
|
use crate::store::object::blob::Blob;
|
||||||
|
|
||||||
|
pub struct Modified {
|
||||||
|
pub obj: LocalObj,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PushChange for Modified {
|
||||||
|
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState {
|
||||||
|
match self.flow(&self.obj, whitelist.clone()) {
|
||||||
|
PushFlowState::Whitelisted => PushState::Done,
|
||||||
|
PushFlowState::NotOnRemote => PushState::Valid,
|
||||||
|
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||||
|
PushFlowState::LocalIsNewer => PushState::Valid,
|
||||||
|
PushFlowState::Error => PushState::Error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn push(&self) -> io::Result<()> {
|
||||||
|
let obj = &self.obj;
|
||||||
|
let res = UploadFile::new()
|
||||||
|
.set_url(obj.path.to_str().unwrap())
|
||||||
|
.set_file(obj.path.clone())
|
||||||
|
.send_with_err();
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Err(ApiError::IncorrectRequest(err)) => {
|
||||||
|
eprintln!("fatal: error pushing file {}: {}", obj.name, err.status());
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
|
Err(ApiError::RequestError(_)) => {
|
||||||
|
eprintln!("fatal: request error pushing file {}", obj.name);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
// get lastmodified props to update it
|
||||||
|
let props = ReqProps::new()
|
||||||
|
.set_url(obj.path.to_str().unwrap())
|
||||||
|
.getlastmodified()
|
||||||
|
.send_req_single();
|
||||||
|
|
||||||
|
let prop = match props {
|
||||||
|
Ok(o) => o,
|
||||||
|
Err(ApiError::IncorrectRequest(err)) => {
|
||||||
|
eprintln!("fatal: {}", err.status());
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
|
Err(ApiError::EmptyError(_)) => {
|
||||||
|
eprintln!("Failed to get body");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
Err(ApiError::RequestError(err)) => {
|
||||||
|
eprintln!("fatal: {}", err);
|
||||||
|
std::process::exit(1);
|
||||||
|
},
|
||||||
|
Err(ApiError::Unexpected(_)) => todo!()
|
||||||
|
};
|
||||||
|
|
||||||
|
let lastmodified = prop.lastmodified.unwrap().timestamp_millis();
|
||||||
|
|
||||||
|
// update blob
|
||||||
|
Blob::new(obj.path.clone()).update(&lastmodified.to_string())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// download file with .distant at the end
|
||||||
|
fn conflict(&self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ use std::io;
|
|||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
use crate::services::req_props::ReqProps;
|
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::object::blob::Blob;
|
use crate::store::object::blob::Blob;
|
||||||
use crate::commands::status::LocalObj;
|
use crate::commands::status::LocalObj;
|
||||||
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
||||||
@ -70,9 +69,6 @@ impl PushChange for New {
|
|||||||
// create new blob
|
// create new blob
|
||||||
Blob::new(obj.path.clone()).create(&lastmodified.to_string(), true)?;
|
Blob::new(obj.path.clone()).create(&lastmodified.to_string(), true)?;
|
||||||
|
|
||||||
// remove index
|
|
||||||
index::rm_line(obj.path.to_str().unwrap())?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ 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;
|
||||||
use crate::commands::push::deleted::Deleted;
|
use crate::commands::push::deleted::Deleted;
|
||||||
|
use crate::commands::push::modified::Modified;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PushState {
|
pub enum PushState {
|
||||||
@ -54,6 +55,7 @@ pub trait PushChange {
|
|||||||
if err.status() == 404 {
|
if err.status() == 404 {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
|
eprintln!("err: when requesting properties of {} ({})", obj.name, err.status());
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -84,7 +86,7 @@ impl PushFactory {
|
|||||||
pub fn new(&self, obj: LocalObj) -> Box<dyn PushChange> {
|
pub fn new(&self, obj: LocalObj) -> Box<dyn PushChange> {
|
||||||
match obj.state {
|
match obj.state {
|
||||||
State::New => Box::new(New { obj }),
|
State::New => Box::new(New { obj }),
|
||||||
State::Modified => todo!(),
|
State::Modified => Box::new(Modified { obj }),
|
||||||
State::Deleted => Box::new(Deleted { obj }),
|
State::Deleted => Box::new(Deleted { obj }),
|
||||||
State::Default => todo!(),
|
State::Default => todo!(),
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
|
@ -134,12 +134,24 @@ 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, mut objs_modified) = get_diff();
|
let mut lines: Vec<String> = vec![];
|
||||||
// get copy, modified
|
|
||||||
let staged_objs = get_staged(&mut new_objs_hashes);
|
|
||||||
|
|
||||||
staged_objs.clone()
|
if let Ok(entries) = index::read_line() {
|
||||||
// todo opti getting staged and then finding differences ?
|
for entry in entries {
|
||||||
|
lines.push(entry.unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut staged_objs = vec![];
|
||||||
|
|
||||||
|
for line in lines {
|
||||||
|
let obj = Blob::new(PathBuf::from(line)).get_local_obj();
|
||||||
|
if obj.state != State::Default {
|
||||||
|
staged_objs.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
staged_objs
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_staged(hashes: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
fn get_staged(hashes: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
||||||
|
@ -222,6 +222,7 @@ fn create_obj(name: String, content: &str) -> io::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the last time a blob synced with remote
|
||||||
pub fn get_timestamp(path_s: String) -> Option<i64> {
|
pub fn get_timestamp(path_s: String) -> Option<i64> {
|
||||||
let mut obj_p = path::objects();
|
let mut obj_p = path::objects();
|
||||||
|
|
||||||
@ -235,7 +236,7 @@ pub fn get_timestamp(path_s: String) -> Option<i64> {
|
|||||||
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(data.next().unwrap().parse::<i64>().unwrap())
|
Some(data.nth_back(1).unwrap().parse::<i64>().unwrap())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
use std::fs::File;
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use std::fs;
|
|
||||||
use crypto::sha1::Sha1;
|
use crypto::sha1::Sha1;
|
||||||
use crypto::digest::Digest;
|
use crypto::digest::Digest;
|
||||||
|
use crate::commands::status::{LocalObj, State};
|
||||||
|
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;
|
||||||
use crate::store::object::{update_dates, add_node, rm_node};
|
use crate::store::object::{update_dates, add_node, rm_node};
|
||||||
@ -82,7 +83,6 @@ impl Blob {
|
|||||||
content.push_str(&secs.to_string());
|
content.push_str(&secs.to_string());
|
||||||
content.push_str(" ");
|
content.push_str(" ");
|
||||||
content.push_str(&self.get_file_hash());
|
content.push_str(&self.get_file_hash());
|
||||||
content.push_str(" ");
|
|
||||||
|
|
||||||
let binding = self.obj_p.clone();
|
let binding = self.obj_p.clone();
|
||||||
let child = binding.file_name();
|
let child = binding.file_name();
|
||||||
@ -118,6 +118,7 @@ impl Blob {
|
|||||||
// create a file in .nextsync/refs with the hash of this blob that
|
// create a file in .nextsync/refs with the hash of this blob that
|
||||||
// redirect to the relative path
|
// redirect to the relative path
|
||||||
fn create_hash_ref(&mut self) -> io::Result<()> {
|
fn create_hash_ref(&mut self) -> io::Result<()> {
|
||||||
|
// todo check if the file has been modified for moved and copy
|
||||||
let refs_p = self.get_file_ref();
|
let refs_p = self.get_file_ref();
|
||||||
|
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
@ -126,7 +127,6 @@ impl Blob {
|
|||||||
.open(refs_p)?;
|
.open(refs_p)?;
|
||||||
|
|
||||||
// todo deal with duplicate content
|
// todo deal with duplicate content
|
||||||
|
|
||||||
writeln!(file, "{}", self.r_path.clone().to_str().unwrap())?;
|
writeln!(file, "{}", self.r_path.clone().to_str().unwrap())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -186,6 +186,50 @@ impl Blob {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update(&mut self, ts_remote: &str) -> io::Result<()> {
|
||||||
|
|
||||||
|
// remove old hash ref
|
||||||
|
let mut refs_p = path::refs();
|
||||||
|
let binding = self.saved_hash();
|
||||||
|
let (dir, res) = binding.split_at(2);
|
||||||
|
refs_p.push(dir);
|
||||||
|
refs_p.push(res);
|
||||||
|
if let Err(err) = fs::remove_file(refs_p) {
|
||||||
|
eprintln!("err: removing hash ref of {}: {}", self.r_path.clone().display(), err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// creating new hash ref
|
||||||
|
if let Err(err) = self.create_hash_ref() {
|
||||||
|
eprintln!("err: saving hash ref of {}: {}", self.r_path.clone().display(), err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// updating content of blob's ref
|
||||||
|
let metadata = fs::metadata(self.a_path.clone())?;
|
||||||
|
let secs = metadata
|
||||||
|
.modified()
|
||||||
|
.unwrap()
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
let mut content = self.saved_filename();
|
||||||
|
content.push_str(" ");
|
||||||
|
content.push_str(ts_remote);
|
||||||
|
content.push_str(" ");
|
||||||
|
content.push_str(&metadata.len().to_string());
|
||||||
|
content.push_str(" ");
|
||||||
|
content.push_str(&secs.to_string());
|
||||||
|
content.push_str(" ");
|
||||||
|
content.push_str(&self.get_file_hash());
|
||||||
|
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.open(self.obj_p.clone())?;
|
||||||
|
|
||||||
|
writeln!(file, "{}", &content)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read_data(&mut self) {
|
pub fn read_data(&mut self) {
|
||||||
if self.data.len() == 0 {
|
if self.data.len() == 0 {
|
||||||
if let Ok(mut file) = File::open(self.obj_p.clone()) {
|
if let Ok(mut file) = File::open(self.obj_p.clone()) {
|
||||||
@ -196,9 +240,60 @@ impl Blob {
|
|||||||
self.data.push(String::from(e));
|
self.data.push(String::from(e));
|
||||||
}
|
}
|
||||||
self.data.reverse();
|
self.data.reverse();
|
||||||
|
|
||||||
|
if let Some(last) = self.data.last_mut() {
|
||||||
|
if last.ends_with("\n") {
|
||||||
|
last.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn saved_filename(&mut self) -> String {
|
||||||
|
self.read_data();
|
||||||
|
if self.data.len() >= 1 {
|
||||||
|
self.data[0].clone()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn saved_remote_ts(&mut self) -> String {
|
||||||
|
self.read_data();
|
||||||
|
if self.data.len() >= 2 {
|
||||||
|
self.data[1].clone()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn saved_local_size(&mut self) -> String {
|
||||||
|
self.read_data();
|
||||||
|
if self.data.len() >= 3 {
|
||||||
|
self.data[2].clone()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn saved_local_ts(&mut self) -> u64 {
|
||||||
|
self.read_data();
|
||||||
|
if self.data.len() >= 4 {
|
||||||
|
self.data[3].parse::<u64>().unwrap()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn saved_hash(&mut self) -> String {
|
||||||
|
self.read_data();
|
||||||
|
if self.data.len() >= 5 {
|
||||||
|
self.data[4].clone()
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn has_same_size(&mut self) -> bool {
|
fn has_same_size(&mut self) -> bool {
|
||||||
let metadata = match fs::metadata(self.a_path.clone()) {
|
let metadata = match fs::metadata(self.a_path.clone()) {
|
||||||
@ -206,9 +301,8 @@ impl Blob {
|
|||||||
Err(_) => return true,
|
Err(_) => return true,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.read_data();
|
if self.saved_local_size() == String::new() { return true; }
|
||||||
if self.data.len() < 3 { return true; }
|
metadata.len().to_string() == self.saved_local_size()
|
||||||
metadata.len().to_string() == self.data[2]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_newer(&mut self) -> bool {
|
fn is_newer(&mut self) -> bool {
|
||||||
@ -217,26 +311,57 @@ impl Blob {
|
|||||||
Err(_) => return true,
|
Err(_) => return true,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.read_data();
|
|
||||||
let secs = metadata
|
let secs = metadata
|
||||||
.modified()
|
.modified()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs();
|
.as_secs();
|
||||||
if self.data.len() < 4 { return true; }
|
if self.saved_local_ts() == 0 { return true; }
|
||||||
secs > self.data[3].parse::<u64>().unwrap()
|
secs > self.saved_local_ts()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_same_hash(&mut self) -> bool {
|
fn has_same_hash(&mut self) -> bool {
|
||||||
self.read_data();
|
self.read_data();
|
||||||
if self.data.len() < 5 { return false; }
|
if self.saved_hash() == String::new() { return false; }
|
||||||
let file_hash = self.get_file_hash().clone();
|
let file_hash = self.get_file_hash().clone();
|
||||||
self.data[4] == file_hash
|
self.saved_hash() == file_hash
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_change(&mut self) -> bool {
|
pub fn has_change(&mut self) -> bool {
|
||||||
!self.has_same_size() || (self.is_newer() && !self.has_same_hash())
|
!self.has_same_size() || (self.is_newer() && !self.has_same_hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_local_obj(&mut self) -> LocalObj {
|
||||||
|
let state = {
|
||||||
|
let has_obj_ref = self.obj_p.clone().exists();
|
||||||
|
let blob_exists = self.a_path.clone().exists();
|
||||||
|
if has_obj_ref && !blob_exists {
|
||||||
|
State::Deleted
|
||||||
|
} else if !has_obj_ref && blob_exists {
|
||||||
|
State::New
|
||||||
|
} else if !has_obj_ref && !blob_exists {
|
||||||
|
State::Default
|
||||||
|
} else if self.has_change() {
|
||||||
|
// todo
|
||||||
|
if false {
|
||||||
|
State::Moved
|
||||||
|
} else if false {
|
||||||
|
State::Copied
|
||||||
|
} else {
|
||||||
|
State::Modified
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
State::Default
|
||||||
|
}
|
||||||
|
};
|
||||||
|
LocalObj {
|
||||||
|
otype: String::from("blob"),
|
||||||
|
name: path_buf_to_string(self.r_path.clone()),
|
||||||
|
path: self.r_path.clone(),
|
||||||
|
path_from: None,
|
||||||
|
state
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user