Skip to content

Commit

Permalink
Fixed problem with sync conflict resolver. Issue #311
Browse files Browse the repository at this point in the history
  • Loading branch information
markuskreusch committed Aug 11, 2016
1 parent 008e3e3 commit 034a667
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Expand Up @@ -27,7 +27,7 @@ class FilenameCryptorImpl implements FilenameCryptor {


private static final BaseNCodec BASE32 = new Base32(); private static final BaseNCodec BASE32 = new Base32();
// https://tools.ietf.org/html/rfc4648#section-6 // https://tools.ietf.org/html/rfc4648#section-6
private static final Pattern BASE32_PATTERN = Pattern.compile("([A-Z2-7]{8})*[A-Z2-7=]{8}"); private static final Pattern BASE32_PATTERN = Pattern.compile("^([A-Z2-7]{8})*[A-Z2-7=]{8}");
private static final ThreadLocal<MessageDigest> SHA1 = new ThreadLocalSha1(); private static final ThreadLocal<MessageDigest> SHA1 = new ThreadLocalSha1();
private static final ThreadLocal<SivMode> AES_SIV = new ThreadLocal<SivMode>() { private static final ThreadLocal<SivMode> AES_SIV = new ThreadLocal<SivMode>() {
@Override @Override
Expand Down
Expand Up @@ -10,6 +10,7 @@


import static java.lang.String.format; import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.lang3.StringUtils.removeStart;
import static org.cryptomator.filesystem.crypto.Constants.DIR_PREFIX; import static org.cryptomator.filesystem.crypto.Constants.DIR_PREFIX;


import java.io.FileNotFoundException; import java.io.FileNotFoundException;
Expand Down Expand Up @@ -91,15 +92,15 @@ public Stream<? extends Node> children() {
private Stream<File> nonConflictingFiles() { private Stream<File> nonConflictingFiles() {
if (exists()) { if (exists()) {
final Stream<? extends File> files = physicalFolder().filter(Folder::exists).map(Folder::files).orElse(Stream.empty()); final Stream<? extends File> files = physicalFolder().filter(Folder::exists).map(Folder::files).orElse(Stream.empty());
return files.filter(containsEncryptedName()).map(conflictResolver::resolveIfNecessary).distinct(); return files.filter(startsWithEncryptedName()).map(conflictResolver::resolveIfNecessary).distinct();
} else { } else {
throw new UncheckedIOException(new FileNotFoundException(format("Folder %s does not exist", this))); throw new UncheckedIOException(new FileNotFoundException(format("Folder %s does not exist", this)));
} }
} }


private Predicate<File> containsEncryptedName() { private Predicate<File> startsWithEncryptedName() {
final Pattern encryptedNamePattern = cryptor.getFilenameCryptor().encryptedNamePattern(); final Pattern encryptedNamePattern = cryptor.getFilenameCryptor().encryptedNamePattern();
return (File file) -> encryptedNamePattern.matcher(file.name()).find(); return (File file) -> encryptedNamePattern.matcher(removeStart(file.name(),DIR_PREFIX)).find();
} }


Optional<String> decryptChildName(String ciphertextFileName) { Optional<String> decryptChildName(String ciphertextFileName) {
Expand Down
Expand Up @@ -14,7 +14,7 @@ final class ConflictResolver {


private static final Logger LOG = LoggerFactory.getLogger(ConflictResolver.class); private static final Logger LOG = LoggerFactory.getLogger(ConflictResolver.class);
private static final String LONG_NAME_FILE_EXT = ".lng"; private static final String LONG_NAME_FILE_EXT = ".lng";
private static final Pattern BASE32_PATTERN = Pattern.compile("([A-Z0-9]{8})*[A-Z0-9=]{8}"); private static final Pattern BASE32_PATTERN = Pattern.compile("^0?([A-Z2-7]{8})*[A-Z2-7=]{8}");
private static final int UUID_FIRST_GROUP_STRLEN = 8; private static final int UUID_FIRST_GROUP_STRLEN = 8;


private ConflictResolver() { private ConflictResolver() {
Expand Down

0 comments on commit 034a667

Please sign in to comment.