Skip to content

Commit 0bdad47

Browse files
committed
Throw custom filesystem exception if an encrypted directory does not contain id files
1 parent 7f800a9 commit 0bdad47

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/main/java/org/cryptomator/cryptofs/CryptoPathMapper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public CiphertextFileType getCiphertextFileType(CryptoPath cleartextPath) throws
105105
} else {
106106
eventConsumer.accept(new BrokenFileNodeEvent(cleartextPath, ciphertextPath.getRawPath()));
107107
LOG.warn("Did not find valid content inside of {}", ciphertextPath.getRawPath());
108-
throw new NoSuchFileException(cleartextPath.toString(), null, "Could not determine type of file " + ciphertextPath.getRawPath());
108+
throw new InvalidFileNodeException(cleartextPath.toString(), ciphertextPath.getRawPath().toString());
109109
}
110110
} else {
111111
// assume "file" if not a directory (even if it isn't a "regular" file, see issue #81):
@@ -117,7 +117,7 @@ public CiphertextFileType getCiphertextFileType(CryptoPath cleartextPath) throws
117117
public CiphertextFilePath getCiphertextFilePath(CryptoPath cleartextPath) throws IOException {
118118
CryptoPath parentPath = cleartextPath.getParent();
119119
if (parentPath == null) {
120-
throw new IllegalArgumentException("Invalid file path (must have a parent): " + cleartextPath); //TODO: cleartext path in Logs!
120+
throw new IllegalArgumentException("Invalid file path (must have a parent): " + cleartextPath);
121121
}
122122
CiphertextDirectory parent = getCiphertextDir(parentPath);
123123
String cleartextName = cleartextPath.getFileName().toString();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.cryptomator.cryptofs;
2+
3+
import java.nio.file.FileSystemException;
4+
5+
/**
6+
* Exception thrown if a c9s or c9r directory does not contain any identification files
7+
*/
8+
public class InvalidFileNodeException extends FileSystemException {
9+
10+
public InvalidFileNodeException(String cleartext, String ciphertext) {
11+
super(cleartext, null, "Unknown type of node %s: Missing identification file".formatted(ciphertext));
12+
}
13+
}

src/test/java/org/cryptomator/cryptofs/CryptoPathMapperTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public void testDetectionPriority(boolean dirFileExists, boolean symlinkFileExis
390390
}
391391

392392
@Test
393-
@DisplayName("Throw NoSuchFileException if no known file exists")
393+
@DisplayName("Throw a FileSystemException if no id file exists")
394394
public void testNoKnownFileExists() throws IOException {
395395
Mockito.when(underlyingFileSystemProvider.readAttributes(c9rPath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenReturn(c9rAttrs);
396396
Mockito.when(c9rAttrs.isDirectory()).thenReturn(true);
@@ -404,7 +404,7 @@ public void testNoKnownFileExists() throws IOException {
404404
CryptoPathMapper mapper = new CryptoPathMapper(pathToVault, cryptor, dirIdProvider, longFileNameProvider, vaultConfig, eventConsumer);
405405

406406
CryptoPath path = fileSystem.getPath("/CLEAR");
407-
Assertions.assertThrows(NoSuchFileException.class, () -> mapper.getCiphertextFileType(path));
407+
Assertions.assertThrows(InvalidFileNodeException.class, () -> mapper.getCiphertextFileType(path));
408408
var isBrokenFileNodeEvent = (ArgumentMatcher<FilesystemEvent>) ev -> ev instanceof BrokenFileNodeEvent;
409409
verify(eventConsumer).accept(ArgumentMatchers.argThat(isBrokenFileNodeEvent));
410410
}

0 commit comments

Comments
 (0)