Skip to content

MountFS's listdir doesn't take into account existing mounts #486

Open
@Frankkkkk

Description

@Frankkkkk

Hi,
First of all thank you for this really good lib !

I'm hitting a small bug using MountFS: the listdir method doesn't take into account mounts for dir listing.

here's a simple test case:

#!/usr/bin/env python3
from fs.osfs import OSFS
from fs.mountfs import MountFS


mounted = OSFS('dir_a')
original = OSFS('dir_b')

final = MountFS()
final.mount('the_mount', mounted)
final.mount('', original)


print(f'Final FS /: {final.listdir("/")}')
print(f'mounted FS /: {mounted.listdir("/")}')
print(f'Final FS /the_mount: {final.listdir("/the_mount")}')

My fs is:

$ tree dir_a dir_b
dir_a
└── file_a
dir_b
└── file_b

and thus, the resulting final FS looks like so:

.
├── file_a
└── the_mount
    └── file_b

However running the script results in:

Final FS /: ['file_b']
mounted FS /: ['file_a']
Final FS /the_mount: ['file_a']

As we can see, the mounted FS is not taken into account by listdir, however it exists in the MountFS as show by the two last lines. The expected result should be:

Final FS /: ['file_b', 'the_mount']

I could try to hack something up but it would entail adding a final list to https://github.com/PyFilesystem/pyfilesystem2/blob/master/fs/mountfs.py#L159 , what do you think ?

Thanks and cheers !
Frank

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions