Skip to content

Commit d9eacaa

Browse files
committed
Recursively copy directory with symbolic link
Closes gh-24823
1 parent a33b7bb commit d9eacaa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

spring-core/src/main/java/org/springframework/util/FileSystemUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,9 +24,12 @@
2424
import java.nio.file.SimpleFileVisitor;
2525
import java.nio.file.StandardCopyOption;
2626
import java.nio.file.attribute.BasicFileAttributes;
27+
import java.util.EnumSet;
2728

2829
import org.springframework.lang.Nullable;
2930

31+
import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
32+
3033
/**
3134
* Utility methods for working with the file system.
3235
*
@@ -65,11 +68,11 @@ public static boolean deleteRecursively(@Nullable File root) {
6568
}
6669

6770
/**
68-
* Delete the supplied {@link File} - for directories,
71+
* Delete the supplied {@link File} — for directories,
6972
* recursively delete any nested directories or files as well.
7073
* @param root the root {@code File} to delete
7174
* @return {@code true} if the {@code File} existed and was deleted,
72-
* or {@code false} it it did not exist
75+
* or {@code false} if it did not exist
7376
* @throws IOException in the case of I/O errors
7477
* @since 5.0
7578
*/
@@ -123,7 +126,7 @@ public static void copyRecursively(Path src, Path dest) throws IOException {
123126
BasicFileAttributes srcAttr = Files.readAttributes(src, BasicFileAttributes.class);
124127

125128
if (srcAttr.isDirectory()) {
126-
Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
129+
Files.walkFileTree(src, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
127130
@Override
128131
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
129132
Files.createDirectories(dest.resolve(src.relativize(dir)));

0 commit comments

Comments
 (0)