|
36 | 36 | import java.nio.file.NoSuchFileException;
|
37 | 37 | import java.nio.file.Path;
|
38 | 38 | import java.nio.file.SimpleFileVisitor;
|
| 39 | +import java.nio.file.StandardCopyOption; |
39 | 40 | import java.nio.file.attribute.BasicFileAttributes;
|
40 | 41 | import java.time.Instant;
|
41 | 42 | import java.util.ArrayList;
|
|
48 | 49 | import java.util.concurrent.atomic.AtomicBoolean;
|
49 | 50 | import java.util.concurrent.atomic.AtomicReference;
|
50 | 51 | import java.util.stream.Collectors;
|
| 52 | +import java.util.stream.Stream; |
| 53 | + |
51 | 54 | import jdk.test.lib.Platform;
|
52 | 55 |
|
53 | 56 | import com.sun.management.UnixOperatingSystemMXBean;
|
@@ -364,6 +367,30 @@ public static void listFileDescriptors(PrintStream ps) {
|
364 | 367 | });
|
365 | 368 | }
|
366 | 369 |
|
| 370 | + /** |
| 371 | + * Copies a directory and all entries in the directory to a destination path. |
| 372 | + * Makes the access permission of the destination entries writable. |
| 373 | + * |
| 374 | + * @param src the path of the source directory |
| 375 | + * @param dst the path of the destination directory |
| 376 | + * @throws IOException if an I/O error occurs while walking the file tree |
| 377 | + * @throws RuntimeException if an I/O error occurs during the copy operation |
| 378 | + * or if the source or destination paths are invalid |
| 379 | + */ |
| 380 | + public static void copyDirectory(Path src, Path dst) throws IOException { |
| 381 | + try (Stream<Path> stream = Files.walk(src)) { |
| 382 | + stream.forEach(sourcePath -> { |
| 383 | + try { |
| 384 | + Path destPath = dst.resolve(src.relativize(sourcePath)); |
| 385 | + Files.copy(sourcePath, destPath, StandardCopyOption.REPLACE_EXISTING); |
| 386 | + destPath.toFile().setWritable(true); |
| 387 | + } catch (IOException e) { |
| 388 | + throw new RuntimeException(e); |
| 389 | + } |
| 390 | + }); |
| 391 | + } |
| 392 | + } |
| 393 | + |
367 | 394 | // Return the current process handle count
|
368 | 395 | @SuppressWarnings("restricted")
|
369 | 396 | public static long getProcessHandleCount() {
|
|
0 commit comments