Compare commits
14 Commits
e66dc8d408
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09f1b26a50 | ||
|
|
3853d1fe27 | ||
|
|
d0f2fafbbb | ||
|
|
487a94f829 | ||
|
|
6989e87a56 | ||
|
|
33d35aba49 | ||
|
|
adac2e6cda | ||
|
|
d442bf689c | ||
|
|
3af7a00b0f | ||
|
|
61531f664b | ||
|
|
e780279acd | ||
|
|
cd7b225145 | ||
|
|
a69a71d843 | ||
|
|
8f636b4bf7 |
@@ -2,3 +2,6 @@ pub mod add;
|
||||
pub mod init;
|
||||
pub mod status;
|
||||
pub mod reset;
|
||||
pub mod push;
|
||||
pub mod test;
|
||||
pub mod clone;
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::config::config::Config;
|
||||
use crate::store::{
|
||||
ignorer::Ignorer,
|
||||
indexer::Indexer,
|
||||
nsobject::{self, NsObject},
|
||||
nsobject::NsObject,
|
||||
structs::{self, to_obj_path},
|
||||
};
|
||||
use crate::utils::path::to_repo_relative;
|
||||
@@ -21,7 +21,7 @@ pub struct AddArgs {
|
||||
}
|
||||
|
||||
pub fn exec(args: AddArgs, config: Config) {
|
||||
structs::init(config.get_root());
|
||||
structs::init(config.get_root_unsafe());
|
||||
|
||||
// Init ignorer
|
||||
let mut ignorer = Ignorer::new(config.get_root_unsafe());
|
||||
|
||||
190
src/commands/clone.rs
Normal file
190
src/commands/clone.rs
Normal file
@@ -0,0 +1,190 @@
|
||||
use super::init;
|
||||
use crate::config::config::Config;
|
||||
use crate::services::{downloader::Downloader, enumerator::Enumerator, service::Service};
|
||||
use crate::store::{
|
||||
nsobject::NsObject,
|
||||
structs,
|
||||
};
|
||||
use regex::Regex;
|
||||
use std::fs;
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
pub struct CloneArgs {
|
||||
pub remote: String,
|
||||
pub depth: Option<String>,
|
||||
pub force_insecure: bool,
|
||||
}
|
||||
|
||||
pub async fn exec(args: CloneArgs, config: Config) {
|
||||
init::init(&config);
|
||||
structs::init(config.get_root_unsafe());
|
||||
|
||||
let mut url_props = get_url_props(&args.remote);
|
||||
|
||||
if args.force_insecure {
|
||||
url_props.is_secure = false;
|
||||
}
|
||||
|
||||
// Ask for webdav user
|
||||
if url_props.user == String::new() {
|
||||
println!("Please enter the username of the webdav instance: ");
|
||||
let stdin = io::stdin();
|
||||
url_props.user = stdin.lock().lines().next().unwrap().unwrap();
|
||||
}
|
||||
|
||||
let service = Service::from(&url_props);
|
||||
let Ok((files, folders)) = Enumerator::new(&service)
|
||||
.set_path(String::new()) // use base_path of the service
|
||||
// .set_depth(args.depth)
|
||||
.get_properties(vec![])
|
||||
.enumerate()
|
||||
.await
|
||||
else {
|
||||
todo!("Enumerator has failed")
|
||||
};
|
||||
dbg!(&files);
|
||||
dbg!(&folders);
|
||||
|
||||
for folder in folders {
|
||||
if folder.abs_path() == "" {
|
||||
continue;
|
||||
}
|
||||
fs::create_dir(folder.obj_path()).unwrap();
|
||||
NsObject::from_local_path(&folder.obj_path())
|
||||
.save()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let downloader = Downloader::new(&service)
|
||||
.set_files(
|
||||
files
|
||||
.into_iter()
|
||||
.map(|file| file.abs_path().to_string())
|
||||
.collect(),
|
||||
)
|
||||
.download()
|
||||
.await;
|
||||
}
|
||||
|
||||
pub struct UrlProps<'a> {
|
||||
pub is_secure: bool,
|
||||
pub domain: &'a str,
|
||||
pub path: &'a str,
|
||||
pub user: String,
|
||||
}
|
||||
|
||||
impl UrlProps<'_> {
|
||||
fn new() -> Self {
|
||||
UrlProps {
|
||||
is_secure: true,
|
||||
domain: "",
|
||||
path: "",
|
||||
user: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate the url with all the informations of the instance
|
||||
pub fn full_url(&self) -> String {
|
||||
format!(
|
||||
"{}@{}{}{}",
|
||||
self.user,
|
||||
match self.is_secure {
|
||||
true => "https://",
|
||||
false => "http://",
|
||||
},
|
||||
self.domain,
|
||||
self.path
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_url_props(url: &str) -> UrlProps {
|
||||
let mut url_props = UrlProps::new();
|
||||
|
||||
// Match protocol and domain
|
||||
let re = Regex::new(r"((?<protocol>https?)://)?(?<domain>[^/]*)").unwrap();
|
||||
let captures = re.captures(url).expect("fatal: invalid url");
|
||||
|
||||
// Assume is secure
|
||||
let protocol = captures.name("protocol").map_or("https", |m| m.as_str());
|
||||
|
||||
url_props.is_secure = protocol == "https";
|
||||
url_props.domain = captures
|
||||
.name("domain")
|
||||
.map(|m| m.as_str())
|
||||
.expect("fatal: domain not found");
|
||||
|
||||
// Get rest of url
|
||||
let end_of_domain_idx = captures
|
||||
.name("domain")
|
||||
.expect("Already unwraped before")
|
||||
.end();
|
||||
let rest_of_url = &url[end_of_domain_idx..];
|
||||
|
||||
// Try webdav url
|
||||
if let Some(rest_of_url) = rest_of_url.strip_prefix("/remote.php/dav/files") {
|
||||
let re = Regex::new(r"[^\/]*(?<path>.*)").unwrap();
|
||||
url_props.path = re
|
||||
.captures(rest_of_url)
|
||||
.expect("fatal: invalid webdav url")
|
||||
.name("path")
|
||||
.map_or("/", |m| m.as_str());
|
||||
return url_props;
|
||||
}
|
||||
|
||||
// Try 'dir' argument
|
||||
let re = Regex::new(r"\?dir=(?<path>[^&]*)").unwrap();
|
||||
if let Some(captures) = re.captures(rest_of_url) {
|
||||
url_props.path = captures.name("path").map_or("/", |m| m.as_str());
|
||||
return url_props;
|
||||
}
|
||||
|
||||
// Try path next to domain
|
||||
if rest_of_url.chars().nth(0).expect("fatal: invalid url") == '/' {
|
||||
url_props.path = rest_of_url;
|
||||
return url_props;
|
||||
}
|
||||
|
||||
panic!("fatal: invalid url (cannot found path)");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
const DOMAIN: &str = "nextcloud.com";
|
||||
const SUBDOMAIN: &str = "nextcloud.example.com";
|
||||
|
||||
fn compare_url_props(url_to_test: &str, is_secure: bool, domain: &str) {
|
||||
let path = "/foo/bar";
|
||||
let url_props = get_url_props(url_to_test);
|
||||
assert_eq!(url_props.is_secure, is_secure);
|
||||
assert_eq!(url_props.domain, domain);
|
||||
assert_eq!(url_props.path, path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_url_props_from_browser_test() {
|
||||
compare_url_props(
|
||||
"https://nextcloud.com/apps/files/?dir=/foo/bar&fileid=166666",
|
||||
true,
|
||||
DOMAIN,
|
||||
);
|
||||
compare_url_props(
|
||||
"https://nextcloud.com/apps/files/files/625?dir=/foo/bar",
|
||||
true,
|
||||
DOMAIN,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_url_props_direct_url_test() {
|
||||
compare_url_props("https://nextcloud.example.com/foo/bar", true, SUBDOMAIN);
|
||||
compare_url_props("http://nextcloud.example.com/foo/bar", false, SUBDOMAIN);
|
||||
compare_url_props("nextcloud.example.com/foo/bar", true, SUBDOMAIN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_url_props_with_port_test() {
|
||||
compare_url_props("localhost:8080/foo/bar", true, "localhost:8080");
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,10 @@ pub struct InitArgs {}
|
||||
///
|
||||
/// This function will panic if it cannot create the mentioned files or directories.
|
||||
pub fn exec(_: InitArgs, config: Config) {
|
||||
init(&config);
|
||||
}
|
||||
|
||||
pub fn init(config: &Config) {
|
||||
let mut path: PathBuf = config.execution_path.clone();
|
||||
path.push(".nextsync");
|
||||
|
||||
|
||||
20
src/commands/push.rs
Normal file
20
src/commands/push.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use crate::config::config::Config;
|
||||
use crate::store::object::Obj;
|
||||
use crate::store::{indexer::Indexer, structs};
|
||||
|
||||
pub struct PushArgs {}
|
||||
|
||||
pub fn exec(_args: PushArgs, config: Config) {
|
||||
structs::init(config.get_root_unsafe());
|
||||
|
||||
let mut indexer = Indexer::new(config.get_root_unsafe());
|
||||
let _ = indexer.load();
|
||||
|
||||
for indexed_obj in indexer.get_indexed_objs() {
|
||||
let local_obj = Obj::from_local_path(&indexed_obj.path);
|
||||
local_obj.save().unwrap();
|
||||
}
|
||||
|
||||
indexer.clear();
|
||||
let _ = indexer.save();
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
use crate::config::config::Config;
|
||||
use crate::store::indexer::Indexer;
|
||||
|
||||
pub struct ResetArgs {
|
||||
}
|
||||
pub struct ResetArgs {}
|
||||
|
||||
pub fn exec(args: ResetArgs, config: Config) {
|
||||
pub fn exec(_args: ResetArgs, config: Config) {
|
||||
// Init ignorer
|
||||
let indexer = Indexer::new(config.get_root_unsafe());
|
||||
let _ = indexer.save();
|
||||
|
||||
@@ -105,12 +105,15 @@ fn setup_staged(obj_statuses: Arc<ObjStatuses>, indexer: &Indexer) -> ObjStaged
|
||||
}
|
||||
|
||||
pub fn exec(args: StatusArgs, config: Config) {
|
||||
let status = get_obj_changes(&args, &config);
|
||||
print_status(&status);
|
||||
let status = get_obj_changes(&config);
|
||||
if args.nostyle {
|
||||
todo!("Not style not implemented yet");
|
||||
}
|
||||
print_status(&status, config.get_root_unsafe());
|
||||
}
|
||||
|
||||
pub fn get_obj_changes(args: &StatusArgs, config: &Config) -> ObjStaged {
|
||||
structs::init(config.get_root());
|
||||
pub fn get_obj_changes(config: &Config) -> ObjStaged {
|
||||
structs::init(config.get_root_unsafe());
|
||||
|
||||
// use root of repo if no custom path has been set by the command
|
||||
let root = if config.is_custom_execution_path {
|
||||
@@ -156,7 +159,7 @@ pub fn get_obj_changes(args: &StatusArgs, config: &Config) -> ObjStaged {
|
||||
}
|
||||
|
||||
///
|
||||
fn print_status(objs: &ObjStaged) {
|
||||
fn print_status(objs: &ObjStaged, root_path: &PathBuf) {
|
||||
if objs.staged.len() == 0 && objs.not_staged.len() == 0 {
|
||||
println!("Nothing to push, working tree clean");
|
||||
return;
|
||||
@@ -168,7 +171,7 @@ fn print_status(objs: &ObjStaged) {
|
||||
// (use "git restore --staged <file>..." to unstage)
|
||||
// by alphabetical order
|
||||
for obj in objs.staged.iter() {
|
||||
print_object(&obj, |status: &str| status.green());
|
||||
print_object(&obj, root_path, |status: &str| status.green());
|
||||
}
|
||||
}
|
||||
// modified
|
||||
@@ -178,7 +181,7 @@ fn print_status(objs: &ObjStaged) {
|
||||
println!("Changes not staged for push:");
|
||||
println!(" (Use \"nextsync add <file>...\" to update what will be pushed)");
|
||||
for obj in objs.not_staged.iter() {
|
||||
print_object(&obj, |status: &str| status.red());
|
||||
print_object(&obj, root_path, |status: &str| status.red());
|
||||
}
|
||||
|
||||
// println!("Untracked files:");
|
||||
@@ -187,21 +190,20 @@ fn print_status(objs: &ObjStaged) {
|
||||
// }
|
||||
}
|
||||
|
||||
fn print_object(obj: &Obj, color: impl Fn(&str) -> ColoredString) {
|
||||
fn print_object(obj: &Obj, root_path: &PathBuf, color: impl Fn(&str) -> ColoredString) {
|
||||
println!(
|
||||
" {}{}",
|
||||
match obj.get_status() {
|
||||
ObjStatus::Created =>
|
||||
if obj.get_obj_type() == &ObjType::Blob {
|
||||
color("new file: ")
|
||||
} else {
|
||||
color("new: ")
|
||||
ObjStatus::Created => match *obj.get_obj_type() {
|
||||
ObjType::Blob => color("new file: "),
|
||||
ObjType::Tree => color("new dir: "),
|
||||
ObjType::Obj => color("new: "),
|
||||
},
|
||||
ObjStatus::Modified => color("modified: "),
|
||||
ObjStatus::Deleted => color("deleted: "),
|
||||
_ => "unknown".red(),
|
||||
},
|
||||
color(&obj.cpy_path().to_string())
|
||||
color(&path::to_string(&obj.get_env_relative_path(root_path)))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
29
src/commands/test.rs
Normal file
29
src/commands/test.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::config::config::Config;
|
||||
// use crate::services::req_props::{Props, ReqProps};
|
||||
// use crate::store::object::Obj;
|
||||
// use crate::store::{indexer::Indexer, structs};
|
||||
|
||||
pub struct TestArgs {}
|
||||
|
||||
pub fn exec(args: TestArgs, config: Config) {
|
||||
// let mut settings = CConfig::default();
|
||||
// settings.merge(File::with_name("config.toml")).unwrap();
|
||||
// dbg!(settings);
|
||||
|
||||
// let config: MainConfig =
|
||||
// toml::from_str(&std::fs::read_to_string("config.toml").unwrap()).unwrap();
|
||||
// dbg!(config);
|
||||
|
||||
// let config: ConfigFile = settings.try_into().unwrap();
|
||||
// println!("{:?}", config);
|
||||
|
||||
// Ok(())
|
||||
// tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
|
||||
// let mut req = ReqProps::new("")
|
||||
// .set_config(&config)
|
||||
// .get_properties(vec![Props::CreationDate, Props::LastModified]);
|
||||
// req.send().await;
|
||||
// });
|
||||
// dbg!(req);
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod config;
|
||||
pub mod nsconfig;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
use super::nsconfig::{load_nsconfig, NsConfig};
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::OnceLock;
|
||||
use crate::store::structs;
|
||||
|
||||
///
|
||||
/// # Parameters
|
||||
/// * `execution_path`: path of the command (directory arg) or current path
|
||||
/// * `root`: path of the repo
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
pub execution_path: PathBuf,
|
||||
pub is_custom_execution_path: bool,
|
||||
root: OnceLock<Option<PathBuf>>,
|
||||
nsconfig: OnceLock<NsConfig>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -19,6 +21,7 @@ impl Config {
|
||||
execution_path: PathBuf::from(env::current_dir().unwrap()),
|
||||
is_custom_execution_path: false,
|
||||
root: OnceLock::new(),
|
||||
nsconfig: OnceLock::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +31,7 @@ impl Config {
|
||||
execution_path: PathBuf::from(path),
|
||||
is_custom_execution_path: true,
|
||||
root: OnceLock::new(),
|
||||
nsconfig: OnceLock::new(),
|
||||
},
|
||||
None => Config::new(),
|
||||
}
|
||||
@@ -59,4 +63,9 @@ impl Config {
|
||||
None => panic!("fatal: not a nextsync repository (or any parent up to mount point /)"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_nsconfig(&self) -> &NsConfig {
|
||||
self.nsconfig
|
||||
.get_or_init(|| load_nsconfig(self.get_root_unsafe()))
|
||||
}
|
||||
}
|
||||
|
||||
67
src/config/nsconfig.rs
Normal file
67
src/config/nsconfig.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
#[serde(default)]
|
||||
struct Core {}
|
||||
|
||||
impl Default for Core {
|
||||
fn default() -> Self {
|
||||
Core {}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
#[serde(default)]
|
||||
pub struct Remote {
|
||||
pub url: Option<String>,
|
||||
/// Force connection to nextcloud to be http (not https)
|
||||
forceinsecure: bool,
|
||||
}
|
||||
|
||||
impl Default for Remote {
|
||||
fn default() -> Self {
|
||||
Remote {
|
||||
url: None,
|
||||
forceinsecure: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
#[serde(default)]
|
||||
pub struct NsConfig {
|
||||
core: Core,
|
||||
remote: std::collections::HashMap<String, Remote>,
|
||||
}
|
||||
|
||||
impl NsConfig {
|
||||
pub fn get_remote(&self, name: &str) -> Remote {
|
||||
self.remote.get(name).unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NsConfig {
|
||||
fn default() -> Self {
|
||||
NsConfig {
|
||||
core: Core::default(),
|
||||
remote: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_nsconfig(repo_root: &PathBuf) -> NsConfig {
|
||||
let mut config_file_path = repo_root.clone();
|
||||
config_file_path.push(".nextsync");
|
||||
config_file_path.push("config");
|
||||
|
||||
if !config_file_path.exists() {
|
||||
return NsConfig::default();
|
||||
}
|
||||
|
||||
let config: NsConfig = toml::from_str(&fs::read_to_string(config_file_path).unwrap()).unwrap();
|
||||
|
||||
config
|
||||
}
|
||||
@@ -3,3 +3,4 @@ pub mod config;
|
||||
pub mod store;
|
||||
pub mod subcommands;
|
||||
pub mod utils;
|
||||
pub mod services;
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -5,8 +5,10 @@ mod config;
|
||||
mod store;
|
||||
mod subcommands;
|
||||
mod utils;
|
||||
mod services;
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let app = Command::new("Nextsync")
|
||||
.version("1.0")
|
||||
.author("grimhilt")
|
||||
@@ -16,6 +18,9 @@ fn main() {
|
||||
subcommands::add::create(),
|
||||
subcommands::status::create(),
|
||||
subcommands::reset::create(),
|
||||
subcommands::push::create(),
|
||||
subcommands::test::create(),
|
||||
subcommands::clone::create(),
|
||||
]);
|
||||
// .setting(clap::AppSettings::SubcommandRequiredElseHelp);
|
||||
|
||||
@@ -26,6 +31,9 @@ fn main() {
|
||||
Some(("add", args)) => subcommands::add::handler(args),
|
||||
Some(("status", args)) => subcommands::status::handler(args),
|
||||
Some(("reset", args)) => subcommands::reset::handler(args),
|
||||
Some(("push", args)) => subcommands::push::handler(args),
|
||||
Some(("test", args)) => subcommands::test::handler(args),
|
||||
Some(("clone", args)) => subcommands::clone::handler(args).await,
|
||||
Some((_, _)) => {}
|
||||
None => {}
|
||||
};
|
||||
|
||||
5
src/services.rs
Normal file
5
src/services.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub mod downloader;
|
||||
pub mod download;
|
||||
pub mod enumerator;
|
||||
pub mod req_props;
|
||||
pub mod service;
|
||||
42
src/services/download.rs
Normal file
42
src/services/download.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use crate::services::service::{Request, Service};
|
||||
use crate::store::nsobject::NsObject;
|
||||
use std::{fs::OpenOptions, io::Write};
|
||||
|
||||
pub struct Download<'a> {
|
||||
request: Request<'a>,
|
||||
obj_path: String,
|
||||
}
|
||||
|
||||
impl<'a> Download<'a> {
|
||||
pub fn new(service: &'a Service) -> Self {
|
||||
Download {
|
||||
request: Request::new(service),
|
||||
obj_path: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_obj_path(mut self, obj_path: String) -> Self {
|
||||
self.request.get(obj_path.clone());
|
||||
self.obj_path = obj_path
|
||||
.strip_prefix("/")
|
||||
.unwrap_or(&self.obj_path.clone())
|
||||
.to_string();
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn send(&mut self) -> Result<(), reqwest::Error> {
|
||||
let res = self.request.send().await;
|
||||
let body = res.unwrap().bytes().await?;
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(self.obj_path.clone())
|
||||
.unwrap();
|
||||
|
||||
file.write_all(&body.to_vec()).unwrap();
|
||||
NsObject::from_local_path(&self.obj_path.clone().into())
|
||||
.save()
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
26
src/services/downloader.rs
Normal file
26
src/services/downloader.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use super::{download::Download, service::Service};
|
||||
|
||||
pub struct Downloader<'a> {
|
||||
service: &'a Service,
|
||||
files: Vec<String>,
|
||||
}
|
||||
|
||||
impl<'a> Downloader<'a> {
|
||||
pub fn new(service: &'a Service) -> Self {
|
||||
Downloader {
|
||||
service,
|
||||
files: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_files(mut self, files: Vec<String>) -> Self {
|
||||
self.files = files;
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn download(&self) {
|
||||
for file in self.files.clone() {
|
||||
Download::new(self.service).set_obj_path(file).send().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
103
src/services/enumerator.rs
Normal file
103
src/services/enumerator.rs
Normal file
@@ -0,0 +1,103 @@
|
||||
use super::{
|
||||
req_props::{Props, ReqProps, Response},
|
||||
service::Service,
|
||||
};
|
||||
use crate::utils::path;
|
||||
use std::sync::Arc;
|
||||
use tokio::{sync::Mutex, task::JoinSet};
|
||||
|
||||
pub const DEFAULT_DEPTH: u16 = 3;
|
||||
|
||||
pub struct Enumerator<'a> {
|
||||
service: &'a Service,
|
||||
path: String,
|
||||
depth: u16,
|
||||
properties: Vec<Props>,
|
||||
}
|
||||
|
||||
impl<'a> Enumerator<'a> {
|
||||
pub fn new(service: &'a Service) -> Self {
|
||||
Enumerator {
|
||||
service,
|
||||
path: String::new(),
|
||||
depth: DEFAULT_DEPTH,
|
||||
properties: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_path(mut self, path: String) -> Self {
|
||||
self.path = path;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_depth(mut self, depth: u16) -> Self {
|
||||
self.depth = depth;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_properties(mut self, properties: Vec<Props>) -> Self {
|
||||
self.properties.extend(properties);
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn enumerate(&self) -> Result<(Vec<Response>, Vec<Response>), std::io::Error> {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let files = Arc::new(Mutex::new(Vec::new()));
|
||||
let folders = Arc::new(Mutex::new(Vec::new()));
|
||||
let service = Arc::from(self.service.clone());
|
||||
let tasks_active = Arc::new(Mutex::new(0));
|
||||
|
||||
tx.send(self.path.clone());
|
||||
|
||||
let mut taskSet = JoinSet::new();
|
||||
|
||||
loop {
|
||||
if let Ok(path) = rx.try_recv() {
|
||||
let current_depth = path::get_depth(&path);
|
||||
*tasks_active.lock().await += 1;
|
||||
let tx_clone = tx.clone();
|
||||
let files_clone = Arc::clone(&files);
|
||||
let folders_clone = Arc::clone(&folders);
|
||||
let service_clone = Arc::clone(&service);
|
||||
let properties = self.properties.clone();
|
||||
let depth = self.depth.clone();
|
||||
let tasks_active_clone = Arc::clone(&tasks_active);
|
||||
|
||||
let task = taskSet.spawn(async move {
|
||||
let res = ReqProps::new(&service_clone)
|
||||
.set_path(path.clone())
|
||||
.set_depth(depth)
|
||||
.get_properties(properties)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
for obj in res.responses {
|
||||
if obj.is_dir() {
|
||||
// Avoid enumerating the same folder multiple times
|
||||
if obj.abs_path() != &path {
|
||||
// depth deeper than current + self.depth
|
||||
if obj.path_depth() >= current_depth + depth {
|
||||
tx_clone.send(obj.abs_path().to_owned()).unwrap();
|
||||
}
|
||||
folders_clone.lock().await.push(obj);
|
||||
}
|
||||
} else {
|
||||
files_clone.lock().await.push(obj);
|
||||
}
|
||||
}
|
||||
*tasks_active_clone.lock().await -= 1;
|
||||
});
|
||||
} else if *tasks_active.lock().await <= 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
taskSet.join_all().await;
|
||||
|
||||
Ok((
|
||||
Arc::try_unwrap(files).unwrap().into_inner(),
|
||||
Arc::try_unwrap(folders).unwrap().into_inner(),
|
||||
))
|
||||
}
|
||||
}
|
||||
166
src/services/req_props.rs
Normal file
166
src/services/req_props.rs
Normal file
@@ -0,0 +1,166 @@
|
||||
use crate::services::service::{Request, Service};
|
||||
use crate::store::structs::{to_obj_path, ObjPath};
|
||||
use crate::utils::path;
|
||||
use serde::Deserialize;
|
||||
use serde_xml_rs::from_str;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Props {
|
||||
CreationDate,
|
||||
LastModified,
|
||||
ETag,
|
||||
ContentType,
|
||||
RessourceType,
|
||||
ContentLength,
|
||||
ContentLanguage,
|
||||
DisplayName,
|
||||
FileId,
|
||||
Permissions,
|
||||
Size,
|
||||
HasPreview,
|
||||
Favorite,
|
||||
CommentsUnread,
|
||||
OwnerDisplayName,
|
||||
ShareTypes,
|
||||
ContainedFolderCount,
|
||||
ContainedFileCountm,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Propstat {
|
||||
#[serde(rename = "prop")]
|
||||
prop: Prop,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Prop {
|
||||
#[serde(rename = "getlastmodified")]
|
||||
last_modified: Option<String>,
|
||||
#[serde(rename = "getcontentlength")]
|
||||
content_length: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Response {
|
||||
#[serde(rename = "href")]
|
||||
pub href: String,
|
||||
#[serde(rename = "propstat")]
|
||||
propstat: Propstat,
|
||||
href_prefix: Option<String>,
|
||||
}
|
||||
|
||||
impl Response {
|
||||
pub fn is_dir(&self) -> bool {
|
||||
self.href.ends_with("/")
|
||||
}
|
||||
|
||||
pub fn abs_path(&self) -> &str {
|
||||
dbg!(self.href_prefix.clone());
|
||||
let path = self
|
||||
.href
|
||||
.strip_prefix(&format!(
|
||||
"/remote.php/dav/files/{}",
|
||||
self.href_prefix.clone().unwrap_or_default()
|
||||
))
|
||||
.expect(&format!(
|
||||
"Unexpected result when requesting props. Cannot strip from {}",
|
||||
self.href
|
||||
));
|
||||
|
||||
if path.ends_with('/') {
|
||||
path.strip_suffix('/').expect("Checked before")
|
||||
} else {
|
||||
path
|
||||
}
|
||||
}
|
||||
|
||||
pub fn obj_path(&self) -> ObjPath {
|
||||
let mut path = self.abs_path();
|
||||
path = path.strip_prefix("/").unwrap();
|
||||
to_obj_path(&PathBuf::from(path))
|
||||
}
|
||||
|
||||
pub fn path_depth(&self) -> u16 {
|
||||
path::get_depth(self.abs_path())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Multistatus {
|
||||
#[serde(rename = "response")]
|
||||
pub responses: Vec<Response>,
|
||||
}
|
||||
|
||||
impl From<&Props> for &str {
|
||||
fn from(variant: &Props) -> Self {
|
||||
match variant {
|
||||
Props::CreationDate => "<d:creationdate />",
|
||||
Props::LastModified => "<d:getlastmodified />",
|
||||
_ => todo!("Props conversion not implemented"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReqProps<'a> {
|
||||
request: Request<'a>,
|
||||
properties: Vec<Props>,
|
||||
}
|
||||
|
||||
impl<'a> ReqProps<'a> {
|
||||
pub fn new(service: &'a Service) -> Self {
|
||||
ReqProps {
|
||||
request: Request::new(service),
|
||||
properties: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_path(mut self, path: String) -> Self {
|
||||
self.request.propfind(path);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_depth(mut self, depth: u16) -> Self {
|
||||
self.request.headers.insert("Depth", depth.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_properties(mut self, properties: Vec<Props>) -> Self {
|
||||
self.properties.extend(properties);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_property(&mut self, property: Props) {
|
||||
self.properties.push(property);
|
||||
}
|
||||
|
||||
fn get_body(&self) -> String {
|
||||
let mut xml = String::from(
|
||||
r#"<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:prop>"#,
|
||||
);
|
||||
for property in &self.properties {
|
||||
xml.push_str(property.into());
|
||||
}
|
||||
xml.push_str(r#"</d:prop></d:propfind>"#);
|
||||
xml
|
||||
}
|
||||
|
||||
pub async fn send(&mut self) -> Result<Multistatus, reqwest::Error> {
|
||||
let res = self.request.send().await;
|
||||
let xml = res.unwrap().text().await?;
|
||||
dbg!(&xml);
|
||||
let mut multistatus: Multistatus =
|
||||
from_str(&xml).expect("Failed to unwrap xml response from req_props");
|
||||
multistatus
|
||||
.responses
|
||||
.iter_mut()
|
||||
.for_each(|res| res.href_prefix = Some(self.request.service.href_prefix()));
|
||||
Ok(multistatus)
|
||||
}
|
||||
}
|
||||
|
||||
// impl From<Obj> for ReqProps<'_> {
|
||||
// fn from(obj: Obj) -> Self {
|
||||
// ReqProps::new(obj.get_obj_path().to_str().unwrap())
|
||||
// }
|
||||
// }
|
||||
151
src/services/service.rs
Normal file
151
src/services/service.rs
Normal file
@@ -0,0 +1,151 @@
|
||||
use crate::commands::clone::UrlProps;
|
||||
use reqwest::{header::HeaderMap, Method};
|
||||
use reqwest::{Client, ClientBuilder, RequestBuilder};
|
||||
|
||||
const USER_AGENT: &str = "Nextsync";
|
||||
|
||||
pub struct ClientConfig {
|
||||
client: Option<ClientBuilder>,
|
||||
}
|
||||
|
||||
impl ClientConfig {
|
||||
pub fn new() -> Self {
|
||||
ClientConfig {
|
||||
client: Some(Client::builder().user_agent(USER_AGENT)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_headers(mut self, headers: HeaderMap) -> Self {
|
||||
self.client = Some(
|
||||
self.client
|
||||
.take()
|
||||
.expect("Client was already built")
|
||||
.default_headers(headers),
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(&mut self) -> Client {
|
||||
self.client
|
||||
.take()
|
||||
.expect("Cannot build the client twice")
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Service {
|
||||
/// http[s]://host.xz/remote.php/dav/files
|
||||
url_base: String,
|
||||
base_path: String,
|
||||
user: String,
|
||||
}
|
||||
|
||||
impl From<&UrlProps<'_>> for Service {
|
||||
fn from(url_props: &UrlProps) -> Self {
|
||||
let mut url_base = if url_props.is_secure {
|
||||
String::from("https://")
|
||||
} else {
|
||||
String::from("http://")
|
||||
};
|
||||
url_base.push_str(url_props.domain);
|
||||
url_base.push_str("/remote.php/dav/files");
|
||||
|
||||
Service {
|
||||
url_base,
|
||||
base_path: url_props.path.to_string(),
|
||||
user: url_props.user.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Service {
|
||||
fn authenticate(&self, request: RequestBuilder) -> RequestBuilder {
|
||||
request
|
||||
.bearer_auth("rK5ud2NmrR8p586Th7v272HRgUcZcEKIEluOGjzQQRj7gWMMAISFTiJcFnnmnNiu2VVlENks")
|
||||
}
|
||||
|
||||
fn build_url(&self, url: &str) -> String {
|
||||
let mut final_url = self.url_base.clone();
|
||||
final_url.push_str("/");
|
||||
final_url.push_str(&self.user);
|
||||
final_url.push_str(&self.base_path);
|
||||
final_url.push_str(url);
|
||||
final_url
|
||||
}
|
||||
|
||||
/// Return the prefix of a href
|
||||
/// /user/base_path/path -> /user/base_path
|
||||
pub fn href_prefix(&self) -> String {
|
||||
let mut prefix = self.user.clone();
|
||||
prefix.push_str(&self.base_path);
|
||||
prefix
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Request<'a> {
|
||||
pub service: &'a Service,
|
||||
client: ClientConfig,
|
||||
method: Option<Method>,
|
||||
url: Option<String>,
|
||||
pub headers: HeaderMap,
|
||||
body: Option<String>,
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
pub fn new(service: &'a Service) -> Self {
|
||||
Request {
|
||||
service,
|
||||
client: ClientConfig::new(),
|
||||
method: None,
|
||||
url: None,
|
||||
headers: HeaderMap::new(),
|
||||
body: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn propfind(&mut self, url: String) -> &mut Self {
|
||||
self.method = Some(Method::from_bytes(b"PROPFIND").expect("Cannot be invalid"));
|
||||
self.url = Some(url);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get(&mut self, url: String) -> &mut Self {
|
||||
self.method = Some(Method::GET);
|
||||
self.url = Some(url);
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn send(&mut self) -> Result<reqwest::Response, reqwest::Error> {
|
||||
dbg!(self.service.build_url(&self.url.clone().expect("An url must be set")));
|
||||
self.service
|
||||
.authenticate(
|
||||
self.client
|
||||
.build()
|
||||
.request(
|
||||
self.method.clone().expect("Method must be set"),
|
||||
self.service
|
||||
.build_url(&self.url.clone().expect("An url must be set")),
|
||||
)
|
||||
.headers(self.headers.clone()),
|
||||
)
|
||||
.send()
|
||||
.await
|
||||
// let mut url = self
|
||||
// .config
|
||||
// .clone()
|
||||
// .expect("A config must be provided to service")
|
||||
// .get_nsconfig()
|
||||
// .get_remote("origin")
|
||||
// .url
|
||||
// .expect("An url must be set on the remote");
|
||||
// url.push_str(&self.url.clone().unwrap());
|
||||
|
||||
// self.client
|
||||
// .build()
|
||||
// .request(self.method.clone().expect("Method must be set"), url)
|
||||
// .send()
|
||||
// .await
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
use crate::store::object::{Obj, ObjType};
|
||||
use crate::store::{
|
||||
object::{Obj, ObjType},
|
||||
structs::{ObjPath, to_obj_path},
|
||||
};
|
||||
use crate::utils::path::normalize_path;
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::io::{self, Write, BufRead, BufReader};
|
||||
use std::path::PathBuf;
|
||||
|
||||
// Custom sorting function to handle paths hierarchically
|
||||
@@ -28,8 +30,8 @@ fn sort_paths_hierarchically(paths: &mut Vec<PathBuf>) {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IndexedObj {
|
||||
obj_type: ObjType,
|
||||
pub path: PathBuf,
|
||||
pub obj_type: ObjType,
|
||||
pub path: ObjPath,
|
||||
}
|
||||
|
||||
pub struct Indexer {
|
||||
@@ -64,7 +66,7 @@ impl Indexer {
|
||||
|
||||
self.indexed_objs.push(IndexedObj {
|
||||
obj_type: ObjType::try_from(line[0]).unwrap(),
|
||||
path,
|
||||
path: to_obj_path(&path),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,7 +94,6 @@ impl Indexer {
|
||||
}
|
||||
|
||||
pub fn is_staged(&self, obj: &Obj) -> bool {
|
||||
dbg!(obj);
|
||||
// self.indexed_objs.iter().position(|o| &o.obj_type == obj.get_obj_type() && &o.path == obj.get_obj_path()).is_some()
|
||||
self.indexed_objs
|
||||
.iter()
|
||||
@@ -115,7 +116,7 @@ impl Indexer {
|
||||
|
||||
let indexed_obj = IndexedObj {
|
||||
obj_type,
|
||||
path: path.clone(),
|
||||
path: to_obj_path(&path),
|
||||
};
|
||||
|
||||
if self.is_indexed(&indexed_obj) {
|
||||
@@ -138,12 +139,13 @@ impl Indexer {
|
||||
|
||||
for obj in self.indexed_objs.iter() {
|
||||
// write obj_type
|
||||
file.write_all(&[obj.obj_type.clone().into()])?;
|
||||
file.write(&[obj.obj_type.clone().into()])?;
|
||||
|
||||
// write path
|
||||
file.write_all(obj.path.to_str().unwrap().as_bytes())?;
|
||||
file.write(obj.path.to_str().unwrap().as_bytes())?;
|
||||
|
||||
file.write_all(b"\n")?;
|
||||
file.write(b"\n")?;
|
||||
file.flush()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -2,8 +2,10 @@ use crate::store::{
|
||||
object::{Obj, ObjMetadata, ObjType},
|
||||
structs::{NsObjPath, ObjPath},
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{self, Write};
|
||||
use std::sync::OnceLock;
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
type NsObjectChilds = Vec<Box<NsObject>>;
|
||||
|
||||
@@ -82,12 +84,96 @@ impl NsObject {
|
||||
/// * if it is a Tree obj after an empty line there will be the definition
|
||||
/// of its subobjs (one line by subobj) *
|
||||
/// obj_type + hash
|
||||
pub fn save(&self) -> Result<(), ()> {
|
||||
pub fn save(&self) -> io::Result<()> {
|
||||
if !self.get_obj_path().exists() {
|
||||
self.delete_nsobj();
|
||||
} else {
|
||||
dbg!(self.get_nsobj_path());
|
||||
if self.get_nsobj_path().exists() {
|
||||
self.edit_nsobj();
|
||||
} else {
|
||||
self.create_nsobj()?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn delete_nsobj(&self) {
|
||||
todo!("Delete nsobj");
|
||||
// delete current obj
|
||||
// delete reference on parent
|
||||
} else {
|
||||
}
|
||||
|
||||
fn create_nsobj(&self) -> io::Result<()> {
|
||||
let nsobj_path = self.get_nsobj_path();
|
||||
let mut file = {
|
||||
let mut nsobj_dir = nsobj_path.clone();
|
||||
nsobj_dir.pop();
|
||||
if !nsobj_dir.exists() {
|
||||
std::fs::create_dir_all(nsobj_dir)?;
|
||||
}
|
||||
File::create(&nsobj_path)?
|
||||
};
|
||||
|
||||
// Write type
|
||||
file.write(&[self.obj_type.clone().into()])?;
|
||||
|
||||
if self.obj_type == ObjType::Blob {
|
||||
if let Some(metadata) = self.get_metadata() {
|
||||
// Write size
|
||||
file.write(&metadata.size.to_le_bytes())?;
|
||||
|
||||
// Write modified
|
||||
file.write(
|
||||
&metadata
|
||||
.modified
|
||||
.expect(&format!(
|
||||
"Expect 'modified' in metadata of {} to save obj",
|
||||
self.get_obj_path().as_path().display()
|
||||
))
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs()
|
||||
.to_le_bytes(),
|
||||
)?;
|
||||
} else {
|
||||
todo!("Cannot load metadata")
|
||||
}
|
||||
}
|
||||
|
||||
file.write_all(b"\n")?;
|
||||
// Write Path
|
||||
file.write_all(self.get_obj_path().to_str().unwrap().as_bytes())?;
|
||||
file.write_all(b"\n")?;
|
||||
|
||||
file.flush()?;
|
||||
|
||||
// Save itself inside its parent
|
||||
let mut parent_path = self.get_obj_path().clone();
|
||||
parent_path.pop();
|
||||
let parent_obj = NsObject::from_local_path(&parent_path);
|
||||
parent_obj.add_child(&self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn edit_nsobj(&self) {
|
||||
todo!("Edit nsobj");
|
||||
}
|
||||
|
||||
|
||||
fn add_child(&self, child: &NsObject) -> io::Result<()> {
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(self.get_nsobj_path())?;
|
||||
|
||||
let child_type = &[child.obj_type.clone().into()];
|
||||
let child_path = child.get_obj_path().to_str().unwrap().as_bytes();
|
||||
file.write(child_type)?;
|
||||
file.write(child_path)?;
|
||||
file.write(b"\n")?;
|
||||
file.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
use crate::store::{structs::ObjPath, nsobject::NsObject};
|
||||
use crate::store::{
|
||||
nsobject::NsObject,
|
||||
structs::{NsObjPath, ObjPath},
|
||||
};
|
||||
use crate::utils::path;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
use std::time::SystemTime;
|
||||
use std::{
|
||||
env, fmt, fs, io,
|
||||
path::PathBuf,
|
||||
sync::OnceLock,
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
const MAX_SIZE_TO_USE_HASH: u64 = 12 * 1024 * 1024;
|
||||
|
||||
pub struct ObjMetadata {
|
||||
size: u64,
|
||||
modified: Option<SystemTime>,
|
||||
pub size: u64,
|
||||
pub modified: Option<SystemTime>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
@@ -20,13 +25,18 @@ pub enum ObjType {
|
||||
Tree,
|
||||
}
|
||||
|
||||
impl fmt::Display for ObjType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjType> for u8 {
|
||||
fn from(variant: ObjType) -> Self {
|
||||
variant as u8
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl TryFrom<u8> for ObjType {
|
||||
type Error = String;
|
||||
|
||||
@@ -43,6 +53,7 @@ impl TryFrom<u8> for ObjType {
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub enum ObjStatus {
|
||||
Undefined,
|
||||
Unchanged,
|
||||
Created,
|
||||
Modified,
|
||||
Moved,
|
||||
@@ -60,19 +71,39 @@ pub struct Obj {
|
||||
|
||||
impl Obj {
|
||||
pub fn from_local_path(path: &ObjPath) -> Self {
|
||||
// todo set state
|
||||
let obj_path = path.clone();
|
||||
Obj {
|
||||
obj_type: ObjType::Obj,
|
||||
obj_type: {
|
||||
if path.abs().exists() {
|
||||
if path.abs().is_dir() {
|
||||
ObjType::Tree
|
||||
} else {
|
||||
ObjType::Blob
|
||||
}
|
||||
} else {
|
||||
ObjType::Obj
|
||||
}
|
||||
},
|
||||
status: OnceLock::new(),
|
||||
obj_path: path.clone(),
|
||||
obj_path,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_status(&self) -> &ObjStatus {
|
||||
self.status.get_or_init(|| {
|
||||
// todo!();
|
||||
// TODO read path
|
||||
ObjStatus::Created
|
||||
let nsobj = self.get_nsobj();
|
||||
if !nsobj.exists() {
|
||||
return ObjStatus::Created;
|
||||
}
|
||||
if !self.obj_path.exists() {
|
||||
return ObjStatus::Deleted;
|
||||
}
|
||||
if self.obj_type != ObjType::Tree && nsobj.obj_type != ObjType::Tree {
|
||||
if *self != nsobj {
|
||||
return ObjStatus::Modified;
|
||||
}
|
||||
}
|
||||
ObjStatus::Unchanged
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,14 +123,59 @@ impl Obj {
|
||||
&self.obj_type
|
||||
}
|
||||
|
||||
pub fn get_obj_path(&self) -> &PathBuf {
|
||||
pub fn get_obj_path(&self) -> &ObjPath {
|
||||
&self.obj_path
|
||||
}
|
||||
|
||||
/// Return the path of the current object relatively to the path the
|
||||
/// command was executed from.
|
||||
///
|
||||
/// * `repo_root`: the absolute repo's root path
|
||||
pub fn get_env_relative_path(&self, repo_root: &PathBuf) -> PathBuf {
|
||||
let binding = env::current_dir().unwrap();
|
||||
|
||||
if let Ok(root_diff) = binding.strip_prefix(repo_root) {
|
||||
match self.obj_path.strip_prefix(&root_diff) {
|
||||
Ok(path) => {
|
||||
if path == PathBuf::from("") {
|
||||
PathBuf::from("./")
|
||||
} else {
|
||||
path.to_path_buf()
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// if cannot strip prefix then we need to go up to the root
|
||||
let mut res_path = PathBuf::new();
|
||||
for _ in 0..path::get_level(&root_diff.to_path_buf()) {
|
||||
res_path.push("..");
|
||||
}
|
||||
res_path.push(&*self.obj_path);
|
||||
res_path
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if cannot strip prefix then we are at the repo's root
|
||||
self.obj_path.to_path_buf()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cpy_path(&self) -> String {
|
||||
path::to_string(&self.obj_path)
|
||||
}
|
||||
|
||||
fn get_nsobj(&self) -> NsObject {
|
||||
NsObject::from_local_path(&self.obj_path)
|
||||
}
|
||||
|
||||
fn get_nsobj_path(&self) -> NsObjPath {
|
||||
NsObjPath::from(&self.obj_path)
|
||||
}
|
||||
|
||||
pub fn save(&self) -> io::Result<()> {
|
||||
self.get_nsobj().save()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_metadata(&self) -> Option<ObjMetadata> {
|
||||
let metadata = match fs::metadata(&*self.obj_path) {
|
||||
Ok(m) => m,
|
||||
@@ -123,7 +199,13 @@ impl Obj {
|
||||
impl PartialEq<NsObject> for Obj {
|
||||
fn eq(&self, other: &NsObject) -> bool {
|
||||
if self.obj_type != other.obj_type {
|
||||
eprintln!("Trying to compare different obj type");
|
||||
eprintln!(
|
||||
"{}",
|
||||
format!(
|
||||
"Trying to compare different obj type ({} != {})",
|
||||
self.obj_type, other.obj_type
|
||||
)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,27 @@
|
||||
use crate::utils::{path, tests};
|
||||
use crypto::digest::Digest;
|
||||
use crypto::sha1::Sha1;
|
||||
use crypto::{digest::Digest, sha1::Sha1};
|
||||
use std::env;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{LazyLock, Mutex, OnceLock};
|
||||
|
||||
// for tests only as it is mutable
|
||||
static REPO_ROOT_DEV: LazyLock<Mutex<Vec<PathBuf>>> =
|
||||
LazyLock::new(|| Mutex::new(vec![PathBuf::new()]));
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
static REPO_ROOT: OnceLock<PathBuf> = OnceLock::new();
|
||||
|
||||
pub fn init(repo_root: &Option<PathBuf>) {
|
||||
pub fn init(repo_root: &PathBuf) {
|
||||
if tests::is_var_setup() {
|
||||
REPO_ROOT_DEV.lock().unwrap()[0] = repo_root.clone().unwrap();
|
||||
return;
|
||||
env::set_var("REPO_ROOT_DEV", path::to_string(repo_root));
|
||||
}
|
||||
|
||||
if let Some(repo_root) = repo_root {
|
||||
if REPO_ROOT.get().is_none() {
|
||||
let _ = REPO_ROOT.set(repo_root.clone());
|
||||
}
|
||||
} else {
|
||||
eprintln!("REPO_ROOT failed to initialize");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_repo_root() -> PathBuf {
|
||||
if tests::is_var_setup() {
|
||||
return REPO_ROOT_DEV.lock().unwrap()[0].clone();
|
||||
return env::var("REPO_ROOT_DEV")
|
||||
.expect("REPO_ROOT_DEV is not set")
|
||||
.into();
|
||||
}
|
||||
|
||||
match REPO_ROOT.get() {
|
||||
@@ -39,9 +32,30 @@ pub fn get_repo_root() -> PathBuf {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ObjPath {
|
||||
path: PathBuf,
|
||||
abs: OnceLock<PathBuf>,
|
||||
}
|
||||
|
||||
impl ObjPath {
|
||||
pub fn abs(&self) -> &PathBuf {
|
||||
self.abs.get_or_init(|| {
|
||||
let mut path = get_repo_root();
|
||||
path.push(self.path.clone());
|
||||
path
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ObjPath {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
if self.abs.get().is_some() && other.abs.get().is_some() {
|
||||
self.abs() == other.abs()
|
||||
} else {
|
||||
self.path == other.path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ObjPath {
|
||||
@@ -57,14 +71,24 @@ impl DerefMut for ObjPath {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Path> for ObjPath {
|
||||
fn as_ref(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_obj_path(path: &PathBuf) -> ObjPath {
|
||||
ObjPath { path: path.clone() }
|
||||
ObjPath {
|
||||
path: path.clone(),
|
||||
abs: OnceLock::new(),
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<ObjPath> for &PathBuf {
|
||||
fn into(self) -> ObjPath {
|
||||
ObjPath {
|
||||
path: path::to_repo_relative(self),
|
||||
abs: OnceLock::from(self.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,11 +97,21 @@ impl Into<ObjPath> for PathBuf {
|
||||
fn into(self) -> ObjPath {
|
||||
ObjPath {
|
||||
path: path::to_repo_relative(&self),
|
||||
abs: OnceLock::from(self.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
impl Into<ObjPath> for String {
|
||||
fn into(self) -> ObjPath {
|
||||
ObjPath {
|
||||
path: self.into(),
|
||||
abs: OnceLock::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct NsObjPath {
|
||||
path: PathBuf,
|
||||
}
|
||||
@@ -95,11 +129,19 @@ impl DerefMut for NsObjPath {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Path> for NsObjPath {
|
||||
fn as_ref(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for NsObjPath {
|
||||
fn from(hash: &str) -> Self {
|
||||
let (dir, res) = hash.split_at(2);
|
||||
|
||||
let mut ns_obj_path = get_repo_root();
|
||||
ns_obj_path.push(".nextsync");
|
||||
ns_obj_path.push("objects");
|
||||
ns_obj_path.push(dir);
|
||||
ns_obj_path.push(res);
|
||||
|
||||
@@ -109,6 +151,14 @@ impl From<&str> for NsObjPath {
|
||||
|
||||
impl From<&ObjPath> for NsObjPath {
|
||||
fn from(obj_path: &ObjPath) -> Self {
|
||||
// NsObjPath of root is the HEAD file
|
||||
if path::get_level(obj_path) == 0 {
|
||||
let mut path = get_repo_root();
|
||||
path.push(".nextsync");
|
||||
path.push("HEAD");
|
||||
return NsObjPath { path };
|
||||
}
|
||||
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.input_str(
|
||||
obj_path
|
||||
|
||||
@@ -2,3 +2,6 @@ pub mod add;
|
||||
pub mod init;
|
||||
pub mod reset;
|
||||
pub mod status;
|
||||
pub mod push;
|
||||
pub mod test;
|
||||
pub mod clone;
|
||||
|
||||
58
src/subcommands/clone.rs
Normal file
58
src/subcommands/clone.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
|
||||
use crate::commands;
|
||||
use crate::config::config::Config;
|
||||
|
||||
pub fn create() -> Command {
|
||||
Command::new("clone")
|
||||
.arg(
|
||||
Arg::new("remote")
|
||||
.required(true)
|
||||
.num_args(1)
|
||||
.value_name("REMOTE")
|
||||
.help("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.")
|
||||
)
|
||||
.arg(
|
||||
Arg::new("depth")
|
||||
.short('d')
|
||||
.long("depth")
|
||||
.required(false)
|
||||
.num_args(1)
|
||||
.help(format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", crate::services::enumerator::DEFAULT_DEPTH))
|
||||
)
|
||||
.arg(
|
||||
Arg::new("force_insecure")
|
||||
.short('f')
|
||||
.long("force-insecure")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Force the connection to nextcloud to be in http (not https)")
|
||||
)
|
||||
.arg(
|
||||
Arg::new("directory")
|
||||
.required(false)
|
||||
.num_args(1)
|
||||
.value_name("DIRECTORY")
|
||||
)
|
||||
.about("Clone a repository into a new directory")
|
||||
.after_help("
|
||||
NEXTSYNC URLS
|
||||
The following syntaxes may be used:
|
||||
- [http[s]://]host.xz/apps/files/?dir=/path/to/repo&fileid=111111
|
||||
- [http[s]://]host.xz/path/to/repo
|
||||
- [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo
|
||||
")
|
||||
}
|
||||
|
||||
pub async fn handler(args: &ArgMatches) {
|
||||
if let Some(remote) = args.get_one::<String>("remote") {
|
||||
commands::clone::exec(
|
||||
commands::clone::CloneArgs {
|
||||
remote: remote.to_string(),
|
||||
depth: args.get_one::<String>("depth").cloned(),
|
||||
force_insecure: *args.get_one::<bool>("force_insecure").unwrap(),
|
||||
},
|
||||
Config::from(args.get_one::<String>("directory")),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
13
src/subcommands/push.rs
Normal file
13
src/subcommands/push.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use clap::{ArgMatches, Command};
|
||||
|
||||
use crate::commands;
|
||||
use crate::commands::push::PushArgs;
|
||||
use crate::config::config::Config;
|
||||
|
||||
pub fn create() -> Command {
|
||||
Command::new("push").about("Push changes on nextcloud")
|
||||
}
|
||||
|
||||
pub fn handler(_args: &ArgMatches) {
|
||||
commands::push::exec(PushArgs {}, Config::new());
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
use clap::{ArgMatches, Command};
|
||||
|
||||
use crate::commands;
|
||||
use crate::commands::reset::ResetArgs;
|
||||
@@ -9,7 +9,7 @@ pub fn create() -> Command {
|
||||
.about("Clear the index")
|
||||
}
|
||||
|
||||
pub fn handler(args: &ArgMatches) {
|
||||
pub fn handler(_args: &ArgMatches) {
|
||||
commands::reset::exec(
|
||||
ResetArgs {},
|
||||
Config::new(),
|
||||
|
||||
13
src/subcommands/test.rs
Normal file
13
src/subcommands/test.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use clap::{Arg, ArgAction, ArgMatches, Command};
|
||||
|
||||
use crate::commands;
|
||||
use crate::commands::test::TestArgs;
|
||||
use crate::config::config::Config;
|
||||
|
||||
pub fn create() -> Command {
|
||||
Command::new("test").about("Test command")
|
||||
}
|
||||
|
||||
pub fn handler(args: &ArgMatches) {
|
||||
commands::test::exec(TestArgs {}, Config::new());
|
||||
}
|
||||
@@ -16,6 +16,15 @@ pub fn to_string(path: &PathBuf) -> String {
|
||||
path.to_str().unwrap().to_string()
|
||||
}
|
||||
|
||||
pub fn get_level(path: &PathBuf) -> i32 {
|
||||
let mut level = 0;
|
||||
let mut path = path.clone();
|
||||
while path.pop() {
|
||||
level += 1;
|
||||
}
|
||||
level
|
||||
}
|
||||
|
||||
/// Improve the path to try remove and solve .. token.
|
||||
/// Taken from https://stackoverflow.com/questions/68231306/stdfscanonicalize-for-files-that-dont-exist
|
||||
///
|
||||
@@ -45,3 +54,8 @@ pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
}
|
||||
normalized
|
||||
}
|
||||
|
||||
/// Calculate depth of a path
|
||||
pub fn get_depth(path: &str) -> u16 {
|
||||
path.split("/").count() as u16
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
use std::env;
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn is_running() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub fn is_running() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn is_var_setup() -> bool {
|
||||
env::var("RUNNING_TESTS").is_ok()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mod common;
|
||||
|
||||
use common::client::ClientTest;
|
||||
use nextsync::store::indexer::Indexer;
|
||||
use nextsync::store::{structs::to_obj_path, indexer::Indexer};
|
||||
use nextsync::commands::status::{get_obj_changes, StatusArgs};
|
||||
use nextsync::config::config::Config;
|
||||
use std::io;
|
||||
@@ -17,7 +17,7 @@ fn indexed_expected(indexer: &Indexer, expected: Vec<&str>) {
|
||||
for obj in expected {
|
||||
assert!(objs
|
||||
.iter()
|
||||
.position(|e| { e.path == PathBuf::from(obj) })
|
||||
.position(|e| { e.path == to_obj_path(&PathBuf::from(obj)) })
|
||||
.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
use nextsync::config::config::Config;
|
||||
use std::fs::OpenOptions;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{self, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Command, Output};
|
||||
use std::str;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
// Absolute path of the nextsync executable
|
||||
static EXE_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||
|
||||
pub struct ClientTest {
|
||||
volume: String, // temp dir for the test
|
||||
pub test_id: String, // name of the test (e.g nextsync_rand)
|
||||
exe_path: PathBuf, // absolute path of nextsync executable
|
||||
}
|
||||
|
||||
pub fn get_random_test_id() -> String {
|
||||
@@ -24,6 +26,11 @@ pub fn get_random_test_id() -> String {
|
||||
|
||||
impl ClientTest {
|
||||
pub fn new(id: &str) -> Self {
|
||||
let _ = EXE_PATH.get_or_init(|| {
|
||||
let mut exe_path = env::current_dir().unwrap();
|
||||
exe_path = exe_path.join("target/debug/nextsync");
|
||||
exe_path
|
||||
});
|
||||
let mut test_id = id.to_string();
|
||||
test_id.push_str("_");
|
||||
test_id.push_str(&get_random_test_id());
|
||||
@@ -34,15 +41,13 @@ impl ClientTest {
|
||||
let _ = fs::remove_dir_all(&vol);
|
||||
let _ = fs::create_dir_all(&vol);
|
||||
|
||||
// get nextsync path
|
||||
let mut exe_path = env::current_dir().unwrap();
|
||||
exe_path = exe_path.join("target/debug/nextsync");
|
||||
// Setup the current dir to the local repo
|
||||
env::set_current_dir(&vol).unwrap();
|
||||
|
||||
// build the client
|
||||
ClientTest {
|
||||
volume: vol,
|
||||
test_id,
|
||||
exe_path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +71,21 @@ impl ClientTest {
|
||||
Config::from(Some(&self.volume))
|
||||
}
|
||||
|
||||
pub fn new_config(&self, path: &str) -> Config {
|
||||
let mut full_path = self.volume.clone();
|
||||
full_path.push_str("/");
|
||||
full_path.push_str(path);
|
||||
Config::from(Some(&full_path))
|
||||
}
|
||||
|
||||
pub fn set_execution_path(&self, path: &str) {
|
||||
let mut new_execution_path = self.volume.clone();
|
||||
new_execution_path.push_str("/");
|
||||
new_execution_path.push_str(path);
|
||||
|
||||
env::set_current_dir(new_execution_path).unwrap();
|
||||
}
|
||||
|
||||
pub fn ok(self) -> io::Result<()> {
|
||||
fs::remove_dir_all(&self.volume)?;
|
||||
Ok(())
|
||||
@@ -84,7 +104,7 @@ impl ClientTest {
|
||||
}
|
||||
|
||||
pub fn exec(&mut self, args: &str) -> Output {
|
||||
let output = Command::new(self.exe_path.to_str().unwrap())
|
||||
let output = Command::new(EXE_PATH.get().unwrap().to_str().unwrap())
|
||||
.current_dir(self.volume.clone())
|
||||
.args(args.split(" "))
|
||||
.output()
|
||||
@@ -133,7 +153,8 @@ impl ClientTest {
|
||||
.write(true)
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(nsignore_path).unwrap();
|
||||
.open(nsignore_path)
|
||||
.unwrap();
|
||||
|
||||
let _ = writeln!(file, "{rule}").unwrap();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
mod common;
|
||||
|
||||
use common::client::ClientTest;
|
||||
use nextsync::store::object::Obj;
|
||||
use nextsync::commands::status::{get_obj_changes, StatusArgs};
|
||||
use nextsync::config::config::Config;
|
||||
use std::io;
|
||||
@@ -8,27 +9,30 @@ use std::path::PathBuf;
|
||||
|
||||
const DEFAULT_STATUS_ARG: StatusArgs = StatusArgs { nostyle: false };
|
||||
|
||||
fn compare_vect(vec1: Vec<Obj>, vec2: Vec<&str>, config: &Config) {
|
||||
for obj in vec2 {
|
||||
assert!(
|
||||
vec1.iter()
|
||||
.position(|e| {
|
||||
e.get_env_relative_path(config.get_root_unsafe()) == PathBuf::from(obj)
|
||||
})
|
||||
.is_some(),
|
||||
"{:?}",
|
||||
vec1.iter()
|
||||
.map(|e| { e.get_env_relative_path(config.get_root_unsafe()) })
|
||||
.collect::<Vec<PathBuf>>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn status_expected(config: &Config, staged: Vec<&str>, not_staged: Vec<&str>) {
|
||||
let res = get_obj_changes(&DEFAULT_STATUS_ARG, config);
|
||||
let res = get_obj_changes(config);
|
||||
|
||||
assert_eq!(res.staged.len(), staged.len());
|
||||
assert_eq!(res.not_staged.len(), not_staged.len());
|
||||
|
||||
for obj in staged {
|
||||
assert!(res
|
||||
.staged
|
||||
.iter()
|
||||
.position(|e| { e.get_obj_path() == &PathBuf::from(obj) })
|
||||
.is_some());
|
||||
}
|
||||
|
||||
for obj in not_staged {
|
||||
assert!(res
|
||||
.not_staged
|
||||
.iter()
|
||||
.position(|e| { e.get_obj_path() == &PathBuf::from(obj) })
|
||||
.is_some());
|
||||
}
|
||||
compare_vect(res.staged, staged, &config);
|
||||
compare_vect(res.not_staged, not_staged, &config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -55,13 +59,16 @@ fn all_folder() -> io::Result<()> {
|
||||
status_expected(&client.get_config(), vec![], vec!["foo", "dir"]);
|
||||
|
||||
client.exec_ok("add dir");
|
||||
status_expected(&client.get_config(), vec!["dir/foo", "dir/bar"], vec!["foo"]);
|
||||
status_expected(
|
||||
&client.get_config(),
|
||||
vec!["dir/foo", "dir/bar"],
|
||||
vec!["foo"],
|
||||
);
|
||||
|
||||
client.ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn all_folder_current() -> io::Result<()> {
|
||||
let mut client = ClientTest::new("status__all_folder_current").init();
|
||||
|
||||
@@ -73,9 +80,30 @@ fn all_folder_current() -> io::Result<()> {
|
||||
|
||||
client.exec_ok("add dir");
|
||||
status_expected(
|
||||
&Config::from(Some(&String::from("./dir"))),
|
||||
vec!["foor", "bar"],
|
||||
vec!["../foo"],
|
||||
&client.new_config("dir"),
|
||||
vec!["dir/foo", "dir/bar"],
|
||||
vec![],
|
||||
);
|
||||
|
||||
client.ok()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relative_path() -> io::Result<()> {
|
||||
let mut client = ClientTest::new("status__all_folder_current").init();
|
||||
|
||||
client.add_dir("dir")?;
|
||||
client.add_file("dir/foo", "foo")?;
|
||||
client.add_file("dir/bar", "bar")?;
|
||||
client.add_file("foor", "foor")?;
|
||||
status_expected(&client.get_config(), vec![], vec!["foor", "dir"]);
|
||||
|
||||
client.exec_ok("add dir");
|
||||
client.set_execution_path("dir");
|
||||
status_expected(
|
||||
&client.get_config(),
|
||||
vec!["foo", "bar"],
|
||||
vec!["../foor"],
|
||||
);
|
||||
|
||||
client.ok()
|
||||
Reference in New Issue
Block a user