Skip to content

FIX: Fix symlink test in copyfile #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Upcoming release 0.13

* TST: reduce the size of docker images & use tags for images (https://github.com/nipy/nipype/pull/1564)
* ENH: Implement missing inputs/outputs in FSL AvScale (https://github.com/nipy/nipype/pull/1563)
* FIX: Fix symlink test in copyfile (https://github.com/nipy/nipype/pull/1570)


Release 0.12.1 (August 3, 2016)
Expand Down
4 changes: 2 additions & 2 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
keep = False
if os.path.lexists(newfile):
if os.path.islink(newfile):
if all(os.path.readlink(newfile) == originalfile, not use_hardlink,
not copy):
if all((os.readlink(newfile) == originalfile, not use_hardlink,
not copy)):
keep = True
elif posixpath.samefile(newfile, originalfile):
keep = True
Expand Down
15 changes: 15 additions & 0 deletions nipype/utils/tests/test_filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ def test_linkchain():
yield assert_false, os.path.islink(new_hdr3)
yield assert_true, os.path.samefile(orig_img, new_img3)
yield assert_true, os.path.samefile(orig_hdr, new_hdr3)

# Test that re-copying leaves files
stat1 = os.stat(new_img1)
stat2 = os.stat(new_img2)
stat3 = os.stat(new_img3)
# Same symlink
copyfile(orig_img, new_img1)
# Hash matches
copyfile(new_img1, new_img2, copy=True)
# Hardlinks
copyfile(new_img1, new_img3, copy=True, use_hardlink=True)
yield assert_equal, stat1, os.stat(new_img1)
yield assert_equal, stat2, os.stat(new_img2)
yield assert_equal, stat3, os.stat(new_img3)

os.unlink(new_img1)
os.unlink(new_hdr1)
os.unlink(new_img2)
Expand Down