Skip to content
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

Add aiofiles.os.symlink function #124

Merged
merged 2 commits into from
Jan 6, 2022
Merged

Add aiofiles.os.symlink function #124

merged 2 commits into from
Jan 6, 2022

Conversation

jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Jan 6, 2022

The os module in the stdlib provides a function called os.symlink that creates a symlink to the src file. This PR adds the async version of that.

Docs: https://docs.python.org/3/library/os.html#os.symlink

I've added the relevant unit test in test_os.py, plus updated the aiofiles.os.link test to better differentiate the two.

tests/test_os.py Outdated
Comment on lines 236 to 251
initial_src_nlink = stat(src_filename).st_nlink
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
exists(src_filename)
and exists(dst_filename)
and (stat(src_filename).st_ino == stat(dst_filename).st_ino)
and (stat(src_filename).st_nlink == initial_src_nlink + 1)(
stat(dst_filename).st_nlink == 2
)
)
await aiofiles.os.remove(dst_filename)
assert exists(src_filename) and exists(dst_filename) is False
assert (
exists(src_filename)
and exists(dst_filename) is False
and (stat(src_filename).st_nlink == initial_src_nlink)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the aiofiles.os.link test to better show the difference between symlinks and hardlinks:

  • Symlinks: Share the same inode (st_ino).
  • Hardlinks: Share the same inode (st_ino) AND have their link counter (st_nlink) incremented.

@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2022

Codecov Report

Merging #124 (554e090) into master (db6c5be) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #124      +/-   ##
==========================================
+ Coverage   89.66%   89.70%   +0.03%     
==========================================
  Files          10       10              
  Lines         300      301       +1     
==========================================
+ Hits          269      270       +1     
  Misses         31       31              
Impacted Files Coverage Δ
src/aiofiles/os.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db6c5be...554e090. Read the comment docs.

@Tinche
Copy link
Owner

Tinche commented Jan 6, 2022

You're on quite a roll! Thanks.

@Tinche Tinche merged commit 313f4a5 into Tinche:master Jan 6, 2022
@jpy-git jpy-git deleted the aiofiles.os.symlink branch January 6, 2022 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants