forked from Qortal/qortal
Fixed edge case.
This commit is contained in:
parent
cfba793fcf
commit
f095964f7b
@ -299,6 +299,9 @@ public class ArbitraryDataReader {
|
||||
if (dest == null || !dest.exists()) {
|
||||
throw new IllegalStateException("Destination directory doesn't exist");
|
||||
}
|
||||
// Ensure destination directory doesn't exist
|
||||
FileUtils.deleteDirectory(dest);
|
||||
// Move files to destination
|
||||
FilesystemUtils.copyAndReplaceDirectory(source.toString(), dest.toString());
|
||||
|
||||
try {
|
||||
|
@ -20,6 +20,15 @@ public class FilesystemUtils {
|
||||
}
|
||||
|
||||
public static void copyAndReplaceDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException {
|
||||
// Ensure parent folders exist in the destination
|
||||
File destFile = new File(destinationDirectoryLocation);
|
||||
if (destFile != null) {
|
||||
destFile.mkdirs();
|
||||
}
|
||||
if (destFile == null || !destFile.exists()) {
|
||||
throw new IOException("Destination directory doesn't exist");
|
||||
}
|
||||
|
||||
Files.walk(Paths.get(sourceDirectoryLocation))
|
||||
.forEach(source -> {
|
||||
Path destination = Paths.get(destinationDirectoryLocation, source.toString()
|
||||
@ -49,7 +58,6 @@ public class FilesystemUtils {
|
||||
}
|
||||
|
||||
File sourceFile = new File(source.toString());
|
||||
File destFile = new File(dest.toString());
|
||||
if (sourceFile == null || !sourceFile.exists()) {
|
||||
throw new IOException("Source file doesn't exist");
|
||||
}
|
||||
@ -58,6 +66,7 @@ public class FilesystemUtils {
|
||||
}
|
||||
|
||||
// Ensure parent folders exist in the destination
|
||||
File destFile = new File(dest.toString());
|
||||
File destParentFile = destFile.getParentFile();
|
||||
if (destParentFile != null) {
|
||||
destParentFile.mkdirs();
|
||||
|
Loading…
x
Reference in New Issue
Block a user