fs_extra/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
macro_rules! err {
($text:expr, $kind:expr) => {
return Err(Error::new($kind, $text))
};
($text:expr) => {
err!($text, ErrorKind::Other)
};
}
/// The error type for fs_extra operations on files and directories.
pub mod error;
/// This module includes additional methods for working with files.
///
/// One of the distinguishing features is receipt information
/// about process work with files.
///
/// # Example
/// ```rust,ignore
/// use std::path::Path;
/// use std::{thread, time};
/// use std::sync::mpsc::{self, TryRecvError};
///
/// extern crate fs_extra;
/// use fs_extra::file::*;
/// use fs_extra::error::*;
///
/// fn example_copy() -> Result<()> {
/// let path_from = Path::new("./temp");
/// let path_to = path_from.join("out");
/// let test_file = (path_from.join("test_file.txt"), path_to.join("test_file.txt"));
///
///
/// fs_extra::dir::create_all(&path_from, true)?;
/// fs_extra::dir::create_all(&path_to, true)?;
///
/// write_all(&test_file.0, "test_data")?;
/// assert!(test_file.0.exists());
/// assert!(!test_file.1.exists());
///
///
/// let options = CopyOptions {
/// buffer_size: 1,
/// ..Default::default()
/// }
/// let (tx, rx) = mpsc::channel();
/// thread::spawn(move || {
/// let handler = |process_info: TransitProcess| {
/// tx.send(process_info).unwrap();
/// thread::sleep(time::Duration::from_millis(500));
/// };
/// copy_with_progress(&test_file.0, &test_file.1, &options, handler).unwrap();
/// assert!(test_file.0.exists());
/// assert!(test_file.1.exists());
///
/// });
/// loop {
/// match rx.try_recv() {
/// Ok(process_info) => {
/// println!("{} of {} bytes",
/// process_info.copied_bytes,
/// process_info.total_bytes);
/// }
/// Err(TryRecvError::Disconnected) => {
/// println!("finished");
/// break;
/// }
/// Err(TryRecvError::Empty) => {}
/// }
/// }
/// Ok(())
///
/// }
///
///
/// fn main() {
/// example_copy();
/// }
///
/// ```
pub mod file;
/// This module includes additional methods for working with directories.
///
/// One of the additional features is information
/// about process and recursion operations.
///
/// # Example
/// ```rust,ignore
/// use std::path::Path;
/// use std::{thread, time};
/// use std::sync::mpsc::{self, TryRecvError};
///
/// extern crate fs_extra;
/// use fs_extra::dir::*;
/// use fs_extra::error::*;
///
/// fn example_copy() -> Result<()> {
///
/// let path_from = Path::new("./temp");
/// let path_to = path_from.join("out");
/// let test_folder = path_from.join("test_folder");
/// let dir = test_folder.join("dir");
/// let sub = dir.join("sub");
/// let file1 = dir.join("file1.txt");
/// let file2 = sub.join("file2.txt");
///
/// create_all(&sub, true)?;
/// create_all(&path_to, true)?;
/// fs_extra::file::write_all(&file1, "content1")?;
/// fs_extra::file::write_all(&file2, "content2")?;
///
/// assert!(dir.exists());
/// assert!(sub.exists());
/// assert!(file1.exists());
/// assert!(file2.exists());
///
///
/// let options = CopyOptions {
/// buffer_size: 1,
/// ..Default::default(),
/// };
/// let (tx, rx) = mpsc::channel();
/// thread::spawn(move || {
/// let handler = |process_info: TransitProcess| {
/// tx.send(process_info).unwrap();
/// thread::sleep(time::Duration::from_millis(500));
/// };
/// copy_with_progress(&test_folder, &path_to, &options, handler).unwrap();
/// });
///
/// loop {
/// match rx.try_recv() {
/// Ok(process_info) => {
/// println!("{} of {} bytes",
/// process_info.copied_bytes,
/// process_info.total_bytes);
/// }
/// Err(TryRecvError::Disconnected) => {
/// println!("finished");
/// break;
/// }
/// Err(TryRecvError::Empty) => {}
/// }
/// }
/// Ok(())
///
/// }
/// fn main() {
/// example_copy();
/// }
/// ```
///
pub mod dir;
use crate::error::*;
use std::path::Path;
/// Copies a list of directories and files to another place recursively. This function will
/// also copy the permission bits of the original files to destination files (not for
/// directories).
///
/// # Errors
///
/// This function will return an error in the following situations, but is not limited to just
/// these case:
///
/// * List `from` contains file or directory does not exist.
///
/// * List `from` contains file or directory with invalid name.
///
/// * The current process does not have the permission to access to file from `lists from` or
/// `to`.
///
/// # Example
///
/// ```rust,ignore
/// extern crate fs_extra;
/// use fs_extra::dir::copy;
///
/// let options = dir::CopyOptions::new(); //Initialize default values for CopyOptions
///
/// // copy dir1 and file1.txt to target/dir1 and target/file1.txt
/// let mut from_paths = Vec::new();
/// from_paths.push("source/dir1");
/// from_paths.push("source/file.txt");
/// copy_items(&from_paths, "target", &options)?;
/// ```
///
pub fn copy_items<P, Q>(from: &[P], to: Q, options: &dir::CopyOptions) -> Result<u64>
where
P: AsRef<Path>,
Q: AsRef<Path>,
{
let mut result: u64 = 0;
if options.content_only {
err!(
"Options 'content_only' not acccess for copy_items function",
ErrorKind::Other
);
}
for item in from {
let item = item.as_ref();
if item.is_dir() {
result += dir::copy(item, &to, options)?;
} else if let Some(file_name) = item.file_name() {
if let Some(file_name) = file_name.to_str() {
let file_options = file::CopyOptions {
overwrite: options.overwrite,
skip_exist: options.skip_exist,
..Default::default()
};
result += file::copy(item, to.as_ref().join(file_name), &file_options)?;
}
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
}
Ok(result)
}
/// A structure which includes information about the current status of copying or moving a directory.
pub struct TransitProcess {
/// Already copied bytes
pub copied_bytes: u64,
/// All the bytes which should be copied or moved (dir size).
pub total_bytes: u64,
/// Copied bytes on this time for file.
pub file_bytes_copied: u64,
/// Size of currently copied file.
pub file_total_bytes: u64,
/// Name of currently copied file.
pub file_name: String,
/// Name of currently copied folder.
pub dir_name: String,
/// Transit state
pub state: dir::TransitState,
}
impl Clone for TransitProcess {
fn clone(&self) -> TransitProcess {
TransitProcess {
copied_bytes: self.copied_bytes,
total_bytes: self.total_bytes,
file_bytes_copied: self.file_bytes_copied,
file_total_bytes: self.file_total_bytes,
file_name: self.file_name.clone(),
dir_name: self.dir_name.clone(),
state: self.state.clone(),
}
}
}
/// Copies a list of directories and files to another place recursively, with
/// information about progress. This function will also copy the permission bits of the
/// original files to destination files (not for directories).
///
/// # Errors
///
/// This function will return an error in the following situations, but is not limited to just
/// these case:
///
/// * List `from` contains file or directory does not exist.
///
/// * List `from` contains file or directory with invalid name.
///
/// * The current process does not have the permission to access to file from `lists from` or
/// `to`.
///
/// # Example
/// ```rust,ignore
///
/// extern crate fs_extra;
/// use fs_extra::dir::copy;
///
/// let options = dir::CopyOptions::new(); //Initialize default values for CopyOptions
/// let handle = |process_info: TransitProcess| {
/// println!("{}", process_info.total_bytes);
/// fs_extra::dir::TransitProcessResult::ContinueOrAbort
/// }
/// // copy dir1 and file1.txt to target/dir1 and target/file1.txt
/// let mut from_paths = Vec::new();
/// from_paths.push("source/dir1");
/// from_paths.push("source/file.txt");
/// copy_items_with_progress(&from_paths, "target", &options, handle)?;
/// ```
///
pub fn copy_items_with_progress<P, Q, F>(
from: &[P],
to: Q,
options: &dir::CopyOptions,
mut progress_handler: F,
) -> Result<u64>
where
P: AsRef<Path>,
Q: AsRef<Path>,
F: FnMut(TransitProcess) -> dir::TransitProcessResult,
{
if options.content_only {
err!(
"Options 'content_only' not access for copy_items_with_progress function",
ErrorKind::Other
);
}
let mut total_size = 0;
let mut list_paths = Vec::new();
for item in from {
let item = item.as_ref();
total_size += dir::get_size(item)?;
list_paths.push(item);
}
let mut result: u64 = 0;
let mut info_process = TransitProcess {
copied_bytes: 0,
total_bytes: total_size,
file_bytes_copied: 0,
file_total_bytes: 0,
file_name: String::new(),
dir_name: String::new(),
state: dir::TransitState::Normal,
};
let mut options = options.clone();
for item in list_paths {
if item.is_dir() {
if let Some(dir_name) = item.components().last() {
if let Ok(dir_name) = dir_name.as_os_str().to_os_string().into_string() {
info_process.dir_name = dir_name;
} else {
err!("Invalid folder from", ErrorKind::InvalidFolder);
}
} else {
err!("Invalid folder from", ErrorKind::InvalidFolder);
}
let copied_bytes = result;
let dir_options = options.clone();
let handler = |info: dir::TransitProcess| {
info_process.copied_bytes = copied_bytes + info.copied_bytes;
info_process.state = info.state;
let result = progress_handler(info_process.clone());
match result {
dir::TransitProcessResult::OverwriteAll => options.overwrite = true,
dir::TransitProcessResult::SkipAll => options.skip_exist = true,
_ => {}
}
result
};
result += dir::copy_with_progress(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,
};
if let Some(file_name) = item.file_name() {
if let Some(file_name) = file_name.to_str() {
info_process.file_name = file_name.to_string();
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
info_process.file_bytes_copied = 0;
info_process.file_total_bytes = item.metadata()?.len();
let copied_bytes = result;
let file_name = to.as_ref().join(info_process.file_name.clone());
let mut work = true;
let mut result_copy: Result<u64>;
while work {
{
let handler = |info: file::TransitProcess| {
info_process.copied_bytes = copied_bytes + info.copied_bytes;
info_process.file_bytes_copied = info.copied_bytes;
progress_handler(info_process.clone());
};
result_copy =
file::copy_with_progress(item, &file_name, &file_options, handler);
}
match result_copy {
Ok(val) => {
result += val;
work = false;
}
Err(err) => match err.kind {
ErrorKind::AlreadyExists => {
let mut info_process = info_process.clone();
info_process.state = dir::TransitState::Exists;
let user_decide = progress_handler(info_process);
match user_decide {
dir::TransitProcessResult::Overwrite => {
file_options.overwrite = true;
}
dir::TransitProcessResult::OverwriteAll => {
file_options.overwrite = true;
options.overwrite = true;
}
dir::TransitProcessResult::Skip => {
file_options.skip_exist = true;
}
dir::TransitProcessResult::SkipAll => {
file_options.skip_exist = true;
options.skip_exist = true;
}
dir::TransitProcessResult::Retry => {}
dir::TransitProcessResult::ContinueOrAbort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
dir::TransitProcessResult::Abort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
}
}
ErrorKind::PermissionDenied => {
let mut info_process = info_process.clone();
info_process.state = dir::TransitState::Exists;
let user_decide = progress_handler(info_process);
match user_decide {
dir::TransitProcessResult::Overwrite => {
err!("Overwrite denied for this situation!", ErrorKind::Other);
}
dir::TransitProcessResult::OverwriteAll => {
err!("Overwrite denied for this situation!", ErrorKind::Other);
}
dir::TransitProcessResult::Skip => {
file_options.skip_exist = true;
}
dir::TransitProcessResult::SkipAll => {
file_options.skip_exist = true;
options.skip_exist = true;
}
dir::TransitProcessResult::Retry => {}
dir::TransitProcessResult::ContinueOrAbort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
dir::TransitProcessResult::Abort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
}
}
_ => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
},
}
}
}
}
Ok(result)
}
/// Moves a list of directories and files to another place recursively. This function will
/// also copy the permission bits of the original files to destination files (not for
/// directories).
///
/// # Errors
///
/// This function will return an error in the following situations, but is not limited to just
/// these case:
///
/// * List `from` contains file or directory does not exist.
///
/// * List `from` contains file or directory with invalid name.
///
/// * The current process does not have the permission to access to file from `lists from` or
/// `to`.
///
/// # Example
///
/// ```rust,ignore
/// extern crate fs_extra;
/// use fs_extra::dir::copy;
///
/// let options = dir::CopyOptions::new(); //Initialize default values for CopyOptions
///
/// // move dir1 and file1.txt to target/dir1 and target/file1.txt
/// let mut from_paths = Vec::new();
/// from_paths.push("source/dir1");
/// from_paths.push("source/file.txt");
/// move_items(&from_paths, "target", &options)?;
/// ```
///
pub fn move_items<P, Q>(from_items: &[P], to: Q, options: &dir::CopyOptions) -> Result<u64>
where
P: AsRef<Path>,
Q: AsRef<Path>,
{
if options.content_only {
err!(
"Options 'content_only' not access for move_items function",
ErrorKind::Other
);
}
let mut total_size = 0;
let mut list_paths = Vec::new();
for item in from_items {
let item = item.as_ref();
total_size += dir::get_size(item)?;
list_paths.push(item);
}
let mut result = 0;
let mut info_process = TransitProcess {
copied_bytes: 0,
total_bytes: total_size,
file_bytes_copied: 0,
file_total_bytes: 0,
file_name: String::new(),
dir_name: String::new(),
state: dir::TransitState::Normal,
};
for item in list_paths {
if item.is_dir() {
if let Some(dir_name) = item.components().last() {
if let Ok(dir_name) = dir_name.as_os_str().to_os_string().into_string() {
info_process.dir_name = dir_name;
} else {
err!("Invalid folder from", ErrorKind::InvalidFolder);
}
} else {
err!("Invalid folder from", ErrorKind::InvalidFolder);
}
result += dir::move_dir(item, &to, options)?;
} else {
let file_options = file::CopyOptions {
overwrite: options.overwrite,
skip_exist: options.skip_exist,
buffer_size: options.buffer_size,
};
if let Some(file_name) = item.file_name() {
if let Some(file_name) = file_name.to_str() {
info_process.file_name = file_name.to_string();
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
info_process.file_bytes_copied = 0;
info_process.file_total_bytes = item.metadata()?.len();
let file_name = to.as_ref().join(info_process.file_name.clone());
result += file::move_file(item, &file_name, &file_options)?;
}
}
Ok(result)
}
/// Moves a list of directories and files to another place recursively, with
/// information about progress. This function will also copy the permission bits of the
/// original files to destination files (not for directories).
///
/// # Errors
///
/// This function will return an error in the following situations, but is not limited to just
/// these case:
///
/// * List `from` contains file or directory does not exist.
///
/// * List `from` contains file or directory with invalid name.
///
/// * The current process does not have the permission to access to file from `lists from` or
/// `to`.
///
/// # Example
///
/// ```rust,ignore
/// extern crate fs_extra;
/// use fs_extra::dir::copy;
///
/// let options = dir::CopyOptions::new(); //Initialize default values for CopyOptions
/// let handle = |process_info: TransitProcess| {
/// println!("{}", process_info.total_bytes);
/// fs_extra::dir::TransitProcessResult::ContinueOrAbort
/// }
/// // move dir1 and file1.txt to target/dir1 and target/file1.txt
/// let mut from_paths = Vec::new();
/// from_paths.push("source/dir1");
/// from_paths.push("source/file.txt");
/// move_items_with_progress(&from_paths, "target", &options, handle)?;
/// ```
///
pub fn move_items_with_progress<P, Q, F>(
from_items: &[P],
to: Q,
options: &dir::CopyOptions,
mut progress_handler: F,
) -> Result<u64>
where
P: AsRef<Path>,
Q: AsRef<Path>,
F: FnMut(TransitProcess) -> dir::TransitProcessResult,
{
if options.content_only {
err!(
"Options 'content_only' not access for move_items_with_progress function",
ErrorKind::Other
);
}
let mut total_size = 0;
let mut list_paths = Vec::new();
for item in from_items {
let item = item.as_ref();
total_size += dir::get_size(item)?;
list_paths.push(item);
}
let mut result = 0;
let mut info_process = TransitProcess {
copied_bytes: 0,
total_bytes: total_size,
file_bytes_copied: 0,
file_total_bytes: 0,
file_name: String::new(),
dir_name: String::new(),
state: dir::TransitState::Normal,
};
let mut options = options.clone();
for item in list_paths {
if item.is_dir() {
if let Some(dir_name) = item.components().last() {
if let Ok(dir_name) = dir_name.as_os_str().to_os_string().into_string() {
info_process.dir_name = dir_name;
} else {
err!("Invalid folder from", ErrorKind::InvalidFolder);
}
} else {
err!("Invalid folder from", ErrorKind::InvalidFolder);
}
let copied_bytes = result;
let dir_options = options.clone();
let handler = |info: dir::TransitProcess| {
info_process.copied_bytes = copied_bytes + info.copied_bytes;
info_process.state = info.state;
let result = progress_handler(info_process.clone());
match result {
dir::TransitProcessResult::OverwriteAll => options.overwrite = true,
dir::TransitProcessResult::SkipAll => options.skip_exist = true,
_ => {}
}
result
};
result += dir::move_dir_with_progress(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,
};
if let Some(file_name) = item.file_name() {
if let Some(file_name) = file_name.to_str() {
info_process.file_name = file_name.to_string();
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
} else {
err!("Invalid file name", ErrorKind::InvalidFileName);
}
info_process.file_bytes_copied = 0;
info_process.file_total_bytes = item.metadata()?.len();
let copied_bytes = result;
let file_name = to.as_ref().join(info_process.file_name.clone());
let mut work = true;
let mut result_copy: Result<u64>;
while work {
{
let handler = |info: file::TransitProcess| {
info_process.copied_bytes = copied_bytes + info.copied_bytes;
info_process.file_bytes_copied = info.copied_bytes;
progress_handler(info_process.clone());
};
result_copy =
file::move_file_with_progress(item, &file_name, &file_options, handler);
}
match result_copy {
Ok(val) => {
result += val;
work = false;
}
Err(err) => match err.kind {
ErrorKind::AlreadyExists => {
let mut info_process = info_process.clone();
info_process.state = dir::TransitState::Exists;
let user_decide = progress_handler(info_process);
match user_decide {
dir::TransitProcessResult::Overwrite => {
file_options.overwrite = true;
}
dir::TransitProcessResult::OverwriteAll => {
file_options.overwrite = true;
options.overwrite = true;
}
dir::TransitProcessResult::Skip => {
file_options.skip_exist = true;
}
dir::TransitProcessResult::SkipAll => {
file_options.skip_exist = true;
options.skip_exist = true;
}
dir::TransitProcessResult::Retry => {}
dir::TransitProcessResult::ContinueOrAbort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
dir::TransitProcessResult::Abort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
}
}
ErrorKind::PermissionDenied => {
let mut info_process = info_process.clone();
info_process.state = dir::TransitState::Exists;
let user_decide = progress_handler(info_process);
match user_decide {
dir::TransitProcessResult::Overwrite => {
err!("Overwrite denied for this situation!", ErrorKind::Other);
}
dir::TransitProcessResult::OverwriteAll => {
err!("Overwrite denied for this situation!", ErrorKind::Other);
}
dir::TransitProcessResult::Skip => {
file_options.skip_exist = true;
}
dir::TransitProcessResult::SkipAll => {
file_options.skip_exist = true;
options.skip_exist = true;
}
dir::TransitProcessResult::Retry => {}
dir::TransitProcessResult::ContinueOrAbort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
dir::TransitProcessResult::Abort => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
}
}
_ => {
let err_msg = err.to_string();
err!(err_msg.as_str(), err.kind)
}
},
}
}
}
}
Ok(result)
}
/// Removes a list of files or directories.
///
/// # Example
///
/// ```rust,ignore
/// let mut from_paths = Vec::new();
/// from_paths.push("source/dir1");
/// from_paths.push("source/file.txt");
///
/// remove_items(&from_paths).unwrap();
/// ```
///
pub fn remove_items<P>(from_items: &[P]) -> Result<()>
where
P: AsRef<Path>,
{
for item in from_items {
let item = item.as_ref();
if item.is_dir() {
dir::remove(item)?;
} else {
file::remove(item)?
}
}
Ok(())
}