Title: Handle not executable directories for `os.listdir` · Issue #117402 · python/cpython · GitHub
Open Graph Title: Handle not executable directories for `os.listdir` · Issue #117402 · python/cpython
X Title: Handle not executable directories for `os.listdir` · Issue #117402 · python/cpython
Description: Bug report Bug description: I have a directory with "rw-" permisions with a file inaccessible.txt: >>> import os >>> os.listdir("directory") ['inaccessible.txt'] >>> os.path.exists("directory/inaccessible.txt") False That's inconsistent ...
Open Graph Description: Bug report Bug description: I have a directory with "rw-" permisions with a file inaccessible.txt: >>> import os >>> os.listdir("directory") ['inaccessible.txt'] >>> os.path.exists("directory/inacc...
X Description: Bug report Bug description: I have a directory with "rw-" permisions with a file inaccessible.txt: >>> import os >>> os.listdir("directory") ['inaccessible...
Opengraph URL: https://github.com/python/cpython/issues/117402
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Handle not executable directories for `os.listdir`","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nI have a directory with \"rw-\" permisions with a file `inaccessible.txt`:\r\n\r\n```python\r\n\u003e\u003e\u003e import os\r\n\u003e\u003e\u003e os.listdir(\"directory\")\r\n['inaccessible.txt']\r\n\u003e\u003e\u003e os.path.exists(\"directory/inaccessible.txt\")\r\nFalse\r\n```\r\n\r\nThat's inconsistent behaviour: `os.listdir` says `directory/inaccessible.txt` exists, while `os.path.exists` says it does not.\r\nThis can be solved simply be raising a `PermissionError` (or a subclass) for `os.listdir` when the directory is not executable.\r\nI can't think of any situation outside of a CTF where it would be useful to be able to list the files in such directories.\r\n\r\n_Note that this is different from a directory with \"-wx\" permisions with a file `secret.txt`:_\r\n\r\n```python\r\n\u003e\u003e\u003e import os\r\n\u003e\u003e\u003e os.listdir(\"directory\")\r\nTraceback (most recent call last):\r\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\r\nPermissionError: [Errno 13] Permission denied: 'directory'\r\n\u003e\u003e\u003e os.path.exists(\"directory/secret.txt\")\r\nTrue\r\n```\r\n\r\n_In this case, files can still be accessed if you know the filename._\r\n\r\n### CPython versions tested on:\r\n\r\n3.12\r\n\r\n### Operating systems tested on:\r\n\r\nmacOS","author":{"url":"https://github.com/nineteendo","@type":"Person","name":"nineteendo"},"datePublished":"2024-03-31T11:58:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/117402/cpython/issues/117402"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:533c0cc3-ff38-19f3-8373-dabb7ae18cef |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D6D2:10503:1A00A9D:21CC3D7:696B2FC9 |
| html-safe-nonce | 5235f6b705a31255e8dbdd5530e1ba809761d1b41b061ce2859495c70e3cf026 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkQyOjEwNTAzOjFBMDBBOUQ6MjFDQzNENzo2OTZCMkZDOSIsInZpc2l0b3JfaWQiOiI2NjY1MjYxODgyMDQ0MDQ2ODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ce85c5af61e59b4c9d513ec6740444e71382f750670d35878ca6a05b72f3835a |
| hovercard-subject-tag | issue:2216930853 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/117402/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b74653e1419e1ae7ca6e6833a80bdf7c02dec7161b790e65d891106c296fd292/python/cpython/issues/117402 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b74653e1419e1ae7ca6e6833a80bdf7c02dec7161b790e65d891106c296fd292/python/cpython/issues/117402 |
| og:image:alt | Bug report Bug description: I have a directory with "rw-" permisions with a file inaccessible.txt: >>> import os >>> os.listdir("directory") ['inaccessible.txt'] >>> os.path.exists("directory/inacc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nineteendo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width