Skip to content

Commit 72d17ad

Browse files
committed
BUG: Fix symlink test in copyfile
TEST: Test existing target code paths, and that files are left untouched
1 parent a26ef19 commit 72d17ad

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

nipype/utils/filemanip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
234234
keep = False
235235
if os.path.lexists(newfile):
236236
if os.path.islink(newfile):
237-
if all(os.path.readlink(newfile) == originalfile, not use_hardlink,
238-
not copy):
237+
if all((os.readlink(newfile) == originalfile, not use_hardlink,
238+
not copy)):
239239
keep = True
240240
elif posixpath.samefile(newfile, originalfile):
241241
keep = True

nipype/utils/tests/test_filemanip.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,21 @@ def test_linkchain():
157157
yield assert_false, os.path.islink(new_hdr3)
158158
yield assert_true, os.path.samefile(orig_img, new_img3)
159159
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)
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+
160175
os.unlink(new_img1)
161176
os.unlink(new_hdr1)
162177
os.unlink(new_img2)

0 commit comments

Comments
 (0)