@@ -158,20 +158,6 @@ def test_linkchain():
158
158
yield assert_true , os .path .samefile (orig_img , new_img3 )
159
159
yield assert_true , os .path .samefile (orig_hdr , new_hdr3 )
160
160
161
- # Test that re-copying leaves files
162
- stat1 = os .stat (new_img1 )
163
- stat2 = os .stat (new_img2 )
164
- stat3 = os .stat (new_img3 )
165
- # Same symlink
166
- copyfile (orig_img , new_img1 )
167
- # Hash matches
168
- copyfile (new_img1 , new_img2 , copy = True )
169
- # Hardlinks
170
- copyfile (new_img1 , new_img3 , copy = True , use_hardlink = True )
171
- yield assert_equal , stat1 , os .stat (new_img1 )
172
- yield assert_equal , stat2 , os .stat (new_img2 )
173
- yield assert_equal , stat3 , os .stat (new_img3 )
174
-
175
161
os .unlink (new_img1 )
176
162
os .unlink (new_hdr1 )
177
163
os .unlink (new_img2 )
@@ -183,6 +169,55 @@ def test_linkchain():
183
169
os .unlink (orig_hdr )
184
170
185
171
172
+ def test_recopy ():
173
+ # Re-copying with the same parameters on an unchanged file should be
174
+ # idempotent
175
+ #
176
+ # Test for copying from regular files and symlinks
177
+ orig_img , orig_hdr = _temp_analyze_files ()
178
+ pth , fname = os .path .split (orig_img )
179
+ img_link = os .path .join (pth , 'imglink.img' )
180
+ hdr_link = os .path .join (pth , 'imglink.hdr' )
181
+ new_img = os .path .join (pth , 'newfile.img' )
182
+ new_hdr = os .path .join (pth , 'newfile.hdr' )
183
+ copyfile (orig_img , img_link )
184
+ for copy in (True , False ):
185
+ for use_hardlink in (True , False ):
186
+ for hashmethod in ('timestamp' , 'content' ):
187
+ kwargs = {'copy' : copy , 'use_hardlink' : use_hardlink ,
188
+ 'hashmethod' : hashmethod }
189
+ # Copying does not preserve the original file's timestamp, so
190
+ # we may delete and re-copy, if the test is slower than a clock
191
+ # tick
192
+ if copy and not use_hardlink and hashmethod == 'timestamp' :
193
+ continue
194
+ copyfile (orig_img , new_img , ** kwargs )
195
+ img_stat = os .stat (new_img )
196
+ hdr_stat = os .stat (new_hdr )
197
+ copyfile (orig_img , new_img , ** kwargs )
198
+ err_msg = "Regular - OS: {}; Copy: {}; Hardlink: {}" .format (
199
+ os .name , copy , use_hardlink )
200
+ yield assert_equal , img_stat , os .stat (new_img ), err_msg
201
+ yield assert_equal , hdr_stat , os .stat (new_hdr ), err_msg
202
+ os .unlink (new_img )
203
+ os .unlink (new_hdr )
204
+
205
+ copyfile (img_link , new_img , ** kwargs )
206
+ img_stat = os .stat (new_img )
207
+ hdr_stat = os .stat (new_hdr )
208
+ copyfile (img_link , new_img , ** kwargs )
209
+ err_msg = "Symlink - OS: {}; Copy: {}; Hardlink: {}" .format (
210
+ os .name , copy , use_hardlink )
211
+ yield assert_equal , img_stat , os .stat (new_img ), err_msg
212
+ yield assert_equal , hdr_stat , os .stat (new_hdr ), err_msg
213
+ os .unlink (new_img )
214
+ os .unlink (new_hdr )
215
+ os .unlink (img_link )
216
+ os .unlink (hdr_link )
217
+ os .unlink (orig_img )
218
+ os .unlink (orig_hdr )
219
+
220
+
186
221
def test_copyfallback ():
187
222
if os .name is not 'posix' :
188
223
return
0 commit comments