From 0ee873441aa1935663c539a70524079946d0cd2d Mon Sep 17 00:00:00 2001 From: Alvi Hysa Date: Fri, 12 Jan 2024 18:44:01 +0100 Subject: [PATCH] Resolved Conversations --- .gitignore | 3 +- Cargo.lock | 49 ++++----------- Cargo.toml | 2 +- src/main.rs | 176 ++++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 145 insertions(+), 85 deletions(-) diff --git a/.gitignore b/.gitignore index 1de5659..55f0498 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -target \ No newline at end of file +target +.ark \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 13d212e..2eff827 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,7 +60,7 @@ dependencies = [ [[package]] name = "arklib" version = "0.1.0" -source = "git+https://github.com/ARK-Builders/arklib?rev=0d25eb0#0d25eb0eb9d59405857e4129f0617046a1ebe159" +source = "git+https://github.com/ARK-Builders/arklib?rev=f92dfc7#f92dfc7b8f241ed71bdec15d923e333bf133baf0" dependencies = [ "anyhow", "canonical-path", @@ -74,7 +74,6 @@ dependencies = [ "lazy_static", "libloading", "log", - "machine-uid", "once_cell", "pathdiff", "pdfium-render", @@ -89,6 +88,7 @@ dependencies = [ "tokio", "ureq", "url", + "uuid", "walkdir", "zip", ] @@ -137,29 +137,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bindgen" -version = "0.66.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" -dependencies = [ - "bitflags 2.4.1", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.42", - "which", -] - [[package]] name = "bindgen" version = "0.69.1" @@ -1163,17 +1140,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" -[[package]] -name = "machine-uid" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "958d2e0ee250103b08a70a5785ca5abcd077a47584b35087248a93758c699f29" -dependencies = [ - "bindgen 0.66.1", - "cc", - "winreg", -] - [[package]] name = "markup5ever" version = "0.11.0" @@ -1450,7 +1416,7 @@ name = "pdfium-render" version = "0.7.26" source = "git+https://github.com/ajrcarey/pdfium-render?rev=d2559c1#d2559c10d27392cc48e51a55d80fffbe6fc87b5c" dependencies = [ - "bindgen 0.69.1", + "bindgen", "bitflags 1.3.2", "bytes", "console_error_panic_hook", @@ -2563,6 +2529,15 @@ dependencies = [ "byteorder", ] +[[package]] +name = "uuid" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +dependencies = [ + "getrandom 0.2.11", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index ea46bd6..54f6b1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "ark-cli" [dependencies] tokio = { version = "1.35.1", features = ["full"] } -arklib = { git = "https://github.com/ARK-Builders/arklib", rev = "0d25eb0" } +arklib = { git = "https://github.com/ARK-Builders/arklib", rev = "f92dfc7" } clap = { version = "3.0.10", features = ["derive"] } env_logger = "0.9.0" fs_extra = "1.2.0" diff --git a/src/main.rs b/src/main.rs index b4ec50a..16943ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,20 @@ -use std::env::current_dir; +use std::env::{self, current_dir}; use std::fs::{canonicalize, create_dir_all, metadata, File}; use std::io::prelude::*; use std::io::BufReader; -use std::path::{Path, PathBuf}; +use std::path::{Display, Path, PathBuf}; use std::thread; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; -use arklib::id::ResourceId; +use arklib::id::{app_id, ResourceId}; use arklib::index::ResourceIndex; use arklib::pdf::PDFQuality; -use arklib::{modify, AtomicFile}; +use arklib::{ + modify, AtomicFile, ARK_FOLDER, DEVICE_ID, FAVORITES_FILE, INDEX_PATH, + METADATA_STORAGE_FOLDER, PREVIEWS_STORAGE_FOLDER, + PROPERTIES_STORAGE_FOLDER, SCORE_STORAGE_FILE, STATS_FOLDER, + TAG_STORAGE_FILE, THUMBNAILS_STORAGE_FOLDER, +}; use clap::{Parser, Subcommand}; use fs_extra::dir::{self, CopyOptions}; use home::home_dir; @@ -67,7 +72,7 @@ enum FileCommand { List { #[clap(parse(from_os_str))] - file_path: Option, + storage: Option, #[clap(short, long)] all: bool, @@ -106,6 +111,17 @@ async fn main() { let args = Cli::parse(); + let temp_dir = std::env::temp_dir(); + let ark_dir = temp_dir.join(".ark"); + if !ark_dir.exists() { + std::fs::create_dir(&ark_dir).unwrap(); + } + println!("Loading app id at {}...", ark_dir.display()); + let _ = app_id::load(ark_dir).map_err(|e| { + println!("Couldn't load app id: {}", e); + std::process::exit(1); + }); + match &args.command { Command::Backup { roots_cfg } => { let timestamp = timestamp().as_secs(); @@ -288,55 +304,108 @@ async fn main() { } } - FileCommand::List { file_path, all } => { + FileCommand::List { storage, all } => { + let root = provide_root(&None); + let storage = storage.as_ref().unwrap_or(&root); + if !all { - let file_path = file_path.as_ref().unwrap(); - let file = AtomicFile::new(file_path).unwrap(); + let file_path = if storage.exists() { + Some(storage.clone()) + } else { + match storage + .clone() + .into_os_string() + .into_string() + .unwrap() + .to_lowercase() + .as_str() + { + "favorites" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(FAVORITES_FILE), + ), + "device" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(DEVICE_ID), + ), + "tage" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(TAG_STORAGE_FILE), + ), + "score" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(SCORE_STORAGE_FILE), + ), + + _ => None, + } + } + .expect("Could not find storage folder"); + + let file = AtomicFile::new(&file_path).unwrap(); if let Ok(file) = format_file(&file) { println!("{}", file); - - let files: Vec = WalkDir::new(file_path) - .into_iter() - .filter_entry(|e| { - !e.file_name() - .to_str() - .map(|s| s.starts_with('.')) - .unwrap_or(false) - }) - .filter_map(|v| v.ok()) - .collect(); - - println!("Versions:"); - for file in files { - if file.file_type().is_file() { - println!(" {}", file.path().display()); - } - } } else { println!( - "File {} is not a valid tag storage", + "FILE: {} is not a valid atomic file", file_path.display() ); } } else { - // walk through all files recursivelty in the folder and store them in a vector called files - - let files: Vec = - WalkDir::new(file_path.as_ref().unwrap()) - .into_iter() - .filter_entry(|e| { - !e.file_name() - .to_str() - .map(|s| s.starts_with('.')) - .unwrap_or(false) - && e.file_type().is_dir() - }) - .filter_map(|v| v.ok()) - .filter_map(|e| match AtomicFile::new(e.path()) { - Ok(file) => Some(file), - Err(_) => None, - }) - .collect(); + let file_path = if storage.exists() { + Some(storage.clone()) + } else { + match storage + .clone() + .into_os_string() + .into_string() + .unwrap() + .to_lowercase() + .as_str() + { + "stats" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(STATS_FOLDER), + ), + "properties" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(PROPERTIES_STORAGE_FOLDER), + ), + "metadata" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(METADATA_STORAGE_FOLDER), + ), + "previews" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(PREVIEWS_STORAGE_FOLDER), + ), + "thumbnails" => Some( + provide_root(&None) + .join(ARK_FOLDER) + .join(THUMBNAILS_STORAGE_FOLDER), + ), + _ => None, + } + } + .expect("Could not find storage folder"); + + let files: Vec = WalkDir::new(file_path) + .into_iter() + .filter_entry(|e| e.file_type().is_dir()) + .filter_map(|v| v.ok()) + .filter_map(|e| match AtomicFile::new(e.path()) { + Ok(file) => Some(file), + Err(_) => None, + }) + .collect(); for file in files { if let Ok(file) = format_file(&file) { @@ -353,7 +422,22 @@ fn format_file(file: &AtomicFile) -> Result { let current = file.load()?; let data = current.read_to_string()?; // !TODO: add version number when arklib is updated - Ok(format!("FILE {} V5 : {}", "./path/here", data)) + + let mut split = current + .path + .file_name() + .expect("Not a file") + .to_str() + .unwrap() + .split("_"); + + Ok(format!( + "{}: [{} - {}]: {}", + current.version, + split.next().unwrap(), + split.next().unwrap(), + data + )) } fn discover_roots(roots_cfg: &Option) -> Vec {