Skip to content

Commit 1f72a65

Browse files
infeooverheadhunter
andcommitted
Apply suggestions from code review
Co-authored-by: Sebastian Stenzel <overheadhunter@users.noreply.github.com>
1 parent 65f0625 commit 1f72a65

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.nio.channels.Channels;
99
import java.nio.channels.FileChannel;
1010
import java.nio.charset.StandardCharsets;
11-
import java.nio.file.Files;
1211
import java.nio.file.NoSuchFileException;
1312
import java.nio.file.Path;
1413
import java.nio.file.StandardOpenOption;
@@ -25,7 +24,6 @@ public DirectoryIdLoader() {
2524

2625
@Override
2726
public String load(Path dirFilePath) throws IOException {
28-
//TODO: replace by Files.readString(StandardCharsets.UTF_8)
2927
try (FileChannel ch = FileChannel.open(dirFilePath, StandardOpenOption.READ);
3028
InputStream in = Channels.newInputStream(ch)) {
3129
long size = ch.size();

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.junit.jupiter.api.Assertions;
1717
import org.junit.jupiter.api.BeforeAll;
1818
import org.junit.jupiter.api.Disabled;
19+
import org.junit.jupiter.api.DisplayName;
1920
import org.junit.jupiter.api.Test;
2021
import org.junit.jupiter.api.io.TempDir;
2122
import org.mockito.Mockito;
@@ -28,6 +29,7 @@
2829
import java.nio.file.FileSystem;
2930
import java.nio.file.Files;
3031
import java.nio.file.Path;
32+
import java.util.function.Predicate;
3133
import java.util.stream.Stream;
3234

3335
import static java.nio.file.StandardOpenOption.CREATE_NEW;
@@ -159,21 +161,35 @@ private Path firstEmptyCiphertextDirectory() throws IOException {
159161
try (Stream<Path> allFilesInVaultDir = Files.walk(pathToVault)) {
160162
return allFilesInVaultDir //
161163
.filter(Files::isDirectory) //
162-
.filter(this::isEmptyDirectory) //
164+
.filter(this::isEmptyCryptoFsDirectory) //
163165
.filter(this::isEncryptedDirectory) //
164166
.findFirst() //
165167
.get();
166168
}
167169
}
168170

169-
private boolean isEmptyDirectory(Path path) {
171+
private boolean isEmptyCryptoFsDirectory(Path path) {
172+
Predicate<Path> isIgnoredFile = p -> Constants.DIR_ID_FILE.equals(p.getFileName().toString());
170173
try (Stream<Path> files = Files.list(path)) {
171-
return files.filter(p -> p.getFileName().toString().equals(Constants.DIR_ID_FILE)).count() == 0;
174+
return files.noneMatch(isIgnoredFile.negate());
172175
} catch (IOException e) {
173176
throw new UncheckedIOException(e);
174177
}
175178
}
176179

180+
@Test
181+
@DisplayName("Tests internal cryptofs directory emptiness definition")
182+
public void testCryptoFsDirEmptiness() throws IOException {
183+
var emptiness = pathToVault.getParent().resolve("emptiness");
184+
var ignoredFile = emptiness.resolve(Constants.DIR_ID_FILE);
185+
Files.createDirectory(emptiness);
186+
Files.createFile(ignoredFile);
187+
188+
boolean result = isEmptyCryptoFsDirectory(emptiness);
189+
190+
Assertions.assertTrue(result, "Directory containing only dir id file is not considered empty");
191+
}
192+
177193
private boolean isEncryptedDirectory(Path pathInVault) {
178194
Path relativePath = pathToVault.relativize(pathInVault);
179195
String relativePathAsString = relativePath.toString().replace(File.separatorChar, '/');

0 commit comments

Comments
 (0)