-
-
Notifications
You must be signed in to change notification settings - Fork 49
Add Fuse mounting support. #33
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package org.cryptomator.cli.frontend; | ||
|
|
||
| import java.nio.file.Path; | ||
|
|
||
| import org.cryptomator.frontend.fuse.mount.CommandFailedException; | ||
| import org.cryptomator.frontend.fuse.mount.EnvironmentVariables; | ||
| import org.cryptomator.frontend.fuse.mount.FuseMountFactory; | ||
| import org.cryptomator.frontend.fuse.mount.Mount; | ||
| import org.cryptomator.frontend.fuse.mount.Mounter; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class FuseMount { | ||
| private static final Logger LOG = LoggerFactory.getLogger(FuseMount.class); | ||
|
|
||
| private Path vaultRoot; | ||
| private Path mountPoint; | ||
| private Mount mnt; | ||
|
|
||
| public FuseMount(Path vaultRoot, Path mountPoint) { | ||
| this.vaultRoot = vaultRoot; | ||
| this.mountPoint = mountPoint; | ||
| this.mnt = null; | ||
| } | ||
|
|
||
| public boolean mount() { | ||
| if (mnt != null) { | ||
| LOG.info("Already mounted to {}", mountPoint); | ||
| return false; | ||
| } | ||
|
|
||
| try { | ||
| Mounter mounter = FuseMountFactory.getMounter(); | ||
| EnvironmentVariables envVars = EnvironmentVariables.create().withFlags(mounter.defaultMountFlags()) | ||
| .withMountPoint(mountPoint).build(); | ||
| mnt = mounter.mount(vaultRoot, envVars); | ||
| LOG.info("Mounted to {}", mountPoint); | ||
| } catch (CommandFailedException e) { | ||
| LOG.error("Can't mount: {}, error: {}", mountPoint, e.getMessage()); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public void unmount() { | ||
| try { | ||
| mnt.unmount(); | ||
| LOG.info("Unmounted {}", mountPoint); | ||
| } catch (CommandFailedException e) { | ||
| LOG.error("Can't unmount gracefully: {}. Force unmount.", e.getMessage()); | ||
| forceUnmount(); | ||
| } | ||
| } | ||
|
|
||
| private void forceUnmount() { | ||
| try { | ||
| mnt.unmountForced(); | ||
| LOG.info("Unmounted {}", mountPoint); | ||
| } catch (CommandFailedException e) { | ||
| LOG.error("Force unmount failed: {}", e.getMessage()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.cryptomator.cli.frontend; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
|
|
||
| import org.cryptomator.frontend.webdav.WebDavServer; | ||
| import org.cryptomator.frontend.webdav.servlet.WebDavServletController; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class WebDav { | ||
| private static final Logger LOG = LoggerFactory.getLogger(WebDav.class); | ||
|
|
||
| private final WebDavServer server; | ||
| private ArrayList<WebDavServletController> servlets; | ||
|
|
||
| public WebDav(String bindAddr, int port) { | ||
| servlets = new ArrayList<>(); | ||
| server = WebDavServer.create(); | ||
| server.bind(bindAddr, port); | ||
| server.start(); | ||
| LOG.info("WebDAV server started: {}:{}", bindAddr, port); | ||
| } | ||
|
|
||
| public void stop() { | ||
| for (WebDavServletController controller : servlets) { | ||
| controller.stop(); | ||
| } | ||
| server.stop(); | ||
| } | ||
|
|
||
| public void addServlet(Path vaultRoot, String vaultName) { | ||
| WebDavServletController servlet = server.createWebDavServlet(vaultRoot, vaultName); | ||
| servlets.add(servlet); | ||
| servlet.start(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why is this?
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.
This is to retain the previous functionality for FUSE mounts (if no WebDAV server is not running): Starting the app mounts the vault and ctrl-c quits the app + umounts. If there is no loop for stdin it just quits the app immediately.
Please let me know if you have suggestions how to achieve this more cleanly!
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.
You can run FUSE in "blocking mode" (second argument of the
mountmethod), but you'd need to also overload the Mounter's mount method, as blocking is currently alwaysfalse:https://github.com/cryptomator/fuse-nio-adapter/blob/develop/src/main/java/org/cryptomator/frontend/fuse/mount/LinuxMounter.java#L22
I'd prefer this approach but leave it open to you.
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.
Thanks for the suggestion. I have a couple of concerns, though. Please let me know if they are valid:
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.
You're right. You can only have a single mount in this case. Ctrl+C will unmount it and end the process.
It can be released any time, there is no schedule we need to follow. It is just a matter of tagging and letting CI do its job.
MacMounter has the same boolean flag, which works the same way. I have already tested it locally.
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.
Ok. I think I would then keep this functionality as it is currently implemented as the previous WebDAV implementation also supports multiple mounts. Now you can basically add any number of WebDAV and/or FUSE mounts with a single instance.
From my side this PR is ready to be merged now in case it's fine for you too.
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.
I still think this is a debatable feature, since you can as well spawn multiple processes and thus have better control over each mounted vault. However, this is out of scope of this PR and should be discussed in a separate issue.
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.
Might this cause #35?