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

Identify sockets #177

Merged
merged 1 commit into from
Mar 3, 2021
Merged

Identify sockets #177

merged 1 commit into from
Mar 3, 2021

Conversation

mxr
Copy link
Member

@mxr mxr commented Mar 2, 2021

This is part of #72

tests/identify_test.py Outdated Show resolved Hide resolved
Comment on lines 44 to 52
return {DIRECTORY}
if os.path.islink(path):
return {SYMLINK}
if stat.S_ISSOCK(os.stat(path).st_mode):
return {SOCKET}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should do a single os.stat call and then decide based on that -- as it is right now this is going to do at least 4 stat calls to determine these tags

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean isdir, islink, and others do os.stat under the hood?

Copy link
Member

Choose a reason for hiding this comment

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

yep, and lexists

Copy link
Member Author

Choose a reason for hiding this comment

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

For os.access do you recommend hand-rolling something that supports both posix & windows or leaving it as-is? Also for some of the public functions that check if a file exists & other properties, should I remove those checks (because the caller checks them) to save on stat calls, or preserve the behavior because they're public?

Copy link
Member Author

Choose a reason for hiding this comment

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

Went with erring towards leaving more code as-is but lmk if there's anything else straightforward that I missed

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants