Fix lock workflow for webdav:

* internally, wait for condition that onExit-Method is exceuted (with timeout)
* store and execute onExitAction also for webdav
This commit is contained in:
Armin Schrenk
2021-04-15 10:14:28 +02:00
parent cd5c55aad7
commit 03886f88e8
3 changed files with 34 additions and 5 deletions

View File

@@ -42,7 +42,11 @@ import java.util.EnumSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static org.cryptomator.common.Constants.MASTERKEY_FILENAME;
@@ -70,6 +74,8 @@ public class Vault {
private final StringBinding accessPoint;
private final BooleanBinding accessPointPresent;
private final BooleanProperty showingStats;
private final Lock lock = new ReentrantLock(); //FIXME: naming
private final Condition isLocked = lock.newCondition(); //FIXME: improve naming
private volatile Volume volume;
@@ -146,6 +152,13 @@ public class Vault {
if (throwable != null) {
LOG.warn("Unexpected unmount and lock of vault " + getDisplayName(), throwable);
}
lock.lock();
try {
isLocked.signal();
} finally {
lock.unlock();
}
});
} catch (Exception e) {
destroyCryptoFileSystem();
@@ -163,6 +176,20 @@ public class Vault {
volume.unmount();
}
destroyCryptoFileSystem();
lock.lock();
try {
while (state.get() != VaultState.Value.LOCKED) {
if (!isLocked.await(3000, TimeUnit.MILLISECONDS)) {
throw new VolumeException("Locking failed"); //FIXME: other exception
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new VolumeException("Lock failed."); //FIXME: other/new exception
} finally {
lock.unlock();
}
}
public void reveal(Volume.Revealer vaultRevealer) throws VolumeException {

View File

@@ -17,8 +17,6 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -34,6 +32,7 @@ public class WebDavVolume implements Volume {
private WebDavServer server;
private WebDavServletController servlet;
private Mounter.Mount mount;
private Consumer<Throwable> onExitAction;
@Inject
public WebDavVolume(Provider<WebDavServer> serverProvider, VaultSettings vaultSettings, Settings settings, WindowsDriveLetters windowsDriveLetters) {
@@ -47,9 +46,10 @@ public class WebDavVolume implements Volume {
public void mount(CryptoFileSystem fs, String mountFlags, Consumer<Throwable> onExitAction) throws VolumeException {
startServlet(fs);
mountServlet();
this.onExitAction = onExitAction;
}
private void startServlet(CryptoFileSystem fs){
private void startServlet(CryptoFileSystem fs) {
if (server == null) {
server = serverProvider.get();
}
@@ -69,7 +69,7 @@ public class WebDavVolume implements Volume {
//on windows, prevent an automatic drive letter selection in the upstream library. Either we choose already a specifc one or there is no free.
Supplier<String> driveLetterSupplier;
if(System.getProperty("os.name").toLowerCase().contains("windows") && vaultSettings.winDriveLetter().isEmpty().get()) {
if (System.getProperty("os.name").toLowerCase().contains("windows") && vaultSettings.winDriveLetter().isEmpty().get()) {
driveLetterSupplier = () -> windowsDriveLetters.getAvailableDriveLetter().orElse(null);
} else {
driveLetterSupplier = () -> vaultSettings.winDriveLetter().get();
@@ -104,6 +104,7 @@ public class WebDavVolume implements Volume {
throw new VolumeException(e);
}
cleanup();
onExitAction.accept(null);
}
@Override
@@ -114,6 +115,7 @@ public class WebDavVolume implements Volume {
throw new VolumeException(e);
}
cleanup();
onExitAction.accept(null);
}
@Override

View File

@@ -83,7 +83,7 @@ public class LockWorkflow extends Task<Void> {
@Override
protected void succeeded() {
LOG.info("Lock of {} succeeded.", vault.getDisplayName());
//DO NOT SET VAULT STATE HERE, this is done by the vault internally
vault.stateProperty().transition(VaultState.Value.PROCESSING, VaultState.Value.LOCKED);
}
@Override