8000 fix os.listdir() when current dir is '/' by dhalbert · Pull Request #932 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

fix os.listdir() when current dir is '/' #932

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

Merged
merged 1 commit into from
Jun 15, 2018

Conversation

dhalbert
Copy link
Collaborator
@dhalbert dhalbert commented Jun 15, 2018

This makes os.listdir() include mounted filesystems when the current directory is /.

Also fixes the mounted filesystem sometimes showing up as, e.g., b'sd' instead of 'sd'. Some code was treating a char * as an mp_obj_t by accident.

The handling of "" by mp_vfs_lookup_path() is not ideal when the main filesystem is mounted at /. This avoids that by actually passing in the current directory instead of "".

Note that os.listdir('.') when the current directory is / still does not include mounted filesystems, because all the path lookup code is pretty fragile. ../. wouldn't be handled properly either. We probably need functionality like os.path.abspath() to fix these properly, instead of having special-case code in the path lookup code now.

Fixes #249 adequately for now.

@dhalbert dhalbert requested a review from tannewt June 15, 2018 15:01
Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Awesome! Simple fixes. :-)

@tannewt tannewt merged commit 5ce1d71 into adafruit:master Jun 15, 2018
@dhalbert dhalbert deleted the listdir_root branch June 15, 2018 18:04
@ricardodeazambuja
Copy link

Hi,

I'm using the 2MB internal flash of a Feather M0 Express and os.listdir apparently is broken when the current dir is '/':

>>> os.chdir('/')
>>> os.listdir()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 2048 bytes

If I use os.listdir within different directory, it works as expected:

>>> os.mkdir('test')
>>> os.chdir('test')
>>> os.listdir()
[]

@tannewt
Copy link
Member
tannewt commented Aug 10, 2020

@ricardodeazambuja Please open a separate issue. This PR can't have its state modified anymore. Thanks!

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.

os.listdir inconsistent
3 participants
0