Compare commits
No commits in common. "b74c5c176bc283937845c2fabd1d76c701279bc7" and "a1aeb65600cb1452799301807f74d20cb8e50616" have entirely different histories.
b74c5c176b
...
a1aeb65600
@ -1,5 +1,3 @@
|
||||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::fs::DirBuilder;
|
||||
use std::path::{Path, PathBuf};
|
||||
use clap::Values;
|
||||
@ -18,16 +16,15 @@ pub fn clone(remote: Values<'_>) {
|
||||
let url = remote.clone().next().unwrap();
|
||||
let (host, tmp_user, dist_path_str) = get_url_props(url);
|
||||
let username = match tmp_user {
|
||||
Some(u) => u.to_string(),
|
||||
Some(u) => u,
|
||||
None => {
|
||||
println!("Please enter the username of the webdav instance: ");
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().lines().next().unwrap().unwrap()
|
||||
eprintln!("No username found");
|
||||
todo!();
|
||||
}
|
||||
};
|
||||
let api_props = ApiProps {
|
||||
host: host.clone(),
|
||||
username: username,
|
||||
username: username.to_string(),
|
||||
root: dist_path_str.to_string(),
|
||||
};
|
||||
|
||||
@ -60,7 +57,7 @@ pub fn clone(remote: Values<'_>) {
|
||||
.getlastmodified()
|
||||
.send_req_multiple();
|
||||
|
||||
let objs = match res {
|
||||
let mut objs = match res {
|
||||
Ok(o) => o,
|
||||
Err(ApiError::IncorrectRequest(err)) => {
|
||||
eprintln!("fatal: {}", err.status());
|
||||
@ -79,9 +76,10 @@ pub fn clone(remote: Values<'_>) {
|
||||
|
||||
// create folder
|
||||
if first_iter {
|
||||
if DirBuilder::new().recursive(true).create(ref_path.clone()).is_err() {
|
||||
eprintln!("fatal: unable to create the destination directory");
|
||||
std::process::exit(1);
|
||||
if DirBuilder::new().create(ref_path.clone()).is_err() {
|
||||
eprintln!("fatal: directory already exist");
|
||||
// destination path 'path' already exists and is not an empty directory.
|
||||
//std::process::exit(1);
|
||||
} else {
|
||||
init::init();
|
||||
}
|
||||
|
@ -3,7 +3,13 @@ use std::io::{self, Write};
|
||||
use crate::utils::{path, read};
|
||||
|
||||
pub fn set(var: &str, val: &str) -> io::Result<()> {
|
||||
let mut root = path::nextsync();
|
||||
let mut root = match path::nextsync() {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
root.push("config");
|
||||
|
||||
// todo check if exist
|
||||
@ -22,7 +28,13 @@ pub fn set(var: &str, val: &str) -> io::Result<()> {
|
||||
}
|
||||
|
||||
pub fn get(var: &str) -> Option<String> {
|
||||
let mut root = path::nextsync();
|
||||
let mut root = match path::nextsync() {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
root.push("config");
|
||||
|
||||
if let Ok(lines) = read::read_lines(root) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::env;
|
||||
use std::fs::{DirBuilder, File};
|
||||
use std::path::PathBuf;
|
||||
use crate::utils::read::read_folder;
|
||||
use crate::global::global::DIR_PATH;
|
||||
|
||||
pub fn init() {
|
||||
@ -11,44 +10,34 @@ pub fn init() {
|
||||
Some(dir) => PathBuf::from(dir),
|
||||
None => env::current_dir().unwrap(),
|
||||
};
|
||||
|
||||
// check if dir is empty
|
||||
if let Ok(entries) = read_folder(path.clone()) {
|
||||
if entries.len() != 0 {
|
||||
eprintln!("fatal: destination path '{}' already exists and is not an empty directory.", path.display());
|
||||
std::process::exit(1);
|
||||
}
|
||||
} else {
|
||||
eprintln!("fatal: cannot open the destination directory");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let builder = DirBuilder::new();
|
||||
// todo check if dir empty
|
||||
|
||||
// .nextsync folder
|
||||
path.push(".nextsync");
|
||||
match builder.create(path.clone()) {
|
||||
Ok(()) => (),
|
||||
Err(_) => println!("Error: cannot create .nextsync"),
|
||||
Err(_) => println!("Error: cannot create directory"),
|
||||
};
|
||||
|
||||
path.push("objects");
|
||||
match builder.create(path.clone()) {
|
||||
Ok(()) => (),
|
||||
Err(_) => println!("Error: cannot create objects"),
|
||||
Err(_) => println!("Error: cannot create directory"),
|
||||
};
|
||||
path.pop();
|
||||
|
||||
path.push("HEAD");
|
||||
match File::create(path.clone()) {
|
||||
Ok(_) => (),
|
||||
Err(_) => println!("Error: cannot create HEAD"),
|
||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
||||
}
|
||||
|
||||
path.pop();
|
||||
path.push("index");
|
||||
match File::create(path.clone()) {
|
||||
Ok(_) => (),
|
||||
Err(_) => println!("Error: cannot create index"),
|
||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
||||
}
|
||||
|
||||
path.pop();
|
||||
|
@ -1,11 +1,18 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::upload_file::UploadFile;
|
||||
use crate::services::delete_path::DeletePath;
|
||||
use crate::services::req_props::{ReqProps, ObjProps};
|
||||
use crate::store::index;
|
||||
use crate::store::object::blob;
|
||||
use crate::commands::{status, config};
|
||||
use crate::commands::status::{State, LocalObj};
|
||||
use crate::commands::push::push_factory::{PushFactory, PushState};
|
||||
|
||||
pub mod push_factory;
|
||||
pub mod new;
|
||||
pub mod new_dir;
|
||||
pub mod deleted;
|
||||
//pub mod new_dir;
|
||||
//pub mod deleted;
|
||||
|
||||
pub fn push() {
|
||||
dbg!(status::get_all_staged());
|
||||
@ -20,27 +27,30 @@ pub fn push() {
|
||||
};
|
||||
|
||||
let staged_objs = status::get_all_staged();
|
||||
// todo sort folder first
|
||||
|
||||
// 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
|
||||
// can be pushed without verification)
|
||||
let mut whitelist: Option<PathBuf> = None;
|
||||
let whitelist: Option<&Path> = None;
|
||||
|
||||
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 = match push_factory.can_push(&mut whitelist) {
|
||||
PushState::Valid => push_factory.push(),
|
||||
PushState::Done => (),
|
||||
PushState::Conflict => (),
|
||||
_ => todo!(),
|
||||
};
|
||||
//let push_factory = PushFactory.new_dir(obj.clone());
|
||||
//let res = match push_factory.can_push(whitelist.clone()) {
|
||||
// PushState::Valid => push_factory.push(),
|
||||
// PushState::Done => (),
|
||||
// PushState::Conflict => (),
|
||||
// _ => todo!(),
|
||||
//};
|
||||
|
||||
//match res {
|
||||
//
|
||||
//}
|
||||
//dbg!("should push folder");
|
||||
} else {
|
||||
dbg!(("file", obj.clone()));
|
||||
let push_factory = PushFactory.new(obj.clone());
|
||||
match push_factory.can_push(&mut whitelist) {
|
||||
match push_factory.can_push(whitelist.clone()) {
|
||||
PushState::Valid => push_factory.push(),
|
||||
PushState::Done => (),
|
||||
PushState::Conflict => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::services::delete_path::DeletePath;
|
||||
@ -12,8 +12,8 @@ pub struct Deleted {
|
||||
}
|
||||
|
||||
impl PushChange for Deleted {
|
||||
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState {
|
||||
match self.flow(&self.obj, whitelist.clone()) {
|
||||
fn can_push(&self, whitelist: Option<&Path>) -> PushState {
|
||||
match self.flow(&self.obj, whitelist) {
|
||||
PushFlowState::Whitelisted => PushState::Done,
|
||||
PushFlowState::NotOnRemote => PushState::Done,
|
||||
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::upload_file::UploadFile;
|
||||
use crate::store::index;
|
||||
@ -11,8 +11,8 @@ pub struct New {
|
||||
}
|
||||
|
||||
impl PushChange for New {
|
||||
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState {
|
||||
match self.flow(&self.obj, whitelist.clone()) {
|
||||
fn can_push(&self, whitelist: Option<&Path>) -> PushState {
|
||||
match self.flow(&self.obj, whitelist) {
|
||||
PushFlowState::Whitelisted => PushState::Valid,
|
||||
PushFlowState::NotOnRemote => PushState::Valid,
|
||||
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||
|
@ -1,57 +0,0 @@
|
||||
use std::path::PathBuf;
|
||||
use crate::services::api::ApiError;
|
||||
use crate::services::req_props::ReqProps;
|
||||
use crate::services::create_folder::CreateFolder;
|
||||
use crate::store::index;
|
||||
use crate::store::object::tree;
|
||||
use crate::commands::status::LocalObj;
|
||||
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
|
||||
|
||||
pub struct NewDir {
|
||||
pub obj: LocalObj
|
||||
}
|
||||
|
||||
impl PushChange for NewDir {
|
||||
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState {
|
||||
match self.flow(&self.obj, whitelist.clone()) {
|
||||
PushFlowState::Whitelisted => PushState::Valid,
|
||||
PushFlowState::NotOnRemote => {
|
||||
*whitelist = Some(self.obj.path.clone());
|
||||
PushState::Valid
|
||||
},
|
||||
PushFlowState::RemoteIsNewer => PushState::Conflict,
|
||||
PushFlowState::LocalIsNewer => {
|
||||
*whitelist = Some(self.obj.path.clone());
|
||||
PushState::Done
|
||||
},
|
||||
PushFlowState::Error => PushState::Error,
|
||||
}
|
||||
}
|
||||
|
||||
fn push(&self) {
|
||||
let obj = &self.obj;
|
||||
let res = CreateFolder::new()
|
||||
.set_url(obj.path.to_str().unwrap())
|
||||
.send_with_err();
|
||||
|
||||
match res {
|
||||
Err(ApiError::IncorrectRequest(err)) => {
|
||||
eprintln!("fatal: error creating folder {}: {}", obj.name, err.status());
|
||||
std::process::exit(1);
|
||||
},
|
||||
Err(ApiError::RequestError(_)) => {
|
||||
eprintln!("fatal: request error creating folder {}", obj.name);
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// update tree
|
||||
tree::add(&obj.path.clone(), "todo_date");
|
||||
|
||||
// remove index
|
||||
index::rm_line(obj.path.to_str().unwrap());
|
||||
}
|
||||
|
||||
fn conflict(&self) {}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use crate::commands::status::{State, LocalObj};
|
||||
use crate::services::api::ApiError;
|
||||
use crate::store::object;
|
||||
use crate::services::req_props::{ObjProps, ReqProps};
|
||||
use crate::commands::push::new::New;
|
||||
use crate::commands::push::new_dir::NewDir;
|
||||
use crate::commands::push::deleted::Deleted;
|
||||
//use crate::commands::push::new_dir::NewDir;
|
||||
//use crate::commands::push::deleted::Deleted;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PushState {
|
||||
@ -24,27 +24,18 @@ pub enum PushFlowState {
|
||||
}
|
||||
|
||||
pub trait PushChange {
|
||||
fn can_push(&self, whitelist: &mut Option<PathBuf>) -> PushState;
|
||||
fn can_push(&self, whitelist: Option<&Path>) -> PushState;
|
||||
fn try_push(&self, whitelist: Option<&Path>);
|
||||
fn push(&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<&Path>) -> bool {
|
||||
match path {
|
||||
Some(p) => obj.path.starts_with(p),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn flow(&self, obj: &LocalObj, whitelist: Option<PathBuf>) -> PushFlowState {
|
||||
fn flow(&self, obj: &LocalObj, whitelist: Option<&Path>) -> PushFlowState {
|
||||
if self.is_whitelisted(obj, whitelist) {
|
||||
return PushFlowState::Whitelisted;
|
||||
}
|
||||
@ -93,14 +84,16 @@ impl PushFactory {
|
||||
State::New => Box::new(New { obj }),
|
||||
State::Renamed => todo!(),
|
||||
State::Modified => todo!(),
|
||||
State::Deleted => Box::new(Deleted { obj }),
|
||||
State::Deleted => todo!(),
|
||||
//State::Deleted => Box::new(Deleted {}),
|
||||
State::Default => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_dir(&self, obj: LocalObj) -> Box<dyn PushChange> {
|
||||
match obj.state {
|
||||
State::New => Box::new(NewDir { obj }),
|
||||
//State::New => Box::new(NewDir {}),
|
||||
State::New => todo!(),
|
||||
State::Renamed => todo!(),
|
||||
State::Modified => todo!(),
|
||||
State::Deleted => todo!(),
|
||||
|
@ -2,7 +2,14 @@ use std::fs::File;
|
||||
use crate::utils;
|
||||
|
||||
pub fn reset() {
|
||||
let mut root = utils::path::nextsync();
|
||||
let mut root = match utils::path::nextsync_root() {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
root.push(".nextsync");
|
||||
root.push("index");
|
||||
if File::create(root).is_err() {
|
||||
eprintln!("fatal: failed to reset");
|
||||
|
@ -26,7 +26,6 @@ pub enum State {
|
||||
}
|
||||
|
||||
// todo: relative path, filename, get modified
|
||||
// todo: not catch added empty folder
|
||||
pub fn status() {
|
||||
let (mut new_objs, mut del_objs) = get_diff();
|
||||
dbg!(get_diff());
|
||||
@ -52,7 +51,7 @@ pub fn get_all_staged() -> Vec<LocalObj> {
|
||||
// todo opti return folder
|
||||
let (mut new_objs, mut del_objs) = get_diff();
|
||||
let mut renamed_objs = get_renamed(&mut new_objs, &mut del_objs);
|
||||
// todo get copy, modified
|
||||
// get copy, modified
|
||||
let mut objs = new_objs;
|
||||
objs.append(&mut del_objs);
|
||||
objs.append(&mut renamed_objs);
|
||||
@ -92,11 +91,16 @@ fn get_diff() -> (Vec<LocalObj>, Vec<LocalObj>) {
|
||||
let mut hashes = HashMap::new();
|
||||
let mut objs: Vec<String> = vec![];
|
||||
|
||||
let root = utils::path::repo_root();
|
||||
|
||||
let root = match utils::path::nextsync_root() {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
dbg!(utils::path::current());
|
||||
let nextsync_path = utils::path::nextsync();
|
||||
let nextsync_path = utils::path::nextsync().unwrap();
|
||||
let current_p = utils::path::current().unwrap();
|
||||
let dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf();
|
||||
|
||||
@ -274,7 +278,7 @@ fn remove_duplicate(hashes: &mut HashMap<String, LocalObj>, objects: &mut Vec<St
|
||||
}
|
||||
|
||||
fn is_nextsync_config(path: PathBuf) -> bool {
|
||||
path.ends_with(".nextsync")
|
||||
path.ends_with(".nextsync") || path.ends_with(".nextsyncignore")
|
||||
}
|
||||
|
||||
fn read_head(mut path: PathBuf) -> io::Result<io::Lines<io::BufReader<File>>> {
|
||||
|
@ -1,5 +1,4 @@
|
||||
pub mod api;
|
||||
pub mod create_folder;
|
||||
pub mod download_files;
|
||||
pub mod req_props;
|
||||
pub mod upload_file;
|
||||
|
@ -2,7 +2,7 @@ use std::env;
|
||||
use dotenv::dotenv;
|
||||
use reqwest::Client;
|
||||
use reqwest::RequestBuilder;
|
||||
use reqwest::{Response, Error, Method};
|
||||
use reqwest::{Response, Error, IntoUrl, Method};
|
||||
use crate::utils::api::ApiProps;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -26,6 +26,11 @@ impl ApiBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_request<U: IntoUrl>(&mut self, method: Method, url: U) -> &mut ApiBuilder {
|
||||
self.request = Some(self.client.request(method, url));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build_request(&mut self, method: Method, path: &str) -> &mut ApiBuilder {
|
||||
dotenv().ok();
|
||||
// todo remove env
|
||||
|
@ -1,4 +1,4 @@
|
||||
use reqwest::{Method, Response, Error};
|
||||
use reqwest::{Method, IntoUrl, Response, Error};
|
||||
use crate::services::api::{ApiBuilder, ApiError};
|
||||
|
||||
pub struct CreateFolder {
|
||||
@ -6,27 +6,21 @@ pub struct CreateFolder {
|
||||
}
|
||||
|
||||
impl CreateFolder {
|
||||
pub fn new() -> Self {
|
||||
CreateFolder {
|
||||
api_builder: ApiBuilder::new(),
|
||||
pub fn new<U: IntoUrl>(url: U) -> Self {
|
||||
ListFolders {
|
||||
api_builder: ApiBuilder::new()
|
||||
.set_request(Method::from_bytes(b"MKCOL").unwrap(), url),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_url(&mut self, url: &str) -> &mut CreateFolder {
|
||||
self.api_builder.build_request(Method::from_bytes(b"MKCOL").unwrap(), url);
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn send(&mut self) -> Result<Response, Error> {
|
||||
self.api_builder.send().await
|
||||
}
|
||||
|
||||
pub fn send_with_err(&mut self) -> Result<(), ApiError> {
|
||||
let res = tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
self.send().await
|
||||
}).map_err(ApiError::RequestError)?;
|
||||
pub async fn send_with_err(mut self) -> Result<(), ApiError> {
|
||||
let res = self.send().await.map_err(ApiError::RequestError)?;
|
||||
if res.status().is_success() {
|
||||
Ok(())
|
||||
Ok()
|
||||
} else {
|
||||
Err(ApiError::IncorrectRequest(res))
|
||||
}
|
||||
|
@ -3,8 +3,35 @@ use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Write};
|
||||
use crate::utils::{read, path};
|
||||
|
||||
pub fn _read_only(mut path: PathBuf) -> File {
|
||||
path.push("HEAD");
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.open(path).expect("Cannot open HEAD file")
|
||||
}
|
||||
|
||||
pub fn _open(mut path: PathBuf) -> File {
|
||||
path.push("HEAD");
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(path).expect("Cannot open HEAD file")
|
||||
}
|
||||
|
||||
pub fn _read_line(mut path: PathBuf) -> io::Result<io::Lines<io::BufReader<File>>> {
|
||||
path.push("HEAD");
|
||||
read::read_lines(path)
|
||||
}
|
||||
|
||||
pub fn add_line(line: String) -> io::Result<()> {
|
||||
let mut root = path::nextsync();
|
||||
let mut root = match path::nextsync_root() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
root.push(".nextsync");
|
||||
root.push("HEAD");
|
||||
|
||||
let mut file = OpenOptions::new()
|
||||
@ -18,7 +45,12 @@ pub fn add_line(line: String) -> io::Result<()> {
|
||||
}
|
||||
|
||||
pub fn rm_line(line: &str) -> io::Result<()> {
|
||||
let mut root = path::nextsync();
|
||||
let mut root = match path::nextsync_root() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
root.push(".nextsync");
|
||||
root.push("HEAD");
|
||||
read::rm_line(root, line)?;
|
||||
Ok(())
|
||||
|
@ -4,8 +4,18 @@ use std::fs::OpenOptions;
|
||||
use std::path::PathBuf;
|
||||
use crate::utils::{read, path};
|
||||
|
||||
pub fn _read_only(mut path: PathBuf) -> File {
|
||||
path.push("index");
|
||||
OpenOptions::new()
|
||||
.read(true)
|
||||
.open(path).expect("Cannot open index file")
|
||||
}
|
||||
|
||||
pub fn open() -> File {
|
||||
let mut path = path::nextsync();
|
||||
let mut path = match path::nextsync() {
|
||||
Some(p) => p,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
path.push("index");
|
||||
OpenOptions::new()
|
||||
@ -17,13 +27,20 @@ pub fn open() -> File {
|
||||
}
|
||||
|
||||
pub fn read_line() -> io::Result<io::Lines<io::BufReader<File>>> {
|
||||
let mut path = path::nextsync();
|
||||
let mut path = match path::nextsync() {
|
||||
Some(p) => p,
|
||||
None => todo!(),
|
||||
};
|
||||
path.push("index");
|
||||
read::read_lines(path)
|
||||
}
|
||||
|
||||
pub fn rm_line(line: &str) -> io::Result<()> {
|
||||
let mut root = path::nextsync();
|
||||
let mut root = match path::nextsync() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
root.push("index");
|
||||
read::rm_line(root, line)?;
|
||||
Ok(())
|
||||
|
@ -37,16 +37,23 @@ fn hash_obj(obj: &str) -> (String, String) {
|
||||
}
|
||||
|
||||
fn _object_path(obj: &str) -> PathBuf {
|
||||
let mut root = path::objects();
|
||||
let mut root = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let (dir, res) = hash_obj(&obj);
|
||||
|
||||
root.push(dir);
|
||||
root.push(res);
|
||||
root
|
||||
}
|
||||
|
||||
fn rm_node(path: &Path, node: &str) -> io::Result<()> {
|
||||
let mut root = path::objects();
|
||||
let mut root = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let (dir, rest) = hash_obj(path.clone().to_str().unwrap());
|
||||
|
||||
root.push(dir);
|
||||
@ -57,7 +64,10 @@ fn rm_node(path: &Path, node: &str) -> io::Result<()> {
|
||||
}
|
||||
|
||||
fn add_node(path: &Path, node: &str) -> io::Result<()> {
|
||||
let mut root = path::objects();
|
||||
let mut root = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let (dir, rest) = hash_obj(path.clone().to_str().unwrap());
|
||||
|
||||
@ -78,7 +88,10 @@ fn add_node(path: &Path, node: &str) -> io::Result<()> {
|
||||
}
|
||||
|
||||
fn create_obj(name: String, content: &str) -> io::Result<()> {
|
||||
let mut root = path::objects();
|
||||
let mut root = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let c = name.clone();
|
||||
let (dir, rest) = c.split_at(2);
|
||||
@ -98,7 +111,10 @@ fn create_obj(name: String, content: &str) -> io::Result<()> {
|
||||
}
|
||||
|
||||
pub fn get_timestamp(path_s: String) -> Option<i64> {
|
||||
let mut obj_p = path::objects();
|
||||
let mut obj_p = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let (dir, res) = hash_obj(&path_s);
|
||||
obj_p.push(dir);
|
||||
|
@ -35,7 +35,10 @@ pub fn rm(path: &Path) -> io::Result<()> {
|
||||
}
|
||||
|
||||
// remove blob object
|
||||
let mut root = path::objects();
|
||||
let mut root = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let c = hash.clone();
|
||||
let (dir, rest) = c.split_at(2);
|
||||
|
@ -25,7 +25,10 @@ pub fn add(path: &Path, date: &str) -> io::Result<()> {
|
||||
}
|
||||
|
||||
pub fn read(tree: String) -> Option<(String, io::Lines<io::BufReader<File>>)> {
|
||||
let mut obj_p = path::objects();
|
||||
let mut obj_p = match path::objects() {
|
||||
Some(path) => path,
|
||||
None => todo!(),
|
||||
};
|
||||
|
||||
let (dir, res) = hash_obj(&tree);
|
||||
obj_p.push(dir);
|
||||
|
@ -23,7 +23,7 @@ pub fn current() -> Option<PathBuf> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn repo_root_without_err() -> Option<PathBuf> {
|
||||
pub fn nextsync_root() -> Option<PathBuf> {
|
||||
let mut path = current()?;
|
||||
|
||||
let root = loop {
|
||||
@ -41,36 +41,32 @@ pub fn repo_root_without_err() -> Option<PathBuf> {
|
||||
root
|
||||
}
|
||||
|
||||
pub fn repo_root() -> PathBuf {
|
||||
match repo_root_without_err() {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nextsync() -> PathBuf {
|
||||
let mut path = repo_root();
|
||||
pub fn nextsync() -> Option<PathBuf> {
|
||||
if let Some(mut path) = nextsync_root() {
|
||||
path.push(".nextsync");
|
||||
path
|
||||
}
|
||||
|
||||
pub fn objects() -> PathBuf {
|
||||
let mut path = repo_root();
|
||||
path.push(".nextsync");
|
||||
path.push("objects");
|
||||
path
|
||||
}
|
||||
|
||||
pub fn nextsyncignore() -> Option<PathBuf> {
|
||||
let mut path = repo_root();
|
||||
path.push(".nextsyncignore");
|
||||
if path.exists() {
|
||||
return Some(path);
|
||||
} else {
|
||||
return None;
|
||||
return Some(path);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn objects() -> Option<PathBuf> {
|
||||
if let Some(mut path) = nextsync_root() {
|
||||
path.push(".nextsync");
|
||||
path.push("objects");
|
||||
return Some(path);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn nextsyncignore() -> Option<PathBuf> {
|
||||
if let Some(mut path) = nextsync_root() {
|
||||
path.push(".nextsyncignore");
|
||||
if path.exists() {
|
||||
return Some(path);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user