cleaning some code
This commit is contained in:
parent
05d17c296f
commit
e405ce7f8f
@ -10,7 +10,6 @@ use crate::services::api::ApiError;
|
|||||||
use crate::services::list_folders::ListFolders;
|
use crate::services::list_folders::ListFolders;
|
||||||
use crate::services::download_files::DownloadFiles;
|
use crate::services::download_files::DownloadFiles;
|
||||||
use crate::utils::object;
|
use crate::utils::object;
|
||||||
use crate::utils::path;
|
|
||||||
use crate::commands;
|
use crate::commands;
|
||||||
use crate::global::global::{DIR_PATH, set_dir_path};
|
use crate::global::global::{DIR_PATH, set_dir_path};
|
||||||
|
|
||||||
@ -72,11 +71,15 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
} else {
|
} else {
|
||||||
// create folder
|
// create folder
|
||||||
let local_folder = get_local_path(folder, local_path.clone(), username, dist_path_str);
|
let local_folder = get_local_path(folder, local_path.clone(), username, dist_path_str);
|
||||||
dbg!(DirBuilder::new().recursive(true).create(local_folder.clone()));
|
if let Err(err) = DirBuilder::new().recursive(true).create(local_folder.clone()) {
|
||||||
|
eprintln!("error: cannot create directory {}: {}", local_folder.display(), err);
|
||||||
|
}
|
||||||
|
|
||||||
// add tree
|
// add tree
|
||||||
let path_folder = local_folder.strip_prefix(local_path.clone()).unwrap();
|
let path_folder = local_folder.strip_prefix(local_path.clone()).unwrap();
|
||||||
object::add_tree(&path_folder);
|
if object::add_tree(&path_folder).is_err() {
|
||||||
|
eprintln!("error: cannot store object {}", path_folder.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find folders and files in response
|
// find folders and files in response
|
||||||
@ -114,7 +117,7 @@ fn write_file(path: PathBuf, content: &Vec<u8>, local_p: PathBuf) -> io::Result<
|
|||||||
f.write_all(&content)?;
|
f.write_all(&content)?;
|
||||||
|
|
||||||
let relative_p = Path::new(&path).strip_prefix(local_p).unwrap();
|
let relative_p = Path::new(&path).strip_prefix(local_p).unwrap();
|
||||||
object::add_blob(relative_p, "tmpdate");
|
object::add_blob(relative_p, "tmpdate")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use crate::utils::path;
|
use crate::utils::path;
|
||||||
use crate::utils::read;
|
use crate::utils::read;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::{self, Write};
|
||||||
|
|
||||||
pub fn set(var: &str, val: &str) {
|
pub fn set(var: &str, val: &str) -> io::Result<()> {
|
||||||
let mut root = match path::nextsync() {
|
let mut root = match path::nextsync() {
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => {
|
None => {
|
||||||
@ -19,12 +19,13 @@ pub fn set(var: &str, val: &str) {
|
|||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open(root).unwrap();
|
.open(root)?;
|
||||||
|
|
||||||
let mut line = var.to_owned();
|
let mut line = var.to_owned();
|
||||||
line.push_str(" ");
|
line.push_str(" ");
|
||||||
line.push_str(val);
|
line.push_str(val);
|
||||||
writeln!(file, "{}", line);
|
writeln!(file, "{}", line)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(var: &str) -> Option<String> {
|
pub fn get(var: &str) -> Option<String> {
|
||||||
|
@ -4,7 +4,6 @@ use crypto::sha1::Sha1;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::path::Path;
|
|
||||||
use std::io::{self, Lines, BufReader};
|
use std::io::{self, Lines, BufReader};
|
||||||
use crate::utils::{self, object};
|
use crate::utils::{self, object};
|
||||||
|
|
||||||
@ -45,9 +44,7 @@ pub fn get_diff() -> (Vec<String>, Vec<String>, Vec<Obj>) {
|
|||||||
dbg!(utils::path::current());
|
dbg!(utils::path::current());
|
||||||
let nextsync_path = utils::path::nextsync().unwrap();
|
let nextsync_path = utils::path::nextsync().unwrap();
|
||||||
let current_p = utils::path::current().unwrap();
|
let current_p = utils::path::current().unwrap();
|
||||||
let mut dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf();
|
let dist_path = current_p.strip_prefix(root.clone()).unwrap().to_path_buf();
|
||||||
dbg!(dist_path.clone());
|
|
||||||
|
|
||||||
|
|
||||||
if let Ok(lines) = read_head(nextsync_path.clone()) {
|
if let Ok(lines) = read_head(nextsync_path.clone()) {
|
||||||
add_to_hashmap(lines, &mut hashes, dist_path.clone());
|
add_to_hashmap(lines, &mut hashes, dist_path.clone());
|
||||||
|
@ -100,7 +100,9 @@ fn main() {
|
|||||||
} else if let Some(matches) = matches.subcommand_matches("config") {
|
} else if let Some(matches) = matches.subcommand_matches("config") {
|
||||||
if let Some(mut var) = matches.values_of("variable") {
|
if let Some(mut var) = matches.values_of("variable") {
|
||||||
if let Some(mut val) = matches.values_of("value") {
|
if let Some(mut val) = matches.values_of("value") {
|
||||||
commands::config::set(var.next().unwrap(), val.next().unwrap());
|
if commands::config::set(var.next().unwrap(), val.next().unwrap()).is_err() {
|
||||||
|
eprintln!("fatal: cannot save the value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,16 +132,12 @@ fn add_node(path: &Path, node: &str) -> io::Result<()> {
|
|||||||
|
|
||||||
let (dir, rest) = hash_obj(path.clone().to_str().unwrap());
|
let (dir, rest) = hash_obj(path.clone().to_str().unwrap());
|
||||||
|
|
||||||
dbg!(root.clone());
|
|
||||||
root.push(dir);
|
root.push(dir);
|
||||||
if !root.exists() {
|
if !root.exists() {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
root.push(rest);
|
root.push(rest);
|
||||||
|
|
||||||
dbg!("create node");
|
|
||||||
dbg!(root.clone());
|
|
||||||
dbg!(node.clone());
|
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user