Skip to content

Commit

Permalink
Merge branch 'release/1.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Jan 20, 2021
2 parents e66c297 + 56a58a8 commit 923ebda
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 41 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/cryptomator/fuse-nio-adapter.svg?branch=develop)](https://travis-ci.org/cryptomator/fuse-nio-adapter)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/47914e82b4c54f39b6150c24b83d7d09)](https://www.codacy.com/app/cryptomator/fuse-nio-adapter?utm_source=github.com&utm_medium=referral&utm_content=cryptomator/fuse-nio-adapter&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/47914e82b4c54f39b6150c24b83d7d09)](https://www.codacy.com/app/cryptomator/fuse-nio-adapter?utm_source=github.com&utm_medium=referral&utm_content=cryptomator/fuse-nio-adapter&utm_campaign=Badge_Coverage)
[![Build Status](https://github.com/cryptomator/fuse-nio-adapter/workflows/Build/badge.svg)](https://github.com/cryptomator/fuse-nio-adapter/actions?query=workflow%3ABuild)
[![Codacy Code Quality](https://app.codacy.com/project/badge/Grade/47914e82b4c54f39b6150c24b83d7d09)](https://www.codacy.com/gh/cryptomator/fuse-nio-adapter)
[![Codacy Coverage](https://app.codacy.com/project/badge/Coverage/47914e82b4c54f39b6150c24b83d7d09)](https://www.codacy.com/gh/cryptomator/fuse-nio-adapter)
[![Known Vulnerabilities](https://snyk.io/test/github/cryptomator/fuse-nio-adapter/badge.svg)](https://snyk.io/test/github/cryptomator/fuse-nio-adapter)

# fuse-nio-adapter
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>fuse-nio-adapter</artifactId>
<version>1.2.6</version>
<version>1.2.7</version>
<name>FUSE-NIO-Adapter</name>
<description>Access resources at a given NIO path via FUSE.</description>
<url>https://github.com/cryptomator/fuse-nio-adapter</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.google.common.base.Preconditions;
import org.cryptomator.frontend.fuse.FuseNioAdapter;

import java.awt.Desktop;
import java.io.IOException;
import java.nio.file.Path;

abstract class AbstractMount implements Mount {
Expand All @@ -25,16 +23,8 @@ public Path getMountPoint() {
}

@Override
public void revealInFileManager() throws CommandFailedException {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().open(mountPoint.toFile());
} catch (IOException e) {
throw new CommandFailedException(e);
}
} else {
throw new CommandFailedException("API to browse files not supported.");
}
public void reveal(Revealer revealer) throws RevealException {
revealer.reveal(mountPoint);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cryptomator.frontend.fuse.mount;

import com.google.common.collect.ObjectArrays;
import org.cryptomator.frontend.fuse.AdapterFactory;
import org.cryptomator.frontend.fuse.FuseNioAdapter;
import org.slf4j.Logger;
Expand All @@ -12,7 +11,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

class LinuxMounter implements Mounter {
Expand Down Expand Up @@ -52,23 +50,8 @@ public boolean isApplicable() {

private static class LinuxMount extends AbstractMount {

private final Optional<String> customRevealCommand;

private LinuxMount(FuseNioAdapter fuseAdapter, EnvironmentVariables envVars) {
super(fuseAdapter, envVars.getMountPoint());
this.customRevealCommand = envVars.getRevealCommand();
}

@Override
public void revealInFileManager() throws CommandFailedException {
if (customRevealCommand.isPresent()) {
ProcessBuilder command = new ProcessBuilder(ObjectArrays.concat(customRevealCommand.get().split("\\s+"), mountPoint.toString()));
command.directory(mountPoint.getParent().toFile());
Process proc = ProcessUtil.startAndWaitFor(command, 5, TimeUnit.SECONDS);
ProcessUtil.assertExitValue(proc, 0);
} else {
super.revealInFileManager();
}
}

@Override
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/cryptomator/frontend/fuse/mount/Mount.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
public interface Mount extends AutoCloseable {

/**
* Attempts to reveal the mounted FUSE volume in the operating system's default file manager.
* Attempts to reveal the mounted FUSE volume. This method <i>may</i> choose to ignore the given <code>revealer</code>. If the revealer is invoked, it <i>must</i> reveal the given path.
*
* @throws CommandFailedException
* @deprecated Use {@link #getMountPoint()} and reveal it yourself (e.g. using JavaFX's <code>application.getHostServices().showDocument(mountPoint)</code>)
* @param revealer Object containing necessary commands to show the Mount content to the user.
*/
@Deprecated
void revealInFileManager() throws CommandFailedException;
void reveal(Revealer revealer) throws RevealException;

/**
* Returns this Mount's mount point.
Expand All @@ -37,6 +35,7 @@ public interface Mount extends AutoCloseable {

/**
* Releases associated resources
*
* @throws CommandFailedException If closing failed
* @throws IllegalStateException If still mounted
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cryptomator.frontend.fuse.mount;

public class RevealException extends Exception {

public RevealException(String msg) {
super(msg);
}

public RevealException(Throwable cause) {
super(cause);
}

public RevealException(String msg, Throwable cause) {
super(msg, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.cryptomator.frontend.fuse.mount;

import java.nio.file.Path;

@FunctionalInterface
public interface Revealer {

void reveal(Path path) throws RevealException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cryptomator.frontend.fuse.mount;

import java.awt.Desktop;
import java.io.IOException;
import java.nio.file.Path;

public class AwtFrameworkRevealer implements Revealer {

@Override
public void reveal(Path path) throws RevealException {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().open(path.toFile());
} catch (IOException e) {
throw new RevealException(e);
}
} else {
throw new RevealException("Desktop API to browse files not supported.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

public class LinuxEnvironmentTest {

Expand All @@ -21,7 +20,11 @@ public static void main(String[] args) throws IOException {
.build();
Path tmp = Paths.get("/tmp");
try (Mount mnt = mounter.mount(tmp, envVars)) {
mnt.revealInFileManager();
try {
mnt.reveal(new AwtFrameworkRevealer());
} catch (RevealException e) {
System.out.println("Reveal failed.");
}
System.out.println("Wait for it...");
System.in.read();
mnt.unmountForced();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ private static void mount(Path pathToMirror, Path mountPoint) {
.build();
try (Mount mnt = mounter.mount(pathToMirror, envVars)) {
LOG.info("Mounted successfully. Enter anything to stop the server...");
mnt.revealInFileManager();
try {
mnt.reveal(new AwtFrameworkRevealer());
} catch (RevealException e) {
LOG.warn("Reveal failed.", e);
}
System.in.read();
try {
mnt.unmount();
Expand Down

0 comments on commit 923ebda

Please sign in to comment.