check if the user is in a nextsync repo and fail else

This commit is contained in:
grimhilt
2023-06-25 18:26:59 +02:00
parent d3592a5209
commit b74c5c176b
15 changed files with 49 additions and 155 deletions

View File

@@ -5,7 +5,6 @@ use std::path::{Path, PathBuf};
use clap::Values;
use regex::Regex;
use crate::utils::api::ApiProps;
use crate::utils::read::read_folder;
use crate::global::global::{DIR_PATH, set_dir_path};
use crate::services::api::ApiError;
use crate::services::req_props::{ReqProps, ObjProps};
@@ -61,7 +60,7 @@ pub fn clone(remote: Values<'_>) {
.getlastmodified()
.send_req_multiple();
let mut objs = match res {
let objs = match res {
Ok(o) => o,
Err(ApiError::IncorrectRequest(err)) => {
eprintln!("fatal: {}", err.status());

View File

@@ -3,13 +3,7 @@ use std::io::{self, Write};
use crate::utils::{path, read};
pub fn set(var: &str, val: &str) -> io::Result<()> {
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);
}
};
let mut root = path::nextsync();
root.push("config");
// todo check if exist
@@ -28,13 +22,7 @@ pub fn set(var: &str, val: &str) -> io::Result<()> {
}
pub fn get(var: &str) -> Option<String> {
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);
}
};
let mut root = path::nextsync();
root.push("config");
if let Ok(lines) = read::read_lines(root) {

View File

@@ -12,6 +12,7 @@ pub fn init() {
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());
@@ -23,9 +24,7 @@ pub fn init() {
}
let builder = DirBuilder::new();
// todo check if dir empty
// .nextsync folder
path.push(".nextsync");
match builder.create(path.clone()) {
Ok(()) => (),

View File

@@ -1,12 +1,5 @@
use std::path::PathBuf;
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;
@@ -27,7 +20,6 @@ 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

View File

@@ -5,7 +5,7 @@ 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, PushFactory, PushFlowState};
use crate::commands::push::push_factory::{PushState, PushChange, PushFlowState};
pub struct NewDir {
pub obj: LocalObj

View File

@@ -2,14 +2,7 @@ use std::fs::File;
use crate::utils;
pub fn reset() {
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");
let mut root = utils::path::nextsync();
root.push("index");
if File::create(root).is_err() {
eprintln!("fatal: failed to reset");

View File

@@ -92,16 +92,11 @@ fn get_diff() -> (Vec<LocalObj>, Vec<LocalObj>) {
let mut hashes = HashMap::new();
let mut objs: Vec<String> = vec![];
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);
}
};
let root = utils::path::repo_root();
dbg!(utils::path::current());
let nextsync_path = utils::path::nextsync().unwrap();
let nextsync_path = utils::path::nextsync();
let current_p = utils::path::current().unwrap();
let dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf();
@@ -279,7 +274,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(".nextsyncignore")
path.ends_with(".nextsync")
}
fn read_head(mut path: PathBuf) -> io::Result<io::Lines<io::BufReader<File>>> {