|  | 
| 16 | 16 | import org.junit.jupiter.api.Assertions; | 
| 17 | 17 | import org.junit.jupiter.api.BeforeAll; | 
| 18 | 18 | import org.junit.jupiter.api.Disabled; | 
|  | 19 | +import org.junit.jupiter.api.DisplayName; | 
| 19 | 20 | import org.junit.jupiter.api.Test; | 
| 20 | 21 | import org.junit.jupiter.api.io.TempDir; | 
| 21 | 22 | import org.mockito.Mockito; | 
|  | 
| 28 | 29 | import java.nio.file.FileSystem; | 
| 29 | 30 | import java.nio.file.Files; | 
| 30 | 31 | import java.nio.file.Path; | 
|  | 32 | +import java.util.function.Predicate; | 
| 31 | 33 | import java.util.stream.Stream; | 
| 32 | 34 | 
 | 
| 33 | 35 | import static java.nio.file.StandardOpenOption.CREATE_NEW; | 
| @@ -159,21 +161,35 @@ private Path firstEmptyCiphertextDirectory() throws IOException { | 
| 159 | 161 | 		try (Stream<Path> allFilesInVaultDir = Files.walk(pathToVault)) { | 
| 160 | 162 | 			return allFilesInVaultDir // | 
| 161 | 163 | 					.filter(Files::isDirectory) // | 
| 162 |  | -					.filter(this::isEmptyDirectory) // | 
|  | 164 | +					.filter(this::isEmptyCryptoFsDirectory) // | 
| 163 | 165 | 					.filter(this::isEncryptedDirectory) // | 
| 164 | 166 | 					.findFirst() // | 
| 165 | 167 | 					.get(); | 
| 166 | 168 | 		} | 
| 167 | 169 | 	} | 
| 168 | 170 | 
 | 
| 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()); | 
| 170 | 173 | 		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()); | 
| 172 | 175 | 		} catch (IOException e) { | 
| 173 | 176 | 			throw new UncheckedIOException(e); | 
| 174 | 177 | 		} | 
| 175 | 178 | 	} | 
| 176 | 179 | 
 | 
|  | 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 | + | 
| 177 | 193 | 	private boolean isEncryptedDirectory(Path pathInVault) { | 
| 178 | 194 | 		Path relativePath = pathToVault.relativize(pathInVault); | 
| 179 | 195 | 		String relativePathAsString = relativePath.toString().replace(File.separatorChar, '/'); | 
|  | 
0 commit comments