Created
March 15, 2016 16:06
-
-
Save thcipriani/501c6aec17249821b2d8 to your computer and use it in GitHub Desktop.
Dumb umask calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
umask.py - a dumb script that demonstrates how umask(2) works | |
""" | |
def umask(default, mask): | |
"""A umask is the bitwise conjunction of default permissions | |
<default> and the bitwise negation of file-creation mode mask <mask>""" | |
new = [] | |
for d, m in zip(default, mask): | |
new.append(str(int(d) & ~int(m))) | |
return ''.join(new) | |
def file_umask(mask): | |
"""The default creation permission for files is 0666""" | |
return umask('0666', mask) | |
def dir_umask(mask): | |
"""The default creation permission for directories is 0777""" | |
return umask('0777', mask) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment