Align new FileSystemUtils NIO implementation with original behavior
Issue: SPR-15845 Issue: SPR-15846
This commit is contained in:
parent
08dfce2cb5
commit
fabc9c28d7
|
|
@ -22,6 +22,7 @@ import java.nio.file.FileVisitResult;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
|
@ -51,7 +52,10 @@ public abstract class FileSystemUtils {
|
|||
* otherwise {@code false}
|
||||
*/
|
||||
public static boolean deleteRecursively(@Nullable File root) {
|
||||
if (root != null) {
|
||||
if (root == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return deleteRecursively(root.toPath());
|
||||
}
|
||||
|
|
@ -59,8 +63,6 @@ public abstract class FileSystemUtils {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the supplied {@link File} - for directories,
|
||||
|
|
@ -72,7 +74,13 @@ public abstract class FileSystemUtils {
|
|||
* @since 5.0
|
||||
*/
|
||||
public static boolean deleteRecursively(@Nullable Path root) throws IOException {
|
||||
if (root != null) {
|
||||
if (root == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Files.exists(root)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
|
|
@ -85,9 +93,7 @@ public abstract class FileSystemUtils {
|
|||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
return Files.deleteIfExists(root);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -125,7 +131,7 @@ public abstract class FileSystemUtils {
|
|||
}
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Files.copy(file, dest.resolve(src.relativize(file)));
|
||||
Files.copy(file, dest.resolve(src.relativize(file)), StandardCopyOption.REPLACE_EXISTING);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue