-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add Filesystem::mount_or_else #57
Conversation
aef3ff1
to
16af6af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't feel like try_mount
is the proper name.
Maybe mount_with_prepare
?
I’m not entirely happy with |
Is this going to be used with anything other than I would have initially just gone with |
Even if it’s just called with A more interesting case would be journaling. Here we first want to try to mount the filesystem, and if it fails, recover from the journal. I’m not sure if we will end up using this method for IFS recovery in the nitrokey-3-firmware, but I think it would make sense to support the use case. |
@sosthene-nitrokey How about |
Looks good! |
When mounting a filesystem, often code like this is used: if !Filesystem::is_mountable(alloc, storage) { Filesystem::format(storage).ok(); } Filesystem::mount(alloc, storage) This mounts the filesystem twice because Filesystem::is_mountable is equivalent to Filesystem::mount(...).is_ok(). Depending on the storage implementation, mounting the filesystem can have significant cost. But directly calling Filesystem::mount and re-mounting in the error case is prohibited by the borrow checker. This patch adds a mount_or_else method that accepts a callable that is called on mount error. Afterwards, mounting is re-tried.
When mounting a filesystem, often code like this is used:
This mounts the filesystem twice because Filesystem::is_mountable is equivalent to Filesystem::mount(...).is_ok(). Depending on the storage implementation, mounting the filesystem can have significant cost. But directly calling Filesystem::mount and re-mounting in the error case is prohibited by the borrow checker.
This patch adds a mount_or_else method that accepts a callable that is called on mount error. Afterwards, mounting is re-tried.