Debian Codegraph @

tests/tests.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 // Copyright 2021-2024 Martin Pool
2
3 //! Public API tests for `cp_r`.
4
5 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/::{create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir()., metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/metadata()., readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read()., writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write()., DirEntryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/DirEntry#, FileTyperust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/FileType#};
6 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/;
7 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#};
8
9 use tempfilerust-analyzer cargo tempfile 3.27.0 crate/::TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#;
10
11 use cp_rrust-analyzer cargo cp_r 0.5.2 crate/::*;
12
13 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
14 fn basic_copyrust-analyzer cargo cp_r 0.5.2 basic_copy().() {
15 let src = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
16 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
17 let file_content = b"hello world\n";
18 let file_name = "a file";
19 let src_file_path = src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(file_name);
20 writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(&src_file_path, file_content).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
21
22 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::defaultrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`][Default]default().()
23 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().())
24 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
25
26 let dest_file_path = &dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(file_name);
27 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(dest_file_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), file_content);
28 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files., 1);
29 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes., file_content.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64);
30
31 let src_mtime = metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/metadata().(&src_file_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().modifiedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]modified().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
32 let dest_mtime = metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/metadata().(dest_file_path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().modifiedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]modified().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
33 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(src_mtime, dest_mtime);
34
35 // Filesystems might not retain perfect resolution on mtimes, but they should at least be
36 // within 1ms everywhere(?); the error might be in either direction.
37 let d = dest_mtime
38 .duration_sincerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[SystemTime]duration_since().(src_mtime)
39 .or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]or_else().(|_| src_mtime.duration_sincerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[SystemTime]duration_since().(dest_mtime))
40 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
41 dbgrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/dbg!!(d);
42 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d.as_microsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_micros().() <rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u128][`PartialOrd<Self>`]lt(). 1000);
43 }
44
45 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
46 fn subdirsrust-analyzer cargo cp_r 0.5.2 subdirs().() {
47 let src = TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#::newrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
48 let dest = TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir#::newrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
49
50 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
51 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("aa")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
52 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
53 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b/bb")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
54
55 let file_content = b"some file content\n";
56 writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a/aa/aaafile"), file_content).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
57
58 // Note here that we can just path a reference to the TempDirs without calling
59 // `.path()`, because they `AsRef` to a `Path`.
60 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::defaultrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`][Default]default().().copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(&src, &dest).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
61
62 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
63 readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a/aa/aaafile")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
64 file_content
65 );
66 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/metadata().(dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b/bb"))
67 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
68 .file_typerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]file_type().()
69 .is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_dir().());
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files., 1);
71 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes., file_content.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64);
72 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs., 4);
73 }
74
75 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
76 fn clean_error_on_nonexistent_sourcerust-analyzer cargo cp_r 0.5.2 clean_error_on_nonexistent_source().() {
77 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
78 let err = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().().copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().("nothing", &dest).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
79 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("err = {:#?}", err);
80 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(err.pathrust-analyzer cargo cp_r 0.5.2 impl#[Error]path().().starts_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]starts_with().("nothing"));
81 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(err.kindrust-analyzer cargo cp_r 0.5.2 impl#[Error]kind().(), ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::ReadDirrust-analyzer cargo cp_r 0.5.2 ErrorKind#ReadDir#);
82 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(err.io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]io_error().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().(), iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::NotFoundrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#NotFound#);
83 }
84
85 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
86 fn create_destination_by_defaultrust-analyzer cargo cp_r 0.5.2 create_destination_by_default().() {
87 let empty_src = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
88 let dest_parent = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
89 let dest = dest_parent.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("nonexistent_child");
90 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
91 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(empty_src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), &dest)
92 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
93 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dest.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().());
94 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs., 1);
95 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files., 0);
96 }
97
98 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
99 fn create_destination_when_requestedrust-analyzer cargo cp_r 0.5.2 create_destination_when_requested().() {
100 let empty_src = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
101 let dest_parent = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
102 let dest = dest_parent.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("nonexistent_child");
103 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
104 .create_destinationrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]create_destination().(true)
105 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(&empty_src, &dest)
106 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
107 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(dest.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]is_dir().());
108 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs., 1);
109 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files., 0);
110 }
111
112 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
113 fn optionally_destination_must_existrust-analyzer cargo cp_r 0.5.2 optionally_destination_must_exist().() {
114 // TODO: At least add an option to create the destination if it does not exist.
115 // But, for now, it must.
116 let dest_parent = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
117 let dest = dest_parent.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("nonexistent_child");
118 let err = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
119 .create_destinationrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]create_destination().(false)
120 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().("src", &dest)
121 .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
122 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("err = {:#?}", err);
123 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(err.kindrust-analyzer cargo cp_r 0.5.2 impl#[Error]kind().(), ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::DestinationDoesNotExistrust-analyzer cargo cp_r 0.5.2 ErrorKind#DestinationDoesNotExist#);
•124 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
125 err.pathrust-analyzer cargo cp_r 0.5.2 impl#[Error]path().().starts_withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]starts_with().(&dest),
126 "path in the error relates to the destination"
127 );
128 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(err.io_errorrust-analyzer cargo cp_r 0.5.2 impl#[Error]io_error().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().(), "no underlying io::Error");
129 }
130
131 #[cfg(unix)]
132 #[ignore]
133 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
134 fn clean_error_failing_to_copy_devicesrust-analyzer cargo cp_r 0.5.2 clean_error_failing_to_copy_devices().() {
135 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
136 let err = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
137 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().("/dev", dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().())
138 .unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
139 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:#?}", err);
140 let kind = err.kindrust-analyzer cargo cp_r 0.5.2 impl#[Error]kind().();
141 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
142 kind == ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::UnsupportedFileTyperust-analyzer cargo cp_r 0.5.2 ErrorKind#UnsupportedFileType# || kind == ErrorKindrust-analyzer cargo cp_r 0.5.2 ErrorKind#::CopyFilerust-analyzer cargo cp_r 0.5.2 ErrorKind#CopyFile#,
143 "unexpected ErrorKind {:?}",
144 kind
145 );
146 // Depending on OS peculiarities, we might detect this at different points, and therefore
147 // return different error kinds, and there may or may not be an ioerror.
148 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(err.pathrust-analyzer cargo cp_r 0.5.2 impl#[Error]path().().strip_prefixrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]strip_prefix().("/dev/").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
149 let formatted = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", err);
150 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
151 formatted.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("unsupported file type: /dev/")
152 || formatted.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(
153 "the source path is neither a regular file nor a symlink to a regular file"
154 ),
155 "unexpected string format: {:?}",
156 formatted
157 );
158 }
159
160 #[cfg(unix)]
161 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
162 fn copy_dangling_symlinkrust-analyzer cargo cp_r 0.5.2 copy_dangling_symlink().() {
163 let src = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
164 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
165 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().("dangling target", src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a_link")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
166 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
167 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().())
168 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
169 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:#?}", stats);
170 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
171 stats,
172 CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats# {
173 filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files.: 0,
174 dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs.: 0,
175 symlinksrust-analyzer cargo cp_r 0.5.2 CopyStats#symlinks.: 1,
176 file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes.: 0,
177 filtered_outrust-analyzer cargo cp_r 0.5.2 CopyStats#filtered_out.: 0,
178 }
179 );
180 }
181
182 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
183 fn filter_by_pathrust-analyzer cargo cp_r 0.5.2 filter_by_path().() {
184 let src = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
185 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
186
187 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
188 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
189 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b/bb")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
190 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("aa")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
191
192 let file_content = b"some file content\n";
193 writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a/aa/aaafile"), file_content).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
194
195 fn not_brust-analyzer cargo cp_r 0.5.2 not_b().(path: &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#) -> cp_rrust-analyzer cargo cp_r 0.5.2 crate/::Resultrust-analyzer cargo cp_r 0.5.2 Result#<bool> {
196 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("b"))
197 }
198 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
199 .filterrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]filter().(not_brust-analyzer cargo cp_r 0.5.2 not_b().)
200 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().())
201 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
202
203 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
204 readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a/aa/aaafile")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
205 file_content
206 );
207 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
208 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
209 stats,
210 CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats# {
211 filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files.: 1,
212 file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes.: file_content.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64,
213 dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs.: 2,
214 symlinksrust-analyzer cargo cp_r 0.5.2 CopyStats#symlinks.: 0,
215 filtered_outrust-analyzer cargo cp_r 0.5.2 CopyStats#filtered_out.: 1,
216 }
217 );
218 }
219
220 const AAA_CONTENTrust-analyzer cargo cp_r 0.5.2 AAA_CONTENT.: &[u8] = b"some file content\n";
221
222 fn setup_a_b_srcrust-analyzer cargo cp_r 0.5.2 setup_a_b_src().() -> tempfilerust-analyzer cargo tempfile 3.27.0 crate/::TempDirrust-analyzer cargo tempfile 3.27.0 dir/TempDir# {
223 let src = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
224 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
225 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
226 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b/bb")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
227 create_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/create_dir().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("aa")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
228
229 let file_content = AAA_CONTENTrust-analyzer cargo cp_r 0.5.2 AAA_CONTENT.;
230 writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/write().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a/aa/aaafile"), file_content).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
231
232 src
233 }
234
235 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
236 fn filter_by_mut_closurerust-analyzer cargo cp_r 0.5.2 filter_by_mut_closure().() {
237 let src = setup_a_b_srcrust-analyzer cargo cp_r 0.5.2 setup_a_b_src().();
238 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
239
240 // Filter paths and also collect all the paths we've seen, as an example of a filter
241 // that's more than a simple function pointer.
242 let mut filter_seen_paths: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
243 let stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::defaultrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`][Default]default().()
244 .filterrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]filter().(|path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, _de| {
245 filter_seen_paths.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(path.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('\\', "/"));
246 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("b"))
247 })
248 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().())
249 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
250
251 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("a/aa/aaafile")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), AAA_CONTENTrust-analyzer cargo cp_r 0.5.2 AAA_CONTENT.,);
252 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("b").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().());
253 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
254 stats,
255 CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats# {
256 filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files.: 1,
257 file_bytesrust-analyzer cargo cp_r 0.5.2 CopyStats#file_bytes.: AAA_CONTENTrust-analyzer cargo cp_r 0.5.2 AAA_CONTENT..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64,
258 dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs.: 2,
259 symlinksrust-analyzer cargo cp_r 0.5.2 CopyStats#symlinks.: 0,
260 filtered_outrust-analyzer cargo cp_r 0.5.2 CopyStats#filtered_out.: 1,
261 }
262 );
263 // The order in which entries are seen is not guaranteed, and in practice
264 // will be partly determined by the unpredictable order that the filesystem
265 // returns directory entries.
266 //
267 // "b" is seen (because the filter records it before filtering it out), but
268 // b's children are not visited.
269 filter_seen_paths.sort_unstablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]sort_unstable().();
270 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(filter_seen_paths, ["a", "a/aa", "a/aa/aaafile", "b"]);
271 }
272
273 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
274 fn after_entry_copied_callbackrust-analyzer cargo cp_r 0.5.2 after_entry_copied_callback().() {
275 let src = setup_a_b_srcrust-analyzer cargo cp_r 0.5.2 setup_a_b_src().();
276 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
277 let mut progress_seen: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, FileTyperust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/FileType#)> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
278 let mut last_stats = CopyStatsrust-analyzer cargo cp_r 0.5.2 CopyStats#::defaultrust-analyzer cargo cp_r 0.5.2 impl#[CopyStats][Default]default().();
279
280 // We can't count on the entries being seen in any particular order, but there are other
281 // properties we can check...
282 let final_stats = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().()
283 .after_entry_copiedrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]after_entry_copied().(|p, ft, stats| {
284 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
285 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().progress_seen.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|(pp, _)| pp == p),
286 "filename has not been seen before"
287 );
288 progress_seen.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().((p.to_ownedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path][ToOwned]to_owned().(), *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ft));
289 if ft.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_file().() {
290 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.filesrust-analyzer cargo cp_r 0.5.2 CopyStats#files., last_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][`Add<Self>`]add(). 1);
291 } else if ft.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_dir().() {
292 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(stats.dirsrust-analyzer cargo cp_r 0.5.2 CopyStats#dirs., last_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][`Add<Self>`]add(). 1);
293 } else {
294 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("unexpected file type {:?}", ft);
295 }
296 last_stats = stats.clonerust-analyzer cargo cp_r 0.5.2 impl#[CopyStats][Clone]clone().();
297 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
298 })
299 .copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().())
300 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
301 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
302 last_stats, final_stats,
303 "progress after the final copy include stats equal to the overall final stats"
304 );
305 }
306
307 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
308 fn after_entry_callback_error_terminates_copyrust-analyzer cargo cp_r 0.5.2 after_entry_callback_error_terminates_copy().() {
309 let src = setup_a_b_srcrust-analyzer cargo cp_r 0.5.2 setup_a_b_src().();
310 let dest = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::tempdirrust-analyzer cargo tempfile 3.27.0 dir/tempdir().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
311
312 // Stop after copying one file. The order in which files are copied is not defined, but we should see
313 // exactly one in the result.
314 let options = CopyOptionsrust-analyzer cargo cp_r 0.5.2 CopyOptions#::newrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]new().().after_entry_copiedrust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]after_entry_copied().(|p, ft, _stats| {
315 if ft.is_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[FileType]is_file().() {
316 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#::Interruptedrust-analyzer cargo cp_r 0.5.2 ErrorKind#Interrupted#, p))
317 } else {
318 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
319 }
320 });
321 let result = options.copy_treerust-analyzer cargo cp_r 0.5.2 impl#[`CopyOptions<'f>`]copy_tree().(src.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().(), dest.pathrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir]path().());
322
323 let err = result.unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
324 let err_str = err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
325 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
326 err_str.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("interrupted"),
327 "unexpected err_str: {:?}",
328 err_str
329 );
330
331 let err_debug = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", err);
332 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
333 err_debug.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("Error") && err_debug.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("kind: Interrupted"),
334 "unexpected err_debug: {:?}",
335 err_debug
336 );
337 }