Skip to content

Commit 316f30d

Browse files
Don't run conflict resolver for files starting with .
fixes #73
1 parent 138583a commit 316f30d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/main/java/org/cryptomator/cryptofs/dir/C9rConflictResolver.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ public C9rConflictResolver(Cryptor cryptor, @Named("dirId") String dirId) {
4646
public Stream<Node> process(Node node) {
4747
Preconditions.checkArgument(node.extractedCiphertext != null, "Can only resolve conflicts if extractedCiphertext is set");
4848
Preconditions.checkArgument(node.cleartextName != null, "Can only resolve conflicts if cleartextName is set");
49-
49+
5050
String canonicalCiphertextFileName = node.extractedCiphertext + Constants.CRYPTOMATOR_FILE_SUFFIX;
5151
if (node.fullCiphertextFileName.equals(canonicalCiphertextFileName)) {
52+
// not a conflict:
5253
return Stream.of(node);
54+
} else if (node.fullCiphertextFileName.startsWith(".")) {
55+
// ignore hidden files:
56+
LOG.debug("Ignoring hidden file {}", node.ciphertextPath);
57+
return Stream.empty();
5358
} else {
59+
// conflicting file:
5460
try {
5561
Path canonicalPath = node.ciphertextPath.resolveSibling(canonicalCiphertextFileName);
5662
return resolveConflict(node, canonicalPath);

src/test/java/org/cryptomator/cryptofs/dir/C9rConflictResolverTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.junit.jupiter.api.BeforeEach;
77
import org.junit.jupiter.api.Test;
88
import org.junit.jupiter.api.io.TempDir;
9+
import org.junit.jupiter.params.ParameterizedTest;
10+
import org.junit.jupiter.params.provider.ValueSource;
911
import org.mockito.Mockito;
1012

1113
import java.io.IOException;
@@ -33,13 +35,24 @@ public void testResolveNonConflictingNode() {
3335
Node unresolved = new Node(Paths.get("foo.c9r"));
3436
unresolved.cleartextName = "bar";
3537
unresolved.extractedCiphertext = "foo";
36-
38+
3739
Stream<Node> result = conflictResolver.process(unresolved);
3840
Node resolved = result.findAny().get();
3941

4042
Assertions.assertSame(unresolved, resolved);
4143
}
4244

45+
@ParameterizedTest
46+
@ValueSource(strings = {"._foo.c9r", ".foo.c9r"})
47+
public void testResolveHiddenNode(String filename) {
48+
Node unresolved = new Node(Paths.get(filename));
49+
unresolved.cleartextName = "bar";
50+
unresolved.extractedCiphertext = "foo";
51+
52+
Stream<Node> result = conflictResolver.process(unresolved);
53+
Assertions.assertFalse(result.findAny().isPresent());
54+
}
55+
4356
@Test
4457
public void testResolveConflictingFileByChoosingNewName(@TempDir Path dir) throws IOException {
4558
Files.createFile(dir.resolve("foo (1).c9r"));

0 commit comments

Comments
 (0)