Skip to content

Commit e1e07f3

Browse files
committed
Merge branch 'release/2.5.2'
2 parents 2f42f3c + 010b052 commit e1e07f3

5 files changed

Lines changed: 7 additions & 37 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.cryptomator</groupId>
44
<artifactId>cryptofs</artifactId>
5-
<version>2.5.1</version>
5+
<version>2.5.2</version>
66
<name>Cryptomator Crypto Filesystem</name>
77
<description>This library provides the Java filesystem provider used by Cryptomator.</description>
88
<url>https://github.com/cryptomator/cryptofs</url>

src/main/java/org/cryptomator/cryptofs/health/dirid/MissingContentDir.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Map<String, String> details() {
4949
//visible for testing
5050
void fix(Path pathToVault, Cryptor cryptor) throws IOException {
5151
var dirIdHash = cryptor.fileNameCryptor().hashDirectoryId(dirId);
52-
Path dirPath = pathToVault.resolve(Constants.DATA_DIR_NAME).resolve(dirIdHash.substring(0, 2)).resolve(dirIdHash.substring(2, 30));
52+
Path dirPath = pathToVault.resolve(Constants.DATA_DIR_NAME).resolve(dirIdHash.substring(0, 2)).resolve(dirIdHash.substring(2, 32));
5353
Files.createDirectories(dirPath);
5454
DirectoryIdBackup.backupManually(cryptor, new CryptoPathMapper.CiphertextDirectory(dirId, dirPath));
5555
}

src/main/java/org/cryptomator/cryptofs/health/dirid/OrphanContentDir.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private void fix(Path pathToVault, VaultConfig config, Cryptor cryptor) throws I
9999
try {
100100
return decryptFileName(orphanedResource, isShortened, id, cryptor.fileNameCryptor());
101101
} catch (IOException | AuthenticationFailedException e) {
102-
LOG.warn("Unable to read and decrypt (long) file name of {}:", orphanedResource, e);
102+
LOG.warn("Unable to read and decrypt file name of {}:", orphanedResource, e);
103103
return null;
104104
}})
105105
.orElseGet(() ->
@@ -182,15 +182,7 @@ Optional<String> retrieveDirId(Path orphanedDir, Cryptor cryptor) {
182182
return Optional.empty();
183183
}
184184

185-
var allegedDirId = StandardCharsets.US_ASCII.decode(dirIdBuffer).toString();
186-
187-
var dirIdHash = orphanedDir.getParent().getFileName().toString() + orphanedDir.getFileName().toString();
188-
if (dirIdHash.equals(cryptor.fileNameCryptor().hashDirectoryId(allegedDirId))) {
189-
return Optional.of(allegedDirId);
190-
} else {
191-
LOG.info("Hash of read directory id {} does not match actual cipher dir hash {}.", allegedDirId, dirIdHash);
192-
return Optional.empty();
193-
}
185+
return Optional.of(StandardCharsets.US_ASCII.decode(dirIdBuffer).toString());
194186
}
195187

196188
//exists and visible for testability

src/test/java/org/cryptomator/cryptofs/health/dirid/MissingContentDirTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public void testGetFix() {
5252
@DisplayName("After fix the content dir including dirId file exists ")
5353
@Test
5454
public void testFix() throws IOException {
55-
var dirIdHash = "ridiculous-30-char-pseudo-hash";
55+
var dirIdHash = "ridiculous-32-char-pseudo-hashhh";
5656
Mockito.doReturn(dirIdHash).when(fileNameCryptor).hashDirectoryId(dirId);
5757
try (var dirIdBackupMock = Mockito.mockStatic(DirectoryIdBackup.class)) {
5858
dirIdBackupMock.when(() -> DirectoryIdBackup.backupManually(Mockito.any(), Mockito.any())).thenAnswer(Answers.RETURNS_SMART_NULLS);
5959

6060
result.fix(pathToVault, cryptor);
6161

62-
var expectedPath = pathToVault.resolve("d/ri/diculous-30-char-pseudo-hash");
62+
var expectedPath = pathToVault.resolve("d/ri/diculous-32-char-pseudo-hashhh");
6363
ArgumentMatcher<CryptoPathMapper.CiphertextDirectory> cipherDirMatcher = obj -> obj.dirId.equals(dirId) && obj.path.endsWith(expectedPath);
6464
dirIdBackupMock.verify(() -> DirectoryIdBackup.backupManually(Mockito.eq(cryptor), Mockito.argThat(cipherDirMatcher)), Mockito.times(1));
6565
var attr = Assertions.assertDoesNotThrow(() -> Files.readAttributes(expectedPath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS));
@@ -70,7 +70,7 @@ public void testFix() throws IOException {
7070
@DisplayName("If dirid.c9r creation fails, fix fails ")
7171
@Test
7272
public void testFixFailsOnFailingDirIdFile() throws IOException {
73-
var dirIdHash = "ridiculous-30-char-pseudo-hash";
73+
var dirIdHash = "ridiculous-32-char-pseudo-hashhh";
7474
try (var dirIdBackupMock = Mockito.mockStatic(DirectoryIdBackup.class)) {
7575
Mockito.doReturn(dirIdHash).when(fileNameCryptor).hashDirectoryId(dirId);
7676
dirIdBackupMock.when(() -> DirectoryIdBackup.backupManually(Mockito.any(), Mockito.any())).thenThrow(new IOException("Access denied"));

src/test/java/org/cryptomator/cryptofs/health/dirid/OrphanDirTest.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -270,28 +270,6 @@ public void testRetrieveDirIdIOExceptionReadingFile() throws IOException {
270270
Assertions.assertTrue(notExistingResult.isEmpty());
271271
}
272272

273-
274-
@Test
275-
@DisplayName("retrieveDirId returns empty optional if content of dirId.c9r does not match cipher dir hash")
276-
public void testRetrieveDirIdWrongContent() throws IOException {
277-
var dirIdFile = cipherOrphan.resolve(Constants.DIR_BACKUP_FILE_NAME);
278-
var dirId = "anOverlyComplexAndCompletelyRandomExampleOfHowAnDirectoryIdIsTooLong";
279-
Files.writeString(dirIdFile, dirId, StandardCharsets.US_ASCII, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
280-
DecryptingReadableByteChannel dirIdReadChannel = Mockito.mock(DecryptingReadableByteChannel.class);
281-
282-
Mockito.doReturn(dirIdReadChannel).when(resultSpy).createDecryptingReadableByteChannel(Mockito.any(), Mockito.eq(cryptor));
283-
Mockito.doAnswer(invocationOnMock -> {
284-
try (ReadableByteChannel channel = Files.newByteChannel(dirIdFile, StandardOpenOption.READ)) {
285-
return channel.read(invocationOnMock.getArgument(0));
286-
}
287-
}).when(dirIdReadChannel).read(Mockito.any());
288-
Mockito.when(fileNameCryptor.hashDirectoryId(dirId.substring(0, 36))).thenReturn("123456");
289-
290-
var maybeDirId = resultSpy.retrieveDirId(cipherOrphan, cryptor);
291-
292-
Assertions.assertTrue(maybeDirId.isEmpty());
293-
}
294-
295273
}
296274

297275

0 commit comments

Comments
 (0)