Commit fb3ab79c by Peter Weidenbach

create symlink creates directories if necessary

parent f8792d09
......@@ -116,6 +116,7 @@ def create_symlink(src_path, dst_path):
:return: None
"""
try:
create_dir_for_file(dst_path)
os.symlink(src_path, dst_path)
except FileExistsError as e:
logging.debug("Could not create Link: File exists: {}".format(e))
......
......@@ -77,6 +77,10 @@ class Test_FailSafeFileOperations(unittest.TestCase):
symlink_path = os.path.join(self.tmp_dir.name, 'test_symlink')
create_symlink(test_file_path, symlink_path)
self.assertEqual(os.readlink(symlink_path), test_file_path)
symlink_path_none_existing_dir = os.path.join(self.tmp_dir.name, 'some_dir/test_symlink')
create_symlink(test_file_path, symlink_path_none_existing_dir)
self.assertEqual(os.readlink(symlink_path_none_existing_dir), test_file_path)
# check error handling
create_symlink(test_file_path, symlink_path)
def test_get_safe_name(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment