Browse Source

Fixed edge case.

qdn
CalDescent 3 years ago
parent
commit
f095964f7b
  1. 3
      src/main/java/org/qortal/arbitrary/ArbitraryDataReader.java
  2. 11
      src/main/java/org/qortal/utils/FilesystemUtils.java

3
src/main/java/org/qortal/arbitrary/ArbitraryDataReader.java

@ -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 {

11
src/main/java/org/qortal/utils/FilesystemUtils.java

@ -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…
Cancel
Save