Requests on parent folders of valid vault urls no longer get delayed

This commit is contained in:
Markus Kreusch
2016-08-12 15:11:54 +02:00
parent 24df3c3809
commit 28f275c22d
8 changed files with 178 additions and 61 deletions
@@ -42,6 +42,7 @@ import org.cryptomator.frontend.Frontend;
import org.cryptomator.frontend.Frontend.MountParam;
import org.cryptomator.frontend.FrontendCreationFailedException;
import org.cryptomator.frontend.FrontendFactory;
import org.cryptomator.frontend.FrontendId;
import org.cryptomator.ui.settings.Settings;
import org.cryptomator.ui.util.DeferredClosable;
import org.cryptomator.ui.util.DeferredCloser;
@@ -73,7 +74,7 @@ public class Vault implements CryptoFileSystemDelegate {
private final Set<String> whitelistedResourcesWithInvalidMac = new HashSet<>();
private final AtomicReference<FileSystem> nioFileSystem = new AtomicReference<>();
private final String id;
private String mountName;
private Character winDriveLetter;
private Optional<StatsFileSystem> statsFileSystem = Optional.empty();
@@ -81,7 +82,8 @@ public class Vault implements CryptoFileSystemDelegate {
/**
* Package private constructor, use {@link VaultFactory}.
* @param string
*
* @param string
*/
Vault(String id, Path vaultDirectoryPath, ShorteningFileSystemFactory shorteningFileSystemFactory, CryptoFileSystemFactory cryptoFileSystemFactory, DeferredCloser closer) {
this.path = new SimpleObjectProperty<Path>(vaultDirectoryPath);
@@ -133,7 +135,7 @@ public class Vault implements CryptoFileSystemDelegate {
FileSystem normalizingFs = new NormalizedNameFileSystem(cryptoFs, SystemUtils.IS_OS_MAC_OSX ? Form.NFD : Form.NFC);
StatsFileSystem statsFs = new StatsFileSystem(normalizingFs);
statsFileSystem = Optional.of(statsFs);
Frontend frontend = frontendFactory.create(statsFs, contextPath());
Frontend frontend = frontendFactory.create(statsFs, FrontendId.from(id), stripStart(mountName, "/"));
filesystemFrontend = closer.closeLater(frontend);
frontend.mount(getMountParams(settings));
success = true;
@@ -146,10 +148,6 @@ public class Vault implements CryptoFileSystemDelegate {
}
}
private String contextPath() {
return String.format("/%s/%s", id, stripStart(mountName, "/"));
}
public synchronized void deactivateFrontend() {
filesystemFrontend.close();
statsFileSystem = Optional.empty();
@@ -312,7 +310,7 @@ public class Vault implements CryptoFileSystemDelegate {
public void setWinDriveLetter(Character winDriveLetter) {
this.winDriveLetter = winDriveLetter;
}
public String getId() {
return id;
}
@@ -8,18 +8,14 @@
*******************************************************************************/
package org.cryptomator.ui.model;
import static java.util.UUID.randomUUID;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.Base64;
import java.util.UUID;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.cryptomator.filesystem.crypto.CryptoFileSystemFactory;
import org.cryptomator.filesystem.shortening.ShorteningFileSystemFactory;
import org.cryptomator.frontend.FrontendId;
import org.cryptomator.ui.util.DeferredCloser;
@Singleton
@@ -41,34 +37,7 @@ public class VaultFactory {
}
public Vault createVault(Path path) {
return createVault(generateId(), path);
}
private String generateId() {
return asBase64String(nineBytesFrom(randomUUID()));
}
private String asBase64String(ByteBuffer bytes) {
ByteBuffer base64Buffer = Base64.getUrlEncoder().encode(bytes);
return new String(asByteArray(base64Buffer));
}
private ByteBuffer nineBytesFrom(UUID uuid) {
ByteBuffer uuidBuffer = ByteBuffer.allocate(9);
uuidBuffer.putLong(uuid.getMostSignificantBits());
uuidBuffer.put((byte)(uuid.getLeastSignificantBits() & 0xFF));
uuidBuffer.flip();
return uuidBuffer;
}
private byte[] asByteArray(ByteBuffer buffer) {
if (buffer.hasArray()) {
return buffer.array();
} else {
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
return bytes;
}
return createVault(FrontendId.generate().toString(), path);
}
}