Skip to content

Commit

Permalink
Recursively copy directory with symbolic link
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Apr 3, 2020
1 parent a33b7bb commit d9eacaa
Showing 1 changed file with 7 additions and 4 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,9 +24,12 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.EnumSet;

import org.springframework.lang.Nullable;

import static java.nio.file.FileVisitOption.FOLLOW_LINKS;

/**
* Utility methods for working with the file system.
*
Expand Down Expand Up @@ -65,11 +68,11 @@ public static boolean deleteRecursively(@Nullable File root) {
}

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

if (srcAttr.isDirectory()) {
Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
Files.walkFileTree(src, EnumSet.of(FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Files.createDirectories(dest.resolve(src.relativize(dir)));
Expand Down

0 comments on commit d9eacaa

Please sign in to comment.