Skip to content

Commit

Permalink
Merge pull request #51 from jose-acevedoflores/add-builder-methods-fo…
Browse files Browse the repository at this point in the history
…r-copy-options

Add builder style methods for CopyOptions
  • Loading branch information
webdesus committed Jun 4, 2022
2 parents 488d8a7 + 5661367 commit d4529d7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,42 @@ impl CopyOptions {
depth: 0,
}
}

/// Overwrite existing files if true.
pub fn overwrite(mut self, overwrite: bool) -> Self {
self.overwrite = overwrite;
self
}

/// Skip existing files if true.
pub fn skip_exist(mut self, skip_exist: bool) -> Self {
self.skip_exist = skip_exist;
self
}

/// 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.
pub fn buffer_size(mut self, buffer_size: usize) -> Self {
self.buffer_size = buffer_size;
self
}

/// Recursively copy a directory with a new name or place it inside the destination (default: false, same behaviors as cp -r on Unix)
pub fn copy_inside(mut self, copy_inside: bool) -> Self {
self.copy_inside = copy_inside;
self
}

/// Copy only contents without a creating a new folder in the destination folder.
pub fn content_only(mut self, content_only: bool) -> Self {
self.content_only = content_only;
self
}

/// Sets levels reading. Set 0 for read all directory folder
pub fn depth(mut self, depth: u64) -> Self {
self.depth = depth;
self
}
}

impl Default for CopyOptions {
Expand Down
18 changes: 18 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ impl CopyOptions {
buffer_size: 64000, //64kb
}
}

/// Sets the option true for overwrite existing files.
pub fn overwrite(mut self, overwrite: bool) -> Self {
self.overwrite = overwrite;
self
}

/// Sets the option true for skip existing files.
pub fn skip_exist(mut self, skip_exist: bool) -> Self {
self.skip_exist = skip_exist;
self
}

/// Sets buffer size for copy/move work only with receipt information about process work.
pub fn buffer_size(mut self, buffer_size: usize) -> Self {
self.buffer_size = buffer_size;
self
}
}

impl Default for CopyOptions {
Expand Down

0 comments on commit d4529d7

Please sign in to comment.