diff --git a/pom.xml b/pom.xml index 0ec1c08a..859c5522 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.cryptomator cryptofs - 1.9.9 + 1.9.10 Cryptomator Crypto Filesystem This library provides the Java filesystem provider used by Cryptomator. https://github.com/cryptomator/cryptofs @@ -14,7 +14,7 @@ - 1.3.1 + 1.3.2 2.27 29.0-jre 1.7.30 diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java index 867afd1c..4bda51a2 100644 --- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java +++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java @@ -24,7 +24,7 @@ class CryptoFileSystems { private static final Logger LOG = LoggerFactory.getLogger(CryptoFileSystems.class); private final ConcurrentMap fileSystems = new ConcurrentHashMap<>(); - private final CryptoFileSystemComponent.Builder cryptoFileSystemComponentBuilder; + private final CryptoFileSystemComponent.Builder cryptoFileSystemComponentBuilder; // sharing reusable builder via synchronized private final FileSystemCapabilityChecker capabilityChecker; @Inject @@ -33,7 +33,7 @@ public CryptoFileSystems(CryptoFileSystemComponent.Builder cryptoFileSystemCompo this.capabilityChecker = capabilityChecker; } - public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathToVault, CryptoFileSystemProperties properties) throws IOException { + public synchronized CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathToVault, CryptoFileSystemProperties properties) throws IOException { try { Path normalizedPathToVault = pathToVault.normalize(); CryptoFileSystemProperties adjustedProperites = adjustForCapabilities(normalizedPathToVault, properties); diff --git a/src/main/java/org/cryptomator/cryptofs/attr/AttributeProvider.java b/src/main/java/org/cryptomator/cryptofs/attr/AttributeProvider.java index 87db7c90..6a7c0db6 100644 --- a/src/main/java/org/cryptomator/cryptofs/attr/AttributeProvider.java +++ b/src/main/java/org/cryptomator/cryptofs/attr/AttributeProvider.java @@ -16,6 +16,7 @@ import org.cryptomator.cryptofs.common.CiphertextFileType; import javax.inject.Inject; +import javax.inject.Provider; import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; @@ -26,13 +27,13 @@ @CryptoFileSystemScoped public class AttributeProvider { - private final AttributeComponent.Builder attributeComponentBuilder; + private final Provider attributeComponentBuilderProvider; private final CryptoPathMapper pathMapper; private final Symlinks symlinks; @Inject - AttributeProvider(AttributeComponent.Builder attributeComponentBuilder, CryptoPathMapper pathMapper, Symlinks symlinks) { - this.attributeComponentBuilder = attributeComponentBuilder; + AttributeProvider(Provider attributeComponentBuilderProvider, CryptoPathMapper pathMapper, Symlinks symlinks) { + this.attributeComponentBuilderProvider = attributeComponentBuilderProvider; this.pathMapper = pathMapper; this.symlinks = symlinks; } @@ -45,7 +46,8 @@ public A readAttributes(CryptoPath cleartextPath } Path ciphertextPath = getCiphertextPath(cleartextPath, ciphertextFileType); A ciphertextAttrs = Files.readAttributes(ciphertextPath, type); - Optional cleartextAttrs = attributeComponentBuilder // + AttributeComponent.Builder builder = attributeComponentBuilderProvider.get(); + Optional cleartextAttrs = builder // .type(type) // .ciphertextFileType(ciphertextFileType) // .ciphertextPath(ciphertextPath) // diff --git a/src/main/java/org/cryptomator/cryptofs/attr/AttributeViewProvider.java b/src/main/java/org/cryptomator/cryptofs/attr/AttributeViewProvider.java index c5df2ac6..c3d753e2 100644 --- a/src/main/java/org/cryptomator/cryptofs/attr/AttributeViewProvider.java +++ b/src/main/java/org/cryptomator/cryptofs/attr/AttributeViewProvider.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import javax.inject.Inject; +import javax.inject.Provider; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.attribute.FileAttributeView; @@ -24,11 +25,11 @@ public class AttributeViewProvider { private static final Logger LOG = LoggerFactory.getLogger(AttributeViewProvider.class); - private final AttributeViewComponent.Builder attrViewComponentBuilder; + private final Provider attrViewComponentBuilderProvider; @Inject - AttributeViewProvider(AttributeViewComponent.Builder attrViewComponentBuilder) { - this.attrViewComponentBuilder = attrViewComponentBuilder; + AttributeViewProvider(Provider attrViewComponentBuilderProvider) { + this.attrViewComponentBuilderProvider = attrViewComponentBuilderProvider; } /** @@ -38,7 +39,8 @@ public class AttributeViewProvider { * @see Files#getFileAttributeView(java.nio.file.Path, Class, java.nio.file.LinkOption...) */ public A getAttributeView(CryptoPath cleartextPath, Class type, LinkOption... options) { - Optional view = attrViewComponentBuilder // + AttributeViewComponent.Builder builder = attrViewComponentBuilderProvider.get(); + Optional view = builder // .cleartextPath(cleartextPath) // .viewType(type) // .linkOptions(options) // diff --git a/src/main/java/org/cryptomator/cryptofs/dir/DirectoryStreamFactory.java b/src/main/java/org/cryptomator/cryptofs/dir/DirectoryStreamFactory.java index bcacb283..d16bbeb8 100644 --- a/src/main/java/org/cryptomator/cryptofs/dir/DirectoryStreamFactory.java +++ b/src/main/java/org/cryptomator/cryptofs/dir/DirectoryStreamFactory.java @@ -20,7 +20,7 @@ public class DirectoryStreamFactory { private final CryptoPathMapper cryptoPathMapper; - private final DirectoryStreamComponent.Builder directoryStreamComponentBuilder; + private final DirectoryStreamComponent.Builder directoryStreamComponentBuilder; // sharing reusable builder via synchronized private final Map streams = new HashMap<>(); private volatile boolean closed = false; diff --git a/src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFiles.java b/src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFiles.java index dea5f027..7dd4ecee 100644 --- a/src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFiles.java +++ b/src/main/java/org/cryptomator/cryptofs/fh/OpenCryptoFiles.java @@ -8,13 +8,11 @@ *******************************************************************************/ package org.cryptomator.cryptofs.fh; -import org.cryptomator.cryptofs.CryptoFileSystemComponent; import org.cryptomator.cryptofs.CryptoFileSystemScoped; import org.cryptomator.cryptofs.EffectiveOpenOptions; -import org.cryptomator.cryptofs.fh.OpenCryptoFile; -import org.cryptomator.cryptofs.fh.OpenCryptoFileComponent; import javax.inject.Inject; +import javax.inject.Provider; import java.io.Closeable; import java.io.IOException; import java.nio.BufferUnderflowException; @@ -32,12 +30,12 @@ @CryptoFileSystemScoped public class OpenCryptoFiles implements Closeable { - private final OpenCryptoFileComponent.Builder openCryptoFileComponentBuilder; + private final Provider openCryptoFileComponentBuilderProvider; private final ConcurrentMap openCryptoFiles = new ConcurrentHashMap<>(); @Inject - OpenCryptoFiles(OpenCryptoFileComponent.Builder openCryptoFileComponentBuilder) { - this.openCryptoFileComponentBuilder = openCryptoFileComponentBuilder; + OpenCryptoFiles(Provider openCryptoFileComponentBuilderProvider) { + this.openCryptoFileComponentBuilderProvider = openCryptoFileComponentBuilderProvider; } /** @@ -67,9 +65,10 @@ public OpenCryptoFile getOrCreate(Path ciphertextPath) { } private OpenCryptoFile create(Path normalizedPath) { - OpenCryptoFileComponent openCryptoFileComponent = openCryptoFileComponentBuilder - .path(normalizedPath) - .onClose(openCryptoFiles::remove) + OpenCryptoFileComponent.Builder builder = openCryptoFileComponentBuilderProvider.get(); + OpenCryptoFileComponent openCryptoFileComponent = builder // + .path(normalizedPath) // + .onClose(openCryptoFiles::remove) // .build(); return openCryptoFileComponent.openCryptoFile(); } diff --git a/src/test/java/org/cryptomator/cryptofs/attr/AttributeProviderTest.java b/src/test/java/org/cryptomator/cryptofs/attr/AttributeProviderTest.java index a856b83a..8b3c38b7 100644 --- a/src/test/java/org/cryptomator/cryptofs/attr/AttributeProviderTest.java +++ b/src/test/java/org/cryptomator/cryptofs/attr/AttributeProviderTest.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import javax.inject.Provider; import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.LinkOption; @@ -32,6 +33,7 @@ public class AttributeProviderTest { + private Provider attributeComponentBuilderProvider; private AttributeComponent.Builder attributeComponentBuilder; private AttributeComponent attributeComponent; private CryptoPathMapper pathMapper; @@ -45,8 +47,10 @@ public class AttributeProviderTest { @BeforeEach public void setup() throws IOException { + attributeComponentBuilderProvider = Mockito.mock(Provider.class); attributeComponentBuilder = Mockito.mock(AttributeComponent.Builder.class); attributeComponent = Mockito.mock(AttributeComponent.class); + Mockito.when(attributeComponentBuilderProvider.get()).thenReturn(attributeComponentBuilder); Mockito.when(attributeComponentBuilder.ciphertextFileType(Mockito.any())).thenReturn(attributeComponentBuilder); Mockito.when(attributeComponentBuilder.ciphertextPath(Mockito.any())).thenReturn(attributeComponentBuilder); Mockito.when(attributeComponentBuilder.ciphertextAttributes(Mockito.any())).thenReturn(attributeComponentBuilder); @@ -89,7 +93,7 @@ public void setup() throws IOException { Mockito.when(pathMapper.getCiphertextFileType(cleartextPath)).thenReturn(CiphertextFileType.FILE); Mockito.when(pathMapper.getCiphertextFilePath(cleartextPath)).thenReturn(ciphertextPath); - prov = new AttributeProvider(attributeComponentBuilder, pathMapper, symlinks); + prov = new AttributeProvider(attributeComponentBuilderProvider, pathMapper, symlinks); } @Test @@ -156,7 +160,7 @@ public void setup() throws IOException { Mockito.when(pathMapper.getCiphertextFileType(cleartextPath)).thenReturn(CiphertextFileType.DIRECTORY); Mockito.when(pathMapper.getCiphertextDir(cleartextPath)).thenReturn(new CiphertextDirectory("foo", ciphertextRawPath)); - prov = new AttributeProvider(attributeComponentBuilder, pathMapper, symlinks); + prov = new AttributeProvider(attributeComponentBuilderProvider, pathMapper, symlinks); } @Test @@ -183,7 +187,7 @@ public class SymbolicLinks { public void setup() throws IOException { Mockito.when(pathMapper.getCiphertextFileType(cleartextPath)).thenReturn(CiphertextFileType.SYMLINK); - prov = new AttributeProvider(attributeComponentBuilder, pathMapper, symlinks); + prov = new AttributeProvider(attributeComponentBuilderProvider, pathMapper, symlinks); } @Test diff --git a/src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFilesTest.java b/src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFilesTest.java index f043e701..c49de017 100644 --- a/src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFilesTest.java +++ b/src/test/java/org/cryptomator/cryptofs/fh/OpenCryptoFilesTest.java @@ -1,16 +1,13 @@ package org.cryptomator.cryptofs.fh; -import org.cryptomator.cryptofs.CryptoFileSystemComponent; import org.cryptomator.cryptofs.EffectiveOpenOptions; -import org.cryptomator.cryptofs.fh.OpenCryptoFile; -import org.cryptomator.cryptofs.fh.OpenCryptoFileComponent; -import org.cryptomator.cryptofs.fh.OpenCryptoFiles; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import javax.inject.Provider; import java.io.IOException; import java.lang.reflect.Field; import java.nio.ByteBuffer; @@ -25,6 +22,7 @@ public class OpenCryptoFilesTest { + private final Provider openCryptoFileComponentBuilderProvider = mock(Provider.class); private final OpenCryptoFileComponent.Builder openCryptoFileComponentBuilder = mock(OpenCryptoFileComponent.Builder.class); private final OpenCryptoFile file = mock(OpenCryptoFile.class, "file"); private final FileChannel ciphertextFileChannel = Mockito.mock(FileChannel.class); @@ -36,6 +34,7 @@ public void setup() throws IOException, ReflectiveOperationException { OpenCryptoFileComponent subComponent = mock(OpenCryptoFileComponent.class); Mockito.when(subComponent.openCryptoFile()).thenReturn(file); + Mockito.when(openCryptoFileComponentBuilderProvider.get()).thenReturn(openCryptoFileComponentBuilder); Mockito.when(openCryptoFileComponentBuilder.path(Mockito.any())).thenReturn(openCryptoFileComponentBuilder); Mockito.when(openCryptoFileComponentBuilder.onClose(Mockito.any())).thenReturn(openCryptoFileComponentBuilder); Mockito.when(openCryptoFileComponentBuilder.build()).thenReturn(subComponent); @@ -45,7 +44,7 @@ public void setup() throws IOException, ReflectiveOperationException { closeLockField.setAccessible(true); closeLockField.set(ciphertextFileChannel, new Object()); - inTest = new OpenCryptoFiles(openCryptoFileComponentBuilder); + inTest = new OpenCryptoFiles(openCryptoFileComponentBuilderProvider); } @Test