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

MountFS fixes #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

MountFS fixes #487

wants to merge 1 commit into from

Conversation

lurch
Copy link
Contributor

@lurch lurch commented Jun 20, 2021

Type of changes

  • Bug fix
  • Tests

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @PyFilesystem/maintainers may be pedantic in the code review.

Description

Addresses issues outlined #486

  • Don't allow MountFS to have an empty mount-path
  • Don't allow files/dirs to be created inside MountFS's internal MemoryFS
  • Change MountFS's .mounts attribute to a dict instead of a list of tuples
  • Add a MountFS.unmount method
  • Add associated unit-tests

It's a long time since I've done any PyFilesystem development, so this should should be considered "WIP code", comments welcome... (e.g. I'm not sure if the unmount method is actually useful?)

This should be reviewed with care as the "bugfixes" this includes (the first two bullet-points above) subtly change the API of MountFS.

* Don't allow files/dirs to be created inside MountFS's internal MemoryFS
* Change MountFS's .mounts attribute to a dict instead of a list of tuples
* Add a MountFS.unmount method
* Add associated unit-tests
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 95.246% when pulling a99ccd2 on mountfs_fixes into 2d0ffc3 on master.

@althonos althonos self-assigned this Jun 27, 2021
Copy link
Member

@althonos althonos left a comment

Choose a reason for hiding this comment

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

Hi @lurch , thanks a lot for this, sorry it went under my radar! I think it looks fine apart from the one change I requested (it's probably me being paranoid/thinking too hard about edge cases).

@@ -67,7 +69,7 @@ def __init__(self, auto_close=True):
super(MountFS, self).__init__()
self.auto_close = auto_close
self.default_fs = MemoryFS() # type: FS
self.mounts = [] # type: MutableSequence[Tuple[Text, FS]]
self.mounts = {} # type: Dict[Text, FS]
Copy link
Member

Choose a reason for hiding this comment

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

I think the reason a list was in use here was to preserve ordering of mounted files. Sure, a dict is fine for newer Python versions but I'd think this would change behaviour on Python 2.7. I think using collections.OrderedDict would work instead (and we can drop that when we move the code to PyFilesystem3).

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.

3 participants