Repository: Tinche/aiofiles (language: python)

Issue:
Please add support for os.link()
https://docs.python.org/3/library/os.html#os.link


Discussion / hints:

Fix patch:
diff --git a/src/aiofiles/os.py b/src/aiofiles/os.py
index 4d22d67..fd25ed3 100644
--- a/src/aiofiles/os.py
+++ b/src/aiofiles/os.py
@@ -26,6 +26,7 @@ async def run(*args, loop=None, executor=None, **kwargs):
 makedirs = wrap(os.makedirs)
 rmdir = wrap(os.rmdir)
 removedirs = wrap(os.removedirs)
+link = wrap(os.link)
 
 if hasattr(os, "sendfile"):
     sendfile = wrap(os.sendfile)


Test patch:
diff --git a/tests/test_os.py b/tests/test_os.py
index d32ef97..485bacb 100644
--- a/tests/test_os.py
+++ b/tests/test_os.py
@@ -1,6 +1,7 @@
 """Tests for asyncio's os module."""
 import aiofiles.os
 import asyncio
+from os import stat
 from os.path import join, dirname, exists, isdir
 import pytest
 import platform
@@ -208,3 +209,19 @@ async def test_getctime():
     filename = join(dirname(__file__), "resources", "test_file1.txt")
     result = await aiofiles.os.path.getctime(filename)
     assert result
+
+
+@pytest.mark.asyncio
+async def test_link():
+    """Test the link call."""
+    src_filename = join(dirname(__file__), "resources", "test_file1.txt")
+    dst_filename = join(dirname(__file__), "resources", "test_file2.txt")
+    await aiofiles.os.link(src_filename, dst_filename)
+    assert (
+        exists(src_filename) and
+        exists(dst_filename) and
+        stat(src_filename).st_ino == stat(dst_filename).st_ino
+    )
+    await aiofiles.os.remove(dst_filename)
+    assert exists(src_filename) and exists(dst_filename) is False
+