Skip to content

Commit

Permalink
Merge branch 'release/1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jul 4, 2017
2 parents 62949e1 + de2da9b commit 39a7993
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 22 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>cryptofs</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<name>Cryptomator Crypto Filesystem</name>
<description>This library provides the Java filesystem provider used by Cryptomator.</description>
<url>https://github.com/cryptomator/cryptofs</url>
Expand Down Expand Up @@ -67,11 +67,6 @@
<artifactId>cryptolib</artifactId>
<version>${cryptolib.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/cryptomator/cryptofs/ArrayUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.cryptomator.cryptofs;

import java.util.Arrays;
import java.util.Objects;

/**
* Functions used from commons-lang
*/
final class ArrayUtils {

public static boolean contains(Object[] array, Object objectToFind) {
return Arrays.stream(Objects.requireNonNull(array)).anyMatch(Objects.requireNonNull(objectToFind)::equals);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;
import org.cryptomator.cryptolib.api.AuthenticationFailedException;
import org.cryptomator.cryptolib.api.Cryptor;
import org.slf4j.Logger;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/cryptomator/cryptofs/CopyOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import javax.inject.Inject;

import org.apache.commons.lang3.ArrayUtils;

@PerProvider
class CopyOperation {

Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/cryptomator/cryptofs/CryptoDirectoryStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CryptoDirectoryStream(Directory ciphertextDir, Path cleartextDir, FileNam
this.finallyUtil = finallyUtil;
this.directoryId = ciphertextDir.dirId;
this.ciphertextDirStream = Files.newDirectoryStream(ciphertextDir.path, p -> true);
LOG.trace("OPEN " + directoryId);
LOG.trace("OPEN {}", directoryId);
this.cleartextDir = cleartextDir;
this.filenameCryptor = filenameCryptor;
this.cryptoPathMapper = cryptoPathMapper;
Expand All @@ -63,9 +63,9 @@ public CryptoDirectoryStream(Directory ciphertextDir, Path cleartextDir, FileNam
public Iterator<Path> iterator() {
Stream<Path> pathIter = StreamSupport.stream(ciphertextDirStream.spliterator(), false);
Stream<Path> resolved = pathIter.map(this::resolveConflictingFileIfNeeded).filter(Objects::nonNull);
Stream<Path> inflated = resolved.map(this::inflateIfNeeded).filter(Objects::nonNull);
Stream<Path> sanitized = inflated.filter(this::passesPlausibilityChecks);
Stream<Path> decrypted = sanitized.map(this::decrypt).filter(Objects::nonNull);
Stream<Path> sanitized = resolved.filter(this::passesPlausibilityChecks);
Stream<Path> inflated = sanitized.map(this::inflateIfNeeded).filter(Objects::nonNull);
Stream<Path> decrypted = inflated.map(this::decrypt).filter(Objects::nonNull);
Stream<Path> filtered = decrypted.filter(this::isAcceptableByFilter);
return filtered.iterator();
}
Expand Down Expand Up @@ -94,6 +94,12 @@ private Path inflateIfNeeded(Path ciphertextPath) {
}
}

/**
* Checks if a given file belongs into this ciphertext dir.
*
* @param ciphertextPath The path to check.
* @return <code>true</code> if the file is an existing ciphertext or directory file.
*/
private boolean passesPlausibilityChecks(Path ciphertextPath) {
return !isBrokenDirectoryFile(ciphertextPath);
}
Expand Down Expand Up @@ -146,7 +152,7 @@ public void close() throws IOException {
finallyUtil.guaranteeInvocationOf( //
() -> ciphertextDirStream.close(), //
() -> onClose.accept(this), //
() -> LOG.trace("CLOSE " + directoryId));
() -> LOG.trace("CLOSE {}", directoryId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

import javax.inject.Inject;

import org.apache.commons.lang3.ArrayUtils;
import org.cryptomator.cryptofs.CryptoPathMapper.CiphertextFileType;
import org.cryptomator.cryptofs.CryptoPathMapper.Directory;
import org.cryptomator.cryptolib.api.Cryptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Set;
import java.util.function.Consumer;

import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Strings;

/**
* Properties to pass to
Expand Down Expand Up @@ -322,7 +322,7 @@ private void validate() {
if (passphrase == null) {
throw new IllegalStateException("passphrase is required");
}
if (StringUtils.isBlank(masterkeyFilename)) {
if (Strings.nullToEmpty(masterkeyFilename).trim().isEmpty()) {
throw new IllegalStateException("masterkeyFilename is required");
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/cryptomator/cryptofs/MoveOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import javax.inject.Inject;

import org.apache.commons.lang3.ArrayUtils;

@PerProvider
class MoveOperation {

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/cryptomator/cryptofs/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.cryptomator.cryptofs;

/**
* Functions used from commons-lang
*/
final class StringUtils {

public static String removeEnd(String str, String remove) {
if (str == null || remove == null) {
return str;
}
if (str.endsWith(remove)) {
return str.substring(0, str.length() - remove.length());
} else {
return str;
}
}

public static String removeStart(String str, String remove) {
if (str == null || remove == null) {
return str;
}
if (str.startsWith(remove)) {
return str.substring(remove.length());
} else {
return str;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Spliterators;
import java.util.function.Consumer;

import org.apache.commons.lang3.StringUtils;
import org.cryptomator.cryptofs.CryptoPathMapper.Directory;
import org.cryptomator.cryptolib.DaggerCryptoLibComponent;
import org.cryptomator.cryptolib.api.CryptorProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import static java.nio.file.Files.readAllBytes;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
import static org.cryptomator.cryptofs.CryptoFileSystemProperties.cryptoFileSystemProperties;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
Expand All @@ -27,6 +26,7 @@
import java.util.EnumSet;

import org.cryptomator.cryptolib.api.InvalidPassphraseException;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
Expand Down Expand Up @@ -127,6 +127,15 @@ public void testOpenAndCloseFileChannel() throws IOException {
}
}

@Test
public void testLongFileNames() throws IOException {
FileSystem fs = CryptoFileSystemProvider.newFileSystem(pathToVault, cryptoFileSystemProperties().withPassphrase("asd").build());
Path longNamePath = fs.getPath("/Internet Telefon Energie Wasser Webseitengeraffel Bus Bahn Mietwagen");
Files.createDirectory(longNamePath);
Assert.assertTrue(Files.isDirectory(longNamePath));
Assert.assertThat(MoreFiles.listFiles(fs.getPath("/")), Matchers.contains(longNamePath));
}

@Test
public void testCopyFileFromOneCryptoFileSystemToAnother() throws IOException {
byte[] data = new byte[] {1, 2, 3, 4, 5, 6, 7};
Expand Down Expand Up @@ -197,7 +206,7 @@ public void testMoveFileFromOneCryptoFileSystemToAnother() throws IOException {

@Test
public void testDosFileAttributes() throws IOException {
Assume.assumeTrue(IS_OS_WINDOWS);
Assume.assumeThat(System.getProperty("os.name"), Matchers.startsWith("Windows"));

Path tmpPath = Files.createTempDirectory("unit-tests");
FileSystem fs = CryptoFileSystemProvider.newFileSystem(tmpPath, cryptoFileSystemProperties().withPassphrase("asd").build());
Expand Down

0 comments on commit 39a7993

Please sign in to comment.