Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/org/cryptomator/cryptofs/CryptoPathMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public void assertNonExisting(CryptoPath cleartextPath) throws FileAlreadyExists
/**
* @param cleartextPath A path
* @return The file type for the given path (if it exists)
* @throws NoSuchFileException If no node exists at the given path for any known type
* @throws NoSuchFileException If the ciphertext path does not exist
* @throws InvalidFileNodeException If the node points to a ciphertext directory, which does not contain an identification file
* @throws IOException
*/
public CiphertextFileType getCiphertextFileType(CryptoPath cleartextPath) throws NoSuchFileException, IOException {
Expand All @@ -105,7 +106,7 @@ public CiphertextFileType getCiphertextFileType(CryptoPath cleartextPath) throws
} else {
eventConsumer.accept(new BrokenFileNodeEvent(cleartextPath, ciphertextPath.getRawPath()));
LOG.warn("Did not find valid content inside of {}", ciphertextPath.getRawPath());
throw new NoSuchFileException(cleartextPath.toString(), null, "Could not determine type of file " + ciphertextPath.getRawPath());
throw new InvalidFileNodeException(cleartextPath.toString(), ciphertextPath.getRawPath().toString());
}
} else {
// assume "file" if not a directory (even if it isn't a "regular" file, see issue #81):
Expand All @@ -117,7 +118,7 @@ public CiphertextFileType getCiphertextFileType(CryptoPath cleartextPath) throws
public CiphertextFilePath getCiphertextFilePath(CryptoPath cleartextPath) throws IOException {
CryptoPath parentPath = cleartextPath.getParent();
if (parentPath == null) {
throw new IllegalArgumentException("Invalid file path (must have a parent): " + cleartextPath); //TODO: cleartext path in Logs!
throw new IllegalArgumentException("Invalid file path (must have a parent): " + cleartextPath);
}
CiphertextDirectory parent = getCiphertextDir(parentPath);
String cleartextName = cleartextPath.getFileName().toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.cryptomator.cryptofs;

import java.nio.file.FileSystemException;

/**
* Exception thrown if a c9s or c9r directory does not contain any identification files
*/
public class InvalidFileNodeException extends FileSystemException {

public InvalidFileNodeException(String cleartext, String ciphertext) {
super(cleartext, null, "Unknown type of node %s: Missing identification file".formatted(ciphertext));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public void testDetectionPriority(boolean dirFileExists, boolean symlinkFileExis
}

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

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