| 1 | // Copyright 2021-2024 Martin Pool |
| 2 | |
| 3 | //! Copy a directory tree, including mtimes and permissions. |
| 4 | //! |
| 5 | //! To copy a tree, first configure parameters on [CopyOptions] and then call |
| 6 | //! [CopyOptions::copy_tree]. |
| 7 | //! |
| 8 | //! # Features |
| 9 | //! |
| 10 | //! * Minimal dependencies: currently just `filetime` to support copying mtimes. |
| 11 | //! * Returns [CopyStats] describing how much data and how many files were |
| 12 | //! copied. |
| 13 | //! * Tested on Linux, macOS and Windows. |
| 14 | //! * Copies mtimes and permissions. |
| 15 | //! * Takes an optional callback to decide which entries are copied or skipped, |
| 16 | //! [CopyOptions::filter]. |
| 17 | //! * Takes an optional callback to show progress or record which files are copied, |
| 18 | //! [CopyOptions::after_entry_copied]. |
| 19 | //! |
| 20 | //! # Missing features that could be added |
| 21 | //! |
| 22 | //! * Options to _not_ copy mtimes or permissions. |
| 23 | //! * A callback that can decide whether to continue after an error. |
| 24 | //! * Overwrite existing directories or files. |
| 25 | //! * Copy single files: don't assume the source path is a directory. |
| 26 | //! * A dry-run mode. |
| 27 | //! |
| 28 | //! # Example |
| 29 | //! |
| 30 | //! ``` |
| 31 | //! use std::path::Path; |
| 32 | //! use cp_r::{CopyOptions, CopyStats}; |
| 33 | //! use tempfile; |
| 34 | //! |
| 35 | //! // Copy this crate's `src` directory. |
| 36 | //! let dest = tempfile::tempdir().unwrap(); |
| 37 | //! let stats = CopyOptions::new().copy_tree(Path::new("src"), dest.path()).unwrap(); |
| 38 | //! assert_eq!(stats.files, 2); |
| 39 | //! assert_eq!(stats.dirs, 0, "no children"); |
| 40 | //! assert_eq!(stats.symlinks, 0, "no symlinks"); |
| 41 | //! ``` |
| 42 | //! |
| 43 | //! # Release history |
| 44 | //! |
| 45 | //! ## 0.5.2 |
| 46 | //! |
| 47 | //! Released 2024-10-07. |
| 48 | //! |
| 49 | //! * New: Copy symlinks on Windows. |
| 50 | //! |
| 51 | //! * New: Declared and tested MSRV of 1.63. |
| 52 | //! |
| 53 | //! ## 0.5.1 |
| 54 | //! |
| 55 | //! Released 2022-03-24. |
| 56 | //! |
| 57 | //! * Change: Ignore errors when trying to set the mtime on copied files. This can |
| 58 | //! happen on Windows if the file is read-only. |
| 59 | //! |
| 60 | //! ## 0.5.0 |
| 61 | //! |
| 62 | //! Released 2022-02-15 |
| 63 | //! |
| 64 | //! ### API changes |
| 65 | //! |
| 66 | //! * The callback passed to [CopyOptions::after_entry_copied] now returns `Result<()>` |
| 67 | //! (previously `()`), so it can return an Err to abort copying. |
| 68 | //! |
| 69 | //! ## 0.4.0 |
| 70 | //! |
| 71 | //! Released 2021-11-30 |
| 72 | //! |
| 73 | //! ### API changes |
| 74 | //! |
| 75 | //! * Remove `copy_buffer_size`, `file_buffers_copied`: these are too niche to have in the public |
| 76 | //! API, and anyhow become meaningless when we use [std::fs::copy]. |
| 77 | //! |
| 78 | //! * New [ErrorKind::DestinationDoesNotExist]. |
| 79 | //! |
| 80 | //! * [Error::io_error] returns `Option<io::Error>` (previously just an `io::Error`): |
| 81 | //! errors from this crate may not have a direct `io::Error` source. |
| 82 | //! |
| 83 | //! * [CopyOptions::copy_tree] arguments are relaxed to `AsRef<Path>` so that they will accept |
| 84 | //! `&str`, `PathBuf`, `tempfile::TempDir`, etc. |
| 85 | //! |
| 86 | //! ### Improvements |
| 87 | //! |
| 88 | //! * Use [std::fs::copy], which is more efficient, and makes this crate simpler. |
| 89 | //! |
| 90 | //! ## 0.3.1 |
| 91 | //! |
| 92 | //! Released 2021-11-07 |
| 93 | //! |
| 94 | //! ### API changes |
| 95 | //! |
| 96 | //! * [CopyOptions::copy_tree] consumes `self` (rather than taking `&mut self`), |
| 97 | //! which reduces lifetime issues in accessing values owned by callbacks. |
| 98 | //! |
| 99 | //! ### New features |
| 100 | //! |
| 101 | //! * [CopyOptions::after_entry_copied] callback added, which can be used for |
| 102 | //! example to draw a progress bar. |
| 103 | //! |
| 104 | //! ## 0.3.0 |
| 105 | //! |
| 106 | //! Released 2021-11-06 |
| 107 | //! |
| 108 | //! ### API changes |
| 109 | //! |
| 110 | //! * [CopyOptions] builder functions now return `self` rather than `&mut self`. |
| 111 | //! * The actual copy operation is run by calling [CopyOptions::copy_tree], |
| 112 | //! rather than passing the options as a parameter to `copy_tree`. |
| 113 | //! * Rename `with_copy_buffer_size` to `copy_buffer_size`. |
| 114 | //! |
| 115 | //! ### New features |
| 116 | //! * A new option to provide a filter on which entries should be copied, |
| 117 | //! through [CopyOptions::filter]. |
| 118 | //! |
| 119 | //! ## 0.2.0 |
| 120 | //! * `copy_tree` will create the immediate destination directory by default, |
| 121 | //! but this can be controlled by [CopyOptions::create_destination]. The |
| 122 | //! destination, if created, is counted in [CopyStats::dirs] and inherits its |
| 123 | //! permissions from the source. |
| 124 | //! |
| 125 | //! ## 0.1.1 |
| 126 | //! * [Error] implements [std::error::Error] and [std::fmt::Display]. |
| 127 | //! |
| 128 | //! * [Error] is tested to be compatible with [Anyhow](https://docs.rs/anyhow). |
| 129 | //! (There is only a dev-dependency on Anyhow; users of this library won't |
| 130 | //! pull it in.) |
| 131 | //! |
| 132 | //! ## 0.1.0 |
| 133 | //! * Initial release. |
| 134 | |
| 135 | #![warn(missing_docs)] |
| 136 | |
| 137 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#; |
| 138 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 139 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, DirEntryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirEntry#}; |
| 140 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 141 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#}; |
| 142 | |
| 143 | #[cfg(windows)] |
| 144 | mod windows; |
| 145 | |
| 146 | #[cfg(windows)] |
| 147 | use windows::copy_symlink; |
| 148 | |
| 149 | /// Options for copying file trees. |
| 150 | /// |
| 151 | /// Default options may be OK for many callers: |
| 152 | /// * Preserve mtime and permissions. |
| 153 | /// * Create the destination if it does not exist. |
| 154 | pub struct CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> { |
| 155 | // TODO: Continue or stop on error? |
| 156 | // TODO: Option controlling whether to copy mtimes? |
| 157 | // TODO: Copy permissions? |
| 158 | create_destinationrust-analyzer cargo cp_r 0.5.2 CopyOptions#create_destination.: bool, |
| 159 | |
| 160 | // I agree with Clippy that the callbacks are complex types, but stable Rust |
| 161 | // seems to have no other way to spell it, because you can't make a type or |
| 162 | // trait alias for a Fn. |
| 163 | #[allow(clippy::type_complexity)] |
| 164 | filterrust-analyzer cargo cp_r 0.5.2 CopyOptions#filter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, &DirEntryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirEntry#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<bool> + 'f>>, |
| 165 | |
| 166 | #[allow(clippy::type_complexity)] |
| 167 | after_entry_copiedrust-analyzer cargo cp_r 0.5.2 CopyOptions#after_entry_copied.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, &fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::FileTyperust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/FileType#, &CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<()> + 'f>>, |
| 168 | } |
| 169 | |
| 170 | impl<'f> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> { |
| 171 | fn defaultrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`][Default]default().() -> CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> { |
| 172 | CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions# { |
| 173 | create_destinationrust-analyzer cargo cp_r 0.5.2 CopyOptions#create_destination.: true, |
| 174 | filterrust-analyzer cargo cp_r 0.5.2 CopyOptions#filter.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 175 | after_entry_copiedrust-analyzer cargo cp_r 0.5.2 CopyOptions#after_entry_copied.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | impl<'f> CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> { |
| 181 | /// Construct reasonable default options. |
| 182 | pub fn newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().() -> CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> { |
| 183 | CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::defaultrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`][Default]default().() |
| 184 | } |
| 185 | |
| 186 | /// Set whether to create the destination if it does not exist (the default), or return an error. |
| 187 | /// |
| 188 | /// Only the immediate destination is created, not all its parents. |
| 189 | #[must_use] |
| 190 | pub fn create_destinationrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]create_destination().(self, create_destination: bool) -> CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> { |
| 191 | CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions# { |
| 192 | create_destinationrust-analyzer cargo cp_r 0.5.2 CopyOptions#create_destination., |
| 193 | ..self |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /// Set a filter callback that can determine which files should be copied. |
| 198 | /// |
| 199 | /// The filter can return |
| 200 | /// * `Ok(true)` to copy an entry (and recursively continue into directories) |
| 201 | /// * `Ok(false)` to skip an entry (and anything inside the directory) |
| 202 | /// * `Err(_)` to stop copying and return this error |
| 203 | /// |
| 204 | /// The path is relative to the top of the tree. The [std::fs::DirEntry] gives access to the file type and other metadata of the source file. |
| 205 | /// |
| 206 | /// ``` |
| 207 | /// use std::fs; |
| 208 | /// use std::path::Path; |
| 209 | /// use cp_r::CopyOptions; |
| 210 | /// |
| 211 | /// let src = tempfile::tempdir().unwrap(); |
| 212 | /// fs::write(src.path().join("transient.tmp"), b"hello?").unwrap(); |
| 213 | /// fs::write(src.path().join("permanent.txt"), b"hello?").unwrap(); |
| 214 | /// let dest = tempfile::tempdir().unwrap(); |
| 215 | /// |
| 216 | /// let stats = CopyOptions::new() |
| 217 | /// .filter( |
| 218 | /// |path, _| Ok(path.extension().and_then(|s| s.to_str()) != Some("tmp"))) |
| 219 | /// .copy_tree(&src.path(), &dest.path()) |
| 220 | /// .unwrap(); |
| 221 | /// |
| 222 | /// assert!(dest.path().join("permanent.txt").exists()); |
| 223 | /// assert!(!dest.path().join("transient.tmp").exists()); |
| 224 | /// assert_eq!(stats.filtered_out, 1); |
| 225 | /// assert_eq!(stats.files, 1); |
| 226 | /// ``` |
| 227 | /// |
| 228 | /// *Note:* Due to limitations in the current Rust compiler's type inference |
| 229 | /// for closures, filter closures may give errors about lifetimes if they are |
| 230 | /// assigned to to a variable rather than declared inline in the parameter. |
| 231 | #[must_use] |
| 232 | pub fn filterrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]filter().<F>(self, filter: F) -> CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> |
| 233 | where |
| 234 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, &DirEntryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirEntry#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<bool> + 'f, |
| 235 | { |
| 236 | CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions# { |
| 237 | filterrust-analyzer cargo cp_r 0.5.2 CopyOptions#filter.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(filter)), |
| 238 | ..self |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /// Set a progress callback that's called after each entry is successfully copied. |
| 243 | /// |
| 244 | /// The callback is passed: |
| 245 | /// * The path, relative to the top of the tree, that was just copied. |
| 246 | /// * The [std::fs::FileType] of the entry that was copied. |
| 247 | /// * The [stats](CopyStats) so far, including the number of files copied. |
| 248 | /// |
| 249 | /// If the callback returns an error, it will abort the copy and the same |
| 250 | /// error will be returned from [CopyOptions::copy_tree]. |
| 251 | #[must_use] |
| 252 | pub fn after_entry_copiedrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]after_entry_copied().<F>(self, after_entry_copied: F) -> CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#<'f> |
| 253 | where |
| 254 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, &fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::FileTyperust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/FileType#, &CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<()> + 'f, |
| 255 | { |
| 256 | CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions# { |
| 257 | after_entry_copiedrust-analyzer cargo cp_r 0.5.2 CopyOptions#after_entry_copied.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(after_entry_copied)), |
| 258 | ..self |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /// Copy the tree according to the options. |
| 263 | /// |
| 264 | /// Returns [CopyStats] describing how many files were copied, etc. |
| 265 | pub fn copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().<P, Q>(mut self, src: P, dest: Q) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#> |
| 266 | where |
| 267 | P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, |
| 268 | Q: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, |
| 269 | { |
| 270 | let src = src.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 271 | let dest = dest.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().(); |
| 272 | |
| 273 | let mut stats = CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#::defaultrust-analyzer cargo cp_r 0.5.2 impl#[CopyStats][Default]default().(); |
| 274 | |
| 275 | // TODO: Handle the src not being a dir: copy that single entry. |
| 276 | if self.create_destinationrust-analyzer cargo cp_r 0.5.2 CopyOptions#create_destination. { |
| 277 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dest.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().() { |
| 278 | copy_dirrust-analyzer cargo cp_r 0.5.2 copy_dir().(src, dest, &mut stats)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 279 | } |
| 280 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dest.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().() { |
| 281 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo cp_r 0.5.2 Error#::newrust-analyzer cargo cp_r 0.5.2 impl#[Error]new().(ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::DestinationDoesNotExistrust-analyzer cargo cp_r 0.5.2 ErrorKind#DestinationDoesNotExist#, dest)); |
| 282 | } |
| 283 | |
| 284 | let mut subdir_queue: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#> = VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().(); |
| 285 | subdir_queue.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().("")); |
| 286 | |
| 287 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(subdir) = subdir_queue.pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().() { |
| 288 | let subdir_full_path = src.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&subdir); |
| 289 | for entry in fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().(&subdir_full_path) |
| 290 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::ReadDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadDir#, &subdir_full_path))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 291 | { |
| 292 | let dir_entry = entry.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| { |
| 293 | Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::ReadDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadDir#, &subdir_full_path) |
| 294 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 295 | let entry_subpath = subdir.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(dir_entry.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().()); |
| 296 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(filter) = &mut self.filterrust-analyzer cargo cp_r 0.5.2 CopyOptions#filter. { |
| 297 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().filter(&entry_subpath, &dir_entry)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 298 | stats.filtered_outrust-analyzer cargo cp_r 0.5.2 CopyStats#filtered_out. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 299 | continue; |
| 300 | } |
| 301 | } |
| 302 | let src_fullpath = src.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&entry_subpath); |
| 303 | let dest_fullpath = dest.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(&entry_subpath); |
| 304 | let file_type = dir_entry |
| 305 | .file_typerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_type().() |
| 306 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::ReadDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadDir#, &src_fullpath))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 307 | if file_type.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_file().() { |
| 308 | copy_filerust-analyzer cargo cp_r 0.5.2 copy_file().(&src_fullpath, &dest_fullpath, &mut stats)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 309 | } else if file_type.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_dir().() { |
| 310 | copy_dirrust-analyzer cargo cp_r 0.5.2 copy_dir().(&src_fullpath, &dest_fullpath, &mut stats)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 311 | subdir_queue.push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(entry_subpath.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().()); |
| 312 | } else if file_type.is_symlinkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_symlink().() { |
| 313 | copy_symlinkrust-analyzer cargo cp_r 0.5.2 copy_symlink().(&src_fullpath, &dest_fullpath, &mut stats)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 314 | } else { |
| 315 | // TODO: Include the file type. |
| 316 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo cp_r 0.5.2 Error#::newrust-analyzer cargo cp_r 0.5.2 impl#[Error]new().(ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::UnsupportedFileTyperust-analyzer cargo cp_r 0.5.2 ErrorKind#UnsupportedFileType#, src_fullpath)); |
| 317 | } |
| 318 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut f) = self.after_entry_copiedrust-analyzer cargo cp_r 0.5.2 CopyOptions#after_entry_copied. { |
| 319 | f(&entry_subpath, &file_type, &stats)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(stats) |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | /// Counters of how many things were copied. |
| 328 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 329 | pub struct CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats# { |
| 330 | /// The number of plain files copied. |
| 331 | pub filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files.: usize, |
| 332 | /// The number of directories copied. |
| 333 | pub dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs.: usize, |
| 334 | /// The number of symlinks copied. |
| 335 | pub symlinksrust-analyzer cargo cp_r 0.5.2 CopyStats#symlinks.: usize, |
| 336 | /// The number of bytes of file content copied, across all files. |
| 337 | pub file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes.: u64, |
| 338 | /// The number of entries filtered out by the [CopyOptions::filter] callback. |
| 339 | pub filtered_outrust-analyzer cargo cp_r 0.5.2 CopyStats#filtered_out.: usize, |
| 340 | } |
| 341 | |
| 342 | /// An error from copying a tree. |
| 343 | /// |
| 344 | /// At present this library does not support continuing after an error, so only the first error is |
| 345 | /// returned by [CopyOptions::copy_tree]. |
| 346 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 347 | pub struct Errorrust-analyzer cargo cp_r 0.5.2 Error# { |
| 348 | pathrust-analyzer cargo cp_r 0.5.2 Error#path.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 349 | /// The original IO error, if any. |
| 350 | iorust-analyzer cargo cp_r 0.5.2 Error#io.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#>, |
| 351 | kindrust-analyzer cargo cp_r 0.5.2 Error#kind.: ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#, |
| 352 | } |
| 353 | |
| 354 | /// A [std::result::Result] possibly containing a `cp_r` [Error]. |
| 355 | pub type Resultrust-analyzer cargo cp_r 0.5.2 Result#<T> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo cp_r 0.5.2 Error#>; |
| 356 | |
| 357 | impl Errorrust-analyzer cargo cp_r 0.5.2 Error# { |
| 358 | /// Construct a new error with no source. |
| 359 | pub fn newrust-analyzer cargo cp_r 0.5.2 impl#[Error]new().<P>(kind: ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#, path: P) -> Errorrust-analyzer cargo cp_r 0.5.2 Error# |
| 360 | where |
| 361 | P: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, |
| 362 | { |
| 363 | Errorrust-analyzer cargo cp_r 0.5.2 Error# { |
| 364 | pathrust-analyzer cargo cp_r 0.5.2 Error#path.: path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 365 | kindrust-analyzer cargo cp_r 0.5.2 Error#kind., |
| 366 | iorust-analyzer cargo cp_r 0.5.2 Error#io.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /// Construct a new error from a [std::io::Error]. |
| 371 | pub fn from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().<P>(io: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#, kind: ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#, path: P) -> Errorrust-analyzer cargo cp_r 0.5.2 Error# |
| 372 | where |
| 373 | P: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, |
| 374 | { |
| 375 | Errorrust-analyzer cargo cp_r 0.5.2 Error# { |
| 376 | pathrust-analyzer cargo cp_r 0.5.2 Error#path.: path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 377 | kindrust-analyzer cargo cp_r 0.5.2 Error#kind., |
| 378 | iorust-analyzer cargo cp_r 0.5.2 Error#io.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(io), |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /// The path where this error occurred. |
| 383 | pub fn pathrust-analyzer cargo cp_r 0.5.2 impl#[Error]path().(&self) -> &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path# { |
| 384 | // TODO: Be consistent about whether this is relative to the root etc. |
| 385 | &self.pathrust-analyzer cargo cp_r 0.5.2 Error#path. |
| 386 | } |
| 387 | |
| 388 | /// The IO error that caused this error, if any. |
| 389 | pub fn io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]io_error().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 390 | self.iorust-analyzer cargo cp_r 0.5.2 Error#io..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() |
| 391 | } |
| 392 | |
| 393 | /// The kind of error that occurred. |
| 394 | pub fn kindrust-analyzer cargo cp_r 0.5.2 impl#[Error]kind().(&self) -> ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind# { |
| 395 | self.kindrust-analyzer cargo cp_r 0.5.2 Error#kind. |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Errorrust-analyzer cargo cp_r 0.5.2 Error# { |
| 400 | fn sourcerust-analyzer cargo cp_r 0.5.2 impl#[Error][Error]source().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + 'static)> { |
| 401 | // It seems like you should be able to spell this like `self.io.as_ref().into()` but that |
| 402 | // doesn't work and I'm not sure why... |
| 403 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(io) = &self.iorust-analyzer cargo cp_r 0.5.2 Error#io. { |
| 404 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(io) |
| 405 | } else { |
| 406 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo cp_r 0.5.2 Error# { |
| 412 | fn fmtrust-analyzer cargo cp_r 0.5.2 impl#[Error][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 413 | use ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::*; |
| 414 | let kind_msg = match self.kindrust-analyzer cargo cp_r 0.5.2 Error#kind. { |
| 415 | ReadDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadDir# => "reading source directory", |
| 416 | ReadFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadFile# => "reading source file", |
| 417 | WriteFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#WriteFile# => "writing file", |
| 418 | CreateDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#CreateDir# => "creating directory", |
| 419 | ReadSymlinkrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadSymlink# => "reading symlink", |
| 420 | CreateSymlinkrust-analyzer cargo cp_r 0.5.2 ErrorKind#CreateSymlink# => "creating symlink", |
| 421 | UnsupportedFileTyperust-analyzer cargo cp_r 0.5.2 ErrorKind#UnsupportedFileType# => "unsupported file type", |
| 422 | CopyFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#CopyFile# => "copying file", |
| 423 | DestinationDoesNotExistrust-analyzer cargo cp_r 0.5.2 ErrorKind#DestinationDoesNotExist# => "destination directory does not exist", |
| 424 | Interruptedrust-analyzer cargo cp_r 0.5.2 ErrorKind#Interrupted# => "interrupted", |
| 425 | }; |
| 426 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(io) = &self.iorust-analyzer cargo cp_r 0.5.2 Error#io. { |
| 427 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}: {}: {}", kind_msg, self.pathrust-analyzer cargo cp_r 0.5.2 Error#path..displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().(), io) |
| 428 | } else { |
| 429 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}: {}", kind_msg, self.pathrust-analyzer cargo cp_r 0.5.2 Error#path..displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()) |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /// Various kinds of errors that can occur while copying a tree. |
| 435 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:)] |
| 436 | #[non_exhaustive] |
| 437 | pub enum ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind# { |
| 438 | /// Error listing a source directory. |
| 439 | ReadDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadDir#, |
| 440 | /// Error opening or reading a source file. |
| 441 | ReadFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadFile#, |
| 442 | /// Error creating or writing a destination file. |
| 443 | WriteFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#WriteFile#, |
| 444 | /// Error in copying a file: might be a read or write error. |
| 445 | CopyFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#CopyFile#, |
| 446 | /// Error creating a destination directory. |
| 447 | CreateDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#CreateDir#, |
| 448 | /// Error reading a symlink. |
| 449 | ReadSymlinkrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadSymlink#, |
| 450 | /// Error creating a symlink in the destination. |
| 451 | CreateSymlinkrust-analyzer cargo cp_r 0.5.2 ErrorKind#CreateSymlink#, |
| 452 | /// The source tree contains a type of file that this library can't copy, such as a Unix |
| 453 | /// FIFO. |
| 454 | UnsupportedFileTyperust-analyzer cargo cp_r 0.5.2 ErrorKind#UnsupportedFileType#, |
| 455 | /// The destination directory does not exist. |
| 456 | DestinationDoesNotExistrust-analyzer cargo cp_r 0.5.2 ErrorKind#DestinationDoesNotExist#, |
| 457 | /// The copy was interrupted by the user. |
| 458 | /// |
| 459 | /// This is not currently generated internally by `cp_r` but can be returned |
| 460 | /// by a callback. |
| 461 | Interruptedrust-analyzer cargo cp_r 0.5.2 ErrorKind#Interrupted#, |
| 462 | } |
| 463 | |
| 464 | fn copy_filerust-analyzer cargo cp_r 0.5.2 copy_file().(src: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, dest: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, stats: &mut CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<()> { |
| 465 | // TODO: Optionally first check and error if the destination exists. |
| 466 | let bytes_copied = |
| 467 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::copyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/copy().(src, dest).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::CopyFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#CopyFile#, src))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 468 | stats.file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<Self>`]add_assign().bytes_copied; |
| 469 | |
| 470 | let src_metadata = src |
| 471 | .metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]metadata().() |
| 472 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::ReadFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadFile#, src))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 473 | let src_mtime = filetimerust-analyzer cargo filetime 0.2.29 crate/::FileTimerust-analyzer cargo filetime 0.2.29 FileTime#::from_last_modification_timerust-analyzer cargo filetime 0.2.29 impl#[FileTime]from_last_modification_time().(&src_metadata); |
| 474 | // It's OK if we can't set the mtime. |
| 475 | let _ = filetimerust-analyzer cargo filetime 0.2.29 crate/::set_file_mtimerust-analyzer cargo filetime 0.2.29 set_file_mtime().(dest, src_mtime); |
| 476 | |
| 477 | // Permissions should have already been set by fs::copy. |
| 478 | stats.filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 479 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 480 | } |
| 481 | |
| 482 | fn copy_dirrust-analyzer cargo cp_r 0.5.2 copy_dir().(_src: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, dest: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, stats: &mut CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<()> { |
| 483 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(dest) |
| 484 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::CreateDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#CreateDir#, dest)) |
| 485 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|()| stats.dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1) |
| 486 | } |
| 487 | |
| 488 | #[cfg(unix)] |
| 489 | fn copy_symlinkrust-analyzer cargo cp_r 0.5.2 copy_symlink().(src: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, dest: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, stats: &mut CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#) -> Resultrust-analyzer cargo cp_r 0.5.2 Result#<()> { |
| 490 | let target = |
| 491 | fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_linkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_link().(src).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::ReadSymlinkrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadSymlink#, src))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 492 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::unixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/::symlinkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/unix/fs/symlink().(target, dest) |
| 493 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|io| Errorrust-analyzer cargo cp_r 0.5.2 Error#::from_io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]from_io_error().(io, ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::CreateSymlinkrust-analyzer cargo cp_r 0.5.2 ErrorKind#CreateSymlink#, dest))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 494 | stats.symlinksrust-analyzer cargo cp_r 0.5.2 CopyStats#symlinks. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 495 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 496 | } |