|
102 | 102 | import java.io.IOException; |
103 | 103 | import java.io.UncheckedIOException; |
104 | 104 | import java.nio.file.DirectoryStream; |
| 105 | +import java.nio.file.FileVisitResult; |
105 | 106 | import java.nio.file.Files; |
| 107 | +import java.nio.file.NoSuchFileException; |
106 | 108 | import java.nio.file.Path; |
| 109 | +import java.nio.file.SimpleFileVisitor; |
| 110 | +import java.nio.file.attribute.BasicFileAttributes; |
107 | 111 | import java.util.ArrayList; |
108 | 112 | import java.util.Arrays; |
109 | 113 | import java.util.Collection; |
@@ -334,18 +338,36 @@ public void testIndexCanChangeCustomDataPath() throws Exception { |
334 | 338 |
|
335 | 339 | logger.info("--> copying data on disk from [{}] to [{}]", indexDataPath, newIndexDataPath); |
336 | 340 | assert Files.exists(newIndexDataPath) == false : "new index data path directory should not exist!"; |
337 | | - try (Stream<Path> stream = Files.walk(indexDataPath)) { |
338 | | - stream.forEach(path -> { |
339 | | - try { |
340 | | - if (path.endsWith(".lock") == false) { |
341 | | - Files.copy(path, newIndexDataPath.resolve(indexDataPath.relativize(path))); |
| 341 | + Files.walkFileTree(indexDataPath, new SimpleFileVisitor<Path>() { |
| 342 | + @Override |
| 343 | + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { |
| 344 | + Path targetDir = newIndexDataPath.resolve(indexDataPath.relativize(dir)); |
| 345 | + Files.createDirectories(targetDir); |
| 346 | + return FileVisitResult.CONTINUE; |
| 347 | + } |
| 348 | + |
| 349 | + @Override |
| 350 | + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { |
| 351 | + if (file.getFileName().toString().endsWith(".lock") == false) { |
| 352 | + Path target = newIndexDataPath.resolve(indexDataPath.relativize(file)); |
| 353 | + try { |
| 354 | + Files.copy(file, target); |
| 355 | + } catch (NoSuchFileException e) { |
| 356 | + logger.error("Failed to copy data path directory", e); |
| 357 | + fail(); |
342 | 358 | } |
343 | | - } catch (final Exception e) { |
344 | | - logger.error("Failed to copy data path directory", e); |
345 | | - fail(); |
346 | 359 | } |
347 | | - }); |
348 | | - } |
| 360 | + return FileVisitResult.CONTINUE; |
| 361 | + } |
| 362 | + |
| 363 | + @Override |
| 364 | + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { |
| 365 | + if (exc instanceof NoSuchFileException) { |
| 366 | + return FileVisitResult.CONTINUE; |
| 367 | + } |
| 368 | + return FileVisitResult.TERMINATE; |
| 369 | + } |
| 370 | + }); |
349 | 371 |
|
350 | 372 | logger.info("--> updating data_path to [{}] for index [{}]", newIndexDataPath, index); |
351 | 373 | // update data path and re-enable refresh |
|
0 commit comments