diff --git a/Cargo.toml b/Cargo.toml index 1cfb325..9ba74f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ include = [ ] [dependencies] +regex = "1" diff --git a/rusty-tags.vi b/rusty-tags.vi new file mode 100644 index 0000000..eaac351 --- /dev/null +++ b/rusty-tags.vi @@ -0,0 +1,62 @@ +!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ +!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ +!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ +!_TAG_PROGRAM_NAME Exuberant Ctags // +!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ +!_TAG_PROGRAM_VERSION 5.9~svn20110310 // +CopyOptions /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub struct CopyOptions {$/;" s +CopyOptions /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub struct CopyOptions {$/;" s +DirContent /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub struct DirContent {$/;" s +DirEntryAttr /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub enum DirEntryAttr {$/;" g +DirEntryValue /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub enum DirEntryValue {$/;" g +DirOptions /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub struct DirOptions {$/;" s +Error /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^pub struct Error {$/;" s +ErrorKind /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^pub enum ErrorKind {$/;" g +LsResult /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub struct LsResult {$/;" s +Result /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^pub type Result = ::std::result::Result;$/;" T +TransitProcess /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub struct TransitProcess {$/;" s +TransitProcess /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub struct TransitProcess {$/;" s +TransitProcess /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^pub struct TransitProcess {$/;" s +TransitProcessResult /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub enum TransitProcessResult {$/;" g +TransitState /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub enum TransitState {$/;" g +_get_dir_content /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^fn _get_dir_content

(path: P, mut depth: u64) -> Result$/;" f +as_str /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ fn as_str(&self) -> &str {$/;" f +clone /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^ fn clone(&self) -> TransitProcess {$/;" f +clone /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^ fn clone(&self) -> TransitProcess {$/;" f +copy /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn copy(from: P, to: Q, options: &CopyOptions) -> Result$/;" f +copy /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn copy(from: P, to: Q, options: &CopyOptions) -> Result$/;" f +copy_items /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^pub fn copy_items(from: &[P], to: Q, options: &dir::CopyOptions) -> Result$/;" f +copy_items_with_progress /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^pub fn copy_items_with_progress($/;" f +copy_with_progress /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn copy_with_progress($/;" f +copy_with_progress /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn copy_with_progress($/;" f +create /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn create

(path: P, erase: bool) -> Result<()>$/;" f +create_all /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn create_all

(path: P, erase: bool) -> Result<()>$/;" f +default /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^ fn default() -> Self {$/;" f +default /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^ fn default() -> Self {$/;" f +description /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ fn description(&self) -> &str {$/;" f +err /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^macro_rules! err {$/;" d +fmt /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {$/;" f +from /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ fn from(err: IoError) -> Error {$/;" f +from /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ fn from(err: OsString) -> Error {$/;" f +from /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ fn from(err: StripPrefixError) -> Error {$/;" f +get_details_entry /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn get_details_entry

($/;" f +get_details_entry_with_meta /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^fn get_details_entry_with_meta

($/;" f +get_dir_content /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn get_dir_content

(path: P) -> Result$/;" f +get_dir_content2 /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn get_dir_content2

(path: P, options: &DirOptions) -> Result$/;" f +get_size /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn get_size

(path: P) -> Result$/;" f +ls /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn ls

(path: P, config: &HashSet) -> Result$/;" f +move_dir /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn move_dir(from: P, to: Q, options: &CopyOptions) -> Result$/;" f +move_dir_with_progress /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn move_dir_with_progress($/;" f +move_file /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn move_file(from: P, to: Q, options: &CopyOptions) -> Result$/;" f +move_file_with_progress /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn move_file_with_progress($/;" f +move_items /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^pub fn move_items(from_items: &[P], to: Q, options: &dir::CopyOptions) -> Result$/;" f +move_items_with_progress /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^pub fn move_items_with_progress($/;" f +new /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^ pub fn new() -> CopyOptions {$/;" f +new /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^ pub fn new() -> DirOptions {$/;" f +new /home/artie/Documents/Repos/smallB_fs_extra/src/error.rs /^ pub fn new(kind: ErrorKind, message: &str) -> Error {$/;" f +new /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^ pub fn new() -> CopyOptions {$/;" f +read_to_string /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn read_to_string

(path: P) -> Result$/;" f +remove /home/artie/Documents/Repos/smallB_fs_extra/src/dir.rs /^pub fn remove>(path: P) -> Result<()> {$/;" f +remove /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn remove

(path: P) -> Result<()>$/;" f +remove_items /home/artie/Documents/Repos/smallB_fs_extra/src/lib.rs /^pub fn remove_items

(from_items: &[P]) -> Result<()>$/;" f +write_all /home/artie/Documents/Repos/smallB_fs_extra/src/file.rs /^pub fn write_all

(path: P, content: &str) -> Result<()>$/;" f diff --git a/src/dir.rs b/src/dir.rs index 9024c52..864c1c7 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -11,6 +11,8 @@ pub struct CopyOptions { pub overwrite: bool, /// Skip existing files if true (default: false). pub skip_exist: bool, + /// If set to true will append new file content to the old one + pub append: bool, /// Buffer size that specifies the amount of bytes to be moved or copied before the progress handler is called. This only affects functions with progress handlers. (default: 64000) pub buffer_size: usize, /// Recursively copy a directory with a new name or place it inside the destination (default: false, same behaviors as cp -r on Unix) @@ -39,6 +41,7 @@ impl CopyOptions { CopyOptions { overwrite: false, skip_exist: false, + append: false, buffer_size: 64000, // 64kb copy_inside: false, content_only: false, @@ -582,6 +585,7 @@ where overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; let mut result_copy: Result; let mut work = true; @@ -793,6 +797,7 @@ where /// /// ``` pub fn copy_with_progress( + selected_mask:&String, from: P, to: Q, options: &CopyOptions, @@ -864,7 +869,15 @@ where }; let mut options = options.clone(); + let rg = regex::RegexSet::new(&selected_mask.split_ascii_whitespace().collect::>());//++artie + let rg_ok = rg.is_ok(); for file in dir_content.files { + /*++artie */ + if rg_ok && !rg.as_ref().unwrap().is_match(&file) + { + continue; + } + //--artie let mut to = to.to_path_buf(); let tp = Path::new(&file).strip_prefix(from)?; let path = to.join(&tp); @@ -880,6 +893,7 @@ where overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; if let Some(file_name) = file_name.to_str() { @@ -896,11 +910,12 @@ where let copied_bytes = result; while work { { - let _progress_handler = |info: super::file::TransitProcess| { - info_process.copied_bytes = copied_bytes + info.copied_bytes; - info_process.file_bytes_copied = info.copied_bytes; - progress_handler(info_process.clone()); - }; + let _progress_handler = + |info: super::file::TransitProcess| -> TransitProcessResult { + info_process.copied_bytes = copied_bytes + info.copied_bytes; + info_process.file_bytes_copied = info.copied_bytes; + progress_handler(info_process.clone()) + }; result_copy = super::file::copy_with_progress(&file, &path, &file_options, _progress_handler); @@ -1075,6 +1090,7 @@ where overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; let mut result_copy: Result; @@ -1217,6 +1233,7 @@ where overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; if let Some(file_name) = file_name.to_str() { @@ -1233,11 +1250,12 @@ where let copied_bytes = result; while work { { - let _progress_handler = |info: super::file::TransitProcess| { - info_process.copied_bytes = copied_bytes + info.copied_bytes; - info_process.file_bytes_copied = info.copied_bytes; - progress_handler(info_process.clone()); - }; + let _progress_handler = + |info: super::file::TransitProcess| -> TransitProcessResult { + info_process.copied_bytes = copied_bytes + info.copied_bytes; + info_process.file_bytes_copied = info.copied_bytes; + progress_handler(info_process.clone()) + }; result_copy = super::file::move_file_with_progress( &file, @@ -1300,7 +1318,8 @@ where file_options.skip_exist = true; } TransitProcessResult::SkipAll => { - file_options.skip_exist = true; + is_remove = false; + file_options.skip_exist = true; options.skip_exist = true; } TransitProcessResult::Retry => {} diff --git a/src/file.rs b/src/file.rs index f9a384b..310d350 100644 --- a/src/file.rs +++ b/src/file.rs @@ -10,6 +10,8 @@ pub struct CopyOptions { pub overwrite: bool, /// Sets the option true for skip existing files. pub skip_exist: bool, + /// If set to true appends content of new file to the old one + pub append: bool, /// Sets buffer size for copy/move work only with receipt information about process work. pub buffer_size: usize, } @@ -29,6 +31,7 @@ impl CopyOptions { CopyOptions { overwrite: false, skip_exist: false, + append: false, buffer_size: 64000, //64kb } } @@ -143,7 +146,7 @@ pub fn copy_with_progress( where P: AsRef, Q: AsRef, - F: FnMut(TransitProcess), + F: FnMut(TransitProcess) -> crate::dir::TransitProcessResult, { let from = from.as_ref(); if !from.exists() { @@ -180,7 +183,11 @@ where let file_size = file_from.metadata()?.len(); let mut copied_bytes: u64 = 0; - let mut file_to = File::create(to)?; + let mut file_to = std::fs::OpenOptions::new() + .write(true) + .create(true) + .append(options.append) + .open(to)?; while !buf.is_empty() { match file_from.read(&mut buf) { Ok(0) => break, @@ -194,7 +201,13 @@ where copied_bytes, total_bytes: file_size, }; - progress_handler(data); + let progres_result = progress_handler(data); + if progres_result as usize == crate::dir::TransitProcessResult::Abort as usize { + return Err(super::error::Error::new( + super::error::ErrorKind::Interrupted, + "Aborted by user", + )); + } } Err(ref e) if e.kind() == ::std::io::ErrorKind::Interrupted => {} Err(e) => return Err(::std::convert::From::from(e)), @@ -275,7 +288,7 @@ pub fn move_file_with_progress( where P: AsRef, Q: AsRef, - F: FnMut(TransitProcess), + F: FnMut(TransitProcess) -> crate::dir::TransitProcessResult, { let mut is_remove = true; if options.skip_exist && to.as_ref().exists() && !options.overwrite { diff --git a/src/lib.rs b/src/lib.rs index 118643a..b0fff86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -287,6 +287,7 @@ impl Clone for TransitProcess { /// ``` /// pub fn copy_items_with_progress( + selected_mask:&String,//++artie from: &[P], to: Q, options: &dir::CopyOptions, @@ -348,12 +349,13 @@ where } result }; - result += dir::copy_with_progress(item, &to, &dir_options, handler)?; + result += dir::copy_with_progress(selected_mask/*++artie */,item, &to, &dir_options, handler)?; } else { let mut file_options = file::CopyOptions { overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; if let Some(file_name) = item.file_name() { @@ -376,10 +378,10 @@ where let mut result_copy: Result; while work { { - let handler = |info: file::TransitProcess| { + let handler = |info: file::TransitProcess| -> dir::TransitProcessResult { info_process.copied_bytes = copied_bytes + info.copied_bytes; info_process.file_bytes_copied = info.copied_bytes; - progress_handler(info_process.clone()); + progress_handler(info_process.clone()) }; result_copy = file::copy_with_progress(item, &file_name, &file_options, handler); @@ -541,6 +543,7 @@ where overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; if let Some(file_name) = item.file_name() { @@ -666,6 +669,7 @@ where overwrite: options.overwrite, skip_exist: options.skip_exist, buffer_size: options.buffer_size, + append: options.append, }; if let Some(file_name) = item.file_name() { @@ -688,10 +692,10 @@ where let mut result_copy: Result; while work { { - let handler = |info: file::TransitProcess| { + let handler = |info: file::TransitProcess| -> dir::TransitProcessResult { info_process.copied_bytes = copied_bytes + info.copied_bytes; info_process.file_bytes_copied = info.copied_bytes; - progress_handler(info_process.clone()); + progress_handler(info_process.clone()) }; result_copy = file::move_file_with_progress(item, &file_name, &file_options, handler);