| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: t_cp.sh,v 1.1 2012/03/17 16:33:10 jruoho Exp $ | | 1 | # $NetBSD: t_cp.sh,v 1.2 2024/04/26 01:33:23 rillig Exp $ |
2 | # | | 2 | # |
3 | # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. | | 3 | # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. |
4 | # All rights reserved. | | 4 | # All rights reserved. |
5 | # | | 5 | # |
6 | # Redistribution and use in source and binary forms, with or without | | 6 | # Redistribution and use in source and binary forms, with or without |
7 | # modification, are permitted provided that the following conditions | | 7 | # modification, are permitted provided that the following conditions |
8 | # are met: | | 8 | # are met: |
9 | # 1. Redistributions of source code must retain the above copyright | | 9 | # 1. Redistributions of source code must retain the above copyright |
10 | # notice, this list of conditions and the following disclaimer. | | 10 | # notice, this list of conditions and the following disclaimer. |
11 | # 2. Redistributions in binary form must reproduce the above copyright | | 11 | # 2. Redistributions in binary form must reproduce the above copyright |
12 | # notice, this list of conditions and the following disclaimer in the | | 12 | # notice, this list of conditions and the following disclaimer in the |
13 | # documentation and/or other materials provided with the distribution. | | 13 | # documentation and/or other materials provided with the distribution. |
14 | # | | 14 | # |
| @@ -52,221 +52,221 @@ file_to_file_head() { | | | @@ -52,221 +52,221 @@ file_to_file_head() { |
52 | } | | 52 | } |
53 | file_to_file_body() { | | 53 | file_to_file_body() { |
54 | reset | | 54 | reset |
55 | | | 55 | |
56 | file_to_file_simple | | 56 | file_to_file_simple |
57 | file_to_file_preserve | | 57 | file_to_file_preserve |
58 | file_to_file_noflags | | 58 | file_to_file_noflags |
59 | } | | 59 | } |
60 | | | 60 | |
61 | file_to_file_simple() { | | 61 | file_to_file_simple() { |
62 | rm -f file2 | | 62 | rm -f file2 |
63 | umask 022 | | 63 | umask 022 |
64 | chmod 777 file | | 64 | chmod 777 file |
65 | atf_check -s eq:0 -o empty -e empty cp file file2 | | 65 | atf_check cp file file2 |
66 | cp_compare file_to_file_simple file file2 | | 66 | cp_compare file_to_file_simple file file2 |
67 | if [ `stat -f "%Lp" file2` != "755" ]; then | | 67 | if [ `stat -f "%Lp" file2` != "755" ]; then |
68 | atf_fail "new file not created with umask" | | 68 | atf_fail "new file not created with umask" |
69 | fi | | 69 | fi |
70 | | | 70 | |
71 | chmod 644 file | | 71 | chmod 644 file |
72 | chmod 777 file2 | | 72 | chmod 777 file2 |
73 | cp_compare file_to_file_simple file file2 | | 73 | cp_compare file_to_file_simple file file2 |
74 | if [ `stat -f "%Lp" file2` != "777" ]; then | | 74 | if [ `stat -f "%Lp" file2` != "777" ]; then |
75 | atf_fail "existing files permissions not retained" | | 75 | atf_fail "existing files permissions not retained" |
76 | fi | | 76 | fi |
77 | } | | 77 | } |
78 | | | 78 | |
79 | file_to_file_preserve() { | | 79 | file_to_file_preserve() { |
80 | rm file3 | | 80 | rm file3 |
81 | chmod 644 file | | 81 | chmod 644 file |
82 | chflags nodump file | | 82 | chflags nodump file |
83 | atf_check -s eq:0 -o empty -e empty cp -p file file3 | | 83 | atf_check cp -p file file3 |
84 | finfo=`stat -f "%p%u%g%m%z%f" file` | | 84 | finfo=`stat -f "%p%u%g%m%z%f" file` |
85 | f3info=`stat -f "%p%u%g%m%z%f" file3` | | 85 | f3info=`stat -f "%p%u%g%m%z%f" file3` |
86 | if [ $finfo != $f3info ]; then | | 86 | if [ $finfo != $f3info ]; then |
87 | atf_fail "attributes not preserved" | | 87 | atf_fail "attributes not preserved" |
88 | fi | | 88 | fi |
89 | } | | 89 | } |
90 | | | 90 | |
91 | file_to_file_noflags() { | | 91 | file_to_file_noflags() { |
92 | rm file3 | | 92 | rm file3 |
93 | chmod 644 file | | 93 | chmod 644 file |
94 | chflags nodump file | | 94 | chflags nodump file |
95 | atf_check -s eq:0 -o empty -e empty cp -p -N file file3 | | 95 | atf_check cp -p -N file file3 |
96 | finfo=`stat -f "%f" file` | | 96 | finfo=`stat -f "%f" file` |
97 | f3info=`stat -f "%f" file3` | | 97 | f3info=`stat -f "%f" file3` |
98 | if [ $finfo = $f3info ]; then | | 98 | if [ $finfo = $f3info ]; then |
99 | atf_fail "-p -N preserved file flags" | | 99 | atf_fail "-p -N preserved file flags" |
100 | fi | | 100 | fi |
101 | } | | 101 | } |
102 | | | 102 | |
103 | atf_test_case file_to_link | | 103 | atf_test_case file_to_link |
104 | file_to_link_head() { | | 104 | file_to_link_head() { |
105 | atf_set "descr" "Checks the copy of a file to a symbolic link" | | 105 | atf_set "descr" "Checks the copy of a file to a symbolic link" |
106 | } | | 106 | } |
107 | file_to_link_body() { | | 107 | file_to_link_body() { |
108 | reset | | 108 | reset |
109 | atf_check -s eq:0 -o empty -e empty cp file2 link | | 109 | atf_check cp file2 link |
110 | cp_compare file_to_link file file2 | | 110 | cp_compare file_to_link file file2 |
111 | } | | 111 | } |
112 | | | 112 | |
113 | atf_test_case link_to_file | | 113 | atf_test_case link_to_file |
114 | link_to_file_head() { | | 114 | link_to_file_head() { |
115 | atf_set "descr" "Checks the copy of a symbolic link to a file" | | 115 | atf_set "descr" "Checks the copy of a symbolic link to a file" |
116 | } | | 116 | } |
117 | link_to_file_body() { | | 117 | link_to_file_body() { |
118 | reset | | 118 | reset |
119 | # file and link are identical (not copied). | | 119 | # file and link are identical (not copied). |
120 | atf_check -s eq:1 -o empty -e ignore cp link file | | 120 | atf_check -s exit:1 -e ignore cp link file |
121 | atf_check -s eq:0 -o empty -e empty cp link file2 | | 121 | atf_check cp link file2 |
122 | cp_compare link_to_file file file2 | | 122 | cp_compare link_to_file file file2 |
123 | } | | 123 | } |
124 | | | 124 | |
125 | atf_test_case file_over_link | | 125 | atf_test_case file_over_link |
126 | file_over_link_head() { | | 126 | file_over_link_head() { |
127 | atf_set "descr" "Checks the copy of a file to a symbolic link" \ | | 127 | atf_set "descr" "Checks the copy of a file to a symbolic link" \ |
128 | "without following it" | | 128 | "without following it" |
129 | } | | 129 | } |
130 | file_over_link_body() { | | 130 | file_over_link_body() { |
131 | reset | | 131 | reset |
132 | atf_check -s eq:0 -o empty -e empty cp -P file link | | 132 | atf_check cp -P file link |
133 | cp_compare file_over_link file link | | 133 | cp_compare file_over_link file link |
134 | } | | 134 | } |
135 | | | 135 | |
136 | atf_test_case link_over_file | | 136 | atf_test_case link_over_file |
137 | link_over_file_head() { | | 137 | link_over_file_head() { |
138 | atf_set "descr" "Checks the copy of a symbolic link to a file" \ | | 138 | atf_set "descr" "Checks the copy of a symbolic link to a file" \ |
139 | "without following the former" | | 139 | "without following the former" |
140 | } | | 140 | } |
141 | link_over_file_body() { | | 141 | link_over_file_body() { |
142 | reset | | 142 | reset |
143 | atf_check -s eq:0 -o empty -e empty cp -P link file | | 143 | atf_check cp -P link file |
144 | if [ `readlink link` != `readlink file` ]; then | | 144 | if [ `readlink link` != `readlink file` ]; then |
145 | atf_fail "readlink link != readlink file" | | 145 | atf_fail "readlink link != readlink file" |
146 | fi | | 146 | fi |
147 | } | | 147 | } |
148 | | | 148 | |
149 | atf_test_case files_to_dir | | 149 | atf_test_case files_to_dir |
150 | files_to_dir_head() { | | 150 | files_to_dir_head() { |
151 | atf_set "descr" "Checks the copy of multiple files into a directory" | | 151 | atf_set "descr" "Checks the copy of multiple files into a directory" |
152 | } | | 152 | } |
153 | files_to_dir_body() { | | 153 | files_to_dir_body() { |
154 | reset | | 154 | reset |
155 | # can't copy multiple files to a file | | 155 | # can't copy multiple files to a file |
156 | atf_check -s eq:1 -o empty -e ignore cp file file2 file3 | | 156 | atf_check -s exit:1 -e ignore cp file file2 file3 |
157 | atf_check -s eq:0 -o empty -e empty cp file file2 link dir | | 157 | atf_check cp file file2 link dir |
158 | cp_compare files_to_dir file "dir/file" | | 158 | cp_compare files_to_dir file "dir/file" |
159 | } | | 159 | } |
160 | | | 160 | |
161 | atf_test_case dir_to_file | | 161 | atf_test_case dir_to_file |
162 | dir_to_file_head() { | | 162 | dir_to_file_head() { |
163 | atf_set "descr" "Checks the copy of a directory onto a file, which" \ | | 163 | atf_set "descr" "Checks the copy of a directory onto a file, which" \ |
164 | "should not work" | | 164 | "should not work" |
165 | } | | 165 | } |
166 | dir_to_file_body() { | | 166 | dir_to_file_body() { |
167 | reset | | 167 | reset |
168 | # can't copy a dir onto a file | | 168 | # can't copy a dir onto a file |
169 | atf_check -s eq:1 -o empty -e ignore cp dir file | | 169 | atf_check -s exit:1 -e ignore cp dir file |
170 | atf_check -s eq:1 -o empty -e ignore cp -R dir file | | 170 | atf_check -s exit:1 -e ignore cp -R dir file |
171 | } | | 171 | } |
172 | | | 172 | |
173 | atf_test_case file_to_linkdir | | 173 | atf_test_case file_to_linkdir |
174 | file_to_linkdir_head() { | | 174 | file_to_linkdir_head() { |
175 | atf_set "descr" "Checks the copy of a file to a symbolic link that" \ | | 175 | atf_set "descr" "Checks the copy of a file to a symbolic link that" \ |
176 | "points to a directory" | | 176 | "points to a directory" |
177 | } | | 177 | } |
178 | file_to_linkdir_body() { | | 178 | file_to_linkdir_body() { |
179 | reset | | 179 | reset |
180 | atf_check -s eq:0 -o empty -e empty cp file dirlink | | 180 | atf_check cp file dirlink |
181 | cp_compare file_to_linkdir file "dir/file" | | 181 | cp_compare file_to_linkdir file "dir/file" |
182 | | | 182 | |
183 | # overwrite the link | | 183 | # overwrite the link |
184 | atf_check -s eq:0 -o empty -e empty cp -P file dirlink | | 184 | atf_check cp -P file dirlink |
185 | atf_check -s eq:1 -o empty -e empty readlink dirlink | | 185 | atf_check -s exit:1 readlink dirlink |
186 | cp_compare file_to_linkdir file dirlink | | 186 | cp_compare file_to_linkdir file dirlink |
187 | } | | 187 | } |
188 | | | 188 | |
189 | atf_test_case linkdir_to_file | | 189 | atf_test_case linkdir_to_file |
190 | linkdir_to_file_head() { | | 190 | linkdir_to_file_head() { |
191 | atf_set "descr" "Checks the copy of a symbolic link that points to" \ | | 191 | atf_set "descr" "Checks the copy of a symbolic link that points to" \ |
192 | "a directory onto a file" | | 192 | "a directory onto a file" |
193 | } | | 193 | } |
194 | linkdir_to_file_body() { | | 194 | linkdir_to_file_body() { |
195 | reset | | 195 | reset |
196 | # cannot copy a dir onto a file | | 196 | # cannot copy a dir onto a file |
197 | atf_check -s eq:1 -o empty -e ignore cp dirlink file | | 197 | atf_check -s exit:1 -e ignore cp dirlink file |
198 | | | 198 | |
199 | # overwrite the link | | 199 | # overwrite the link |
200 | atf_check -s eq:0 -o empty -e empty cp -P dirlink file | | 200 | atf_check cp -P dirlink file |
201 | if [ `readlink file` != `readlink dirlink` ]; then | | 201 | if [ `readlink file` != `readlink dirlink` ]; then |
202 | atf_fail "readlink link != readlink file" | | 202 | atf_fail "readlink link != readlink file" |
203 | fi | | 203 | fi |
204 | } | | 204 | } |
205 | | | 205 | |
206 | dir_to_dne_no_R() { | | 206 | dir_to_dne_no_R() { |
207 | atf_check -s eq:1 -o empty -e ignore cp dir dir2 | | 207 | atf_check -s exit:1 -e ignore cp dir dir2 |
208 | } | | 208 | } |
209 | | | 209 | |
210 | dir_to_dne() { | | 210 | dir_to_dne() { |
211 | atf_check -s eq:0 -o empty -e empty cp -R dir dir2 | | 211 | atf_check cp -R dir dir2 |
212 | cp_compare dir_to_dne "dir/file" "dir2/file" | | 212 | cp_compare dir_to_dne "dir/file" "dir2/file" |
213 | readlink dir2/link >/dev/null | | 213 | readlink dir2/link >/dev/null |
214 | if [ $? -gt 0 ]; then | | 214 | if [ $? -gt 0 ]; then |
215 | atf_fail "-R didn't copy a link as a link" | | 215 | atf_fail "-R didn't copy a link as a link" |
216 | fi | | 216 | fi |
217 | } | | 217 | } |
218 | | | 218 | |
219 | dir_to_dir_H() { | | 219 | dir_to_dir_H() { |
220 | dir_to_dir_setup | | 220 | dir_to_dir_setup |
221 | atf_check -s eq:0 -o empty -e empty cp -R dir dir2 | | 221 | atf_check cp -R dir dir2 |
222 | | | 222 | |
223 | chmod 777 dir | | 223 | chmod 777 dir |
224 | | | 224 | |
225 | # copy a dir into a dir, only command-line links are followed | | 225 | # copy a dir into a dir, only command-line links are followed |
226 | atf_check -s eq:0 -o empty -e empty cp -R -H dirlink dir2 | | 226 | atf_check cp -R -H dirlink dir2 |
227 | cp_compare dir_to_dir_H "dir/file" "dir2/dirlink/file" | | 227 | cp_compare dir_to_dir_H "dir/file" "dir2/dirlink/file" |
228 | readlink dir2/dirlink/link >/dev/null | | 228 | readlink dir2/dirlink/link >/dev/null |
229 | if [ $? -gt 0 ]; then | | 229 | if [ $? -gt 0 ]; then |
230 | atf_fail "didn't copy a link as a link" | | 230 | atf_fail "didn't copy a link as a link" |
231 | fi | | 231 | fi |
232 | | | 232 | |
233 | # Created directories have the same mode as the corresponding | | 233 | # Created directories have the same mode as the corresponding |
234 | # source directory, unmodified by the process's umask. | | 234 | # source directory, unmodified by the process's umask. |
235 | if [ `stat -f "%Lp" dir2/dirlink` != "777" ]; then | | 235 | if [ `stat -f "%Lp" dir2/dirlink` != "777" ]; then |
236 | atf_fail "-R modified dir perms with umask" | | 236 | atf_fail "-R modified dir perms with umask" |
237 | fi | | 237 | fi |
238 | } | | 238 | } |
239 | | | 239 | |
240 | dir_to_dir_L() { | | 240 | dir_to_dir_L() { |
241 | dir_to_dir_setup | | 241 | dir_to_dir_setup |
242 | atf_check -s eq:0 -o empty -e empty cp -R dir dir2 | | 242 | atf_check cp -R dir dir2 |
243 | atf_check -s eq:0 -o empty -e empty cp -R -H dirlink dir2 | | 243 | atf_check cp -R -H dirlink dir2 |
244 | | | 244 | |
245 | # copy a dir into a dir, following all links | | 245 | # copy a dir into a dir, following all links |
246 | atf_check -s eq:0 -o empty -e empty cp -R -H -L dirlink dir2/dirlink | | 246 | atf_check cp -R -H -L dirlink dir2/dirlink |
247 | cp_compare dir_to_dir_L "dir/file" "dir2/dirlink/dirlink/file" | | 247 | cp_compare dir_to_dir_L "dir/file" "dir2/dirlink/dirlink/file" |
248 | # fail if -R -L copied a link as a link | | 248 | # fail if -R -L copied a link as a link |
249 | atf_check -s eq:1 -o ignore -e empty readlink dir2/dirlink/dirlink/link | | 249 | atf_check -s exit:1 -o ignore readlink dir2/dirlink/dirlink/link |
250 | } | | 250 | } |
251 | | | 251 | |
252 | dir_to_dir_subdir_exists() { | | 252 | dir_to_dir_subdir_exists() { |
253 | # recursively copy a dir into another dir, with some subdirs already | | 253 | # recursively copy a dir into another dir, with some subdirs already |
254 | # existing | | 254 | # existing |
255 | cleanup | | 255 | cleanup |
256 | | | 256 | |
257 | mkdir -p dir/1 dir/2 dir/3 target/2 | | 257 | mkdir -p dir/1 dir/2 dir/3 target/2 |
258 | echo "file" > dir/2/file | | 258 | echo "file" > dir/2/file |
259 | atf_check -s eq:0 -o empty -e empty cp -R dir/* target | | 259 | atf_check cp -R dir/* target |
260 | cp_compare dir_to_dir_subdir_exists "dir/2/file" "target/2/file" | | 260 | cp_compare dir_to_dir_subdir_exists "dir/2/file" "target/2/file" |
261 | } | | 261 | } |
262 | | | 262 | |
263 | dir_to_dir_setup() { | | 263 | dir_to_dir_setup() { |
264 | reset | | 264 | reset |
265 | umask 077 | | 265 | umask 077 |
266 | cp -P file file2 file3 link dir | | 266 | cp -P file file2 file3 link dir |
267 | } | | 267 | } |
268 | | | 268 | |
269 | atf_test_case dir_to_dir | | 269 | atf_test_case dir_to_dir |
270 | dir_to_dir_head() { | | 270 | dir_to_dir_head() { |
271 | atf_set "descr" "Checks the copy of a directory onto another directory" | | 271 | atf_set "descr" "Checks the copy of a directory onto another directory" |
272 | } | | 272 | } |