Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2073] Fix DependenciesManager FileNotFoundException with some filen… #1041

Open
wants to merge 1 commit into
base: 1.4.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions framework/src/play/libs/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
import play.utils.OrderSafeProperties;

import java.io.*;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import java.util.Properties;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.apache.commons.io.IOUtils.closeQuietly;

/**
Expand Down Expand Up @@ -232,20 +238,31 @@ public static void write(InputStream is, File f) {

// If targetLocation does not exist, it will be created.
public static void copyDirectory(File source, File target) {
if (source.isDirectory()) {
if (!target.exists()) {
target.mkdir();
}
for (String child: source.list()) {
copyDirectory(new File(source, child), new File(target, child));
}
} else {
try {
write(new FileInputStream(source), new FileOutputStream(target));
} catch (IOException e) {
throw new UnexpectedException(e);
}
final Path src = source.toPath();
final Path dest = target.toPath();
try {
Files.walkFileTree(src,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
FileVisitResult preVisitDirectoryResult = super.preVisitDirectory(dir, attrs);
if (FileVisitResult.CONTINUE.equals(preVisitDirectoryResult)) {
Path targetPath = dest.resolve(src.relativize(dir));
if (!Files.exists(targetPath)) Files.createDirectory(targetPath);
}
return preVisitDirectoryResult;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
FileVisitResult visitFileResult = super.visitFile(file, attrs);
if (FileVisitResult.CONTINUE.equals(visitFileResult))
Files.copy(file, dest.resolve(src.relativize(file)), REPLACE_EXISTING);
return visitFileResult;
}
});
} catch (IOException e) {
throw new UnexpectedException(e);
}
}

}