Created
February 5, 2021 16:02
-
-
Save keehun/5a05521de6cbd7b7a654003412ca3b9c to your computer and use it in GitHub Desktop.
Resolving Firmlinks in Python
This file contains 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
import fcntl | |
import os | |
path = '/Applications/Safari.app/' | |
# MacOS-only fcntl command defined in xnu/bsd/sys/fcntl.h | |
F_GETPATH_NOFIRMLINK = 102 | |
# The documented max length of an fcntl buffer in python documentation. | |
FCNTL_MAX_LENGTH = 1024 | |
fd = os.open(path, os.O_DIRECTORY) | |
full_path_bytes = fcntl.fcntl(fd, F_GETPATH_NOFIRMLINK, bytes(FCNTL_MAX_LENGTH)) | |
full_path = full_path_bytes.decode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment