Skip to content
Open
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
5 changes: 5 additions & 0 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ def symlink(source_path, symlink_path, use_abspath_source=True):

if os.path.exists(symlink_path):
abs_source_path = os.path.abspath(source_path)
if not os.path.islink(symlink_path):
raise EasyBuildError("Trying to symlink %s to %s, but there already is a %s at %s.",
source_path, symlink_path, "file" if os.path.isfile(symlink_path) else "folder",
symlink_path)

symlink_target_path = os.path.abspath(os.readlink(symlink_path))
if abs_source_path != symlink_target_path:
raise EasyBuildError("Trying to symlink %s to %s, but the symlink already exists and points to %s.",
Expand Down
6 changes: 6 additions & 0 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,12 @@ def test_symlink_resolve_path(self):
(test_file2, link, test_file),
ft.symlink, test_file2, link)

# Test when symlink is an existing file
self.assertErrorRegex(EasyBuildError,
"Trying to symlink %s to %s, but there already is a file at %s." %
(test_file2, test_file, test_file),
ft.symlink, test_file2, test_file)

# test resolve_path
self.assertEqual(test_dir, ft.resolve_path(link_dir))
self.assertEqual(os.path.join(os.path.realpath(self.test_prefix), 'test', 'test.txt'), ft.resolve_path(link))
Expand Down