More control over copying files

This commit is contained in:
Grahame Grieve 2022-10-23 23:13:45 +11:00
parent 1c3a6ee439
commit 628ace4716
2 changed files with 39 additions and 1 deletions

View File

@ -33,6 +33,17 @@ package org.hl7.fhir.utilities;
public interface FileNotifier {
public interface FileNotifier2 {
/// if return false, not copy
public boolean copyFile(String src, String dst);
/// if return false, not copy
public boolean copyFolder(String src, String dst);
}
public void copyFile(String src, String dst);
}

View File

@ -63,6 +63,7 @@ import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.FileNotifier.FileNotifier2;
public class Utilities {
@ -306,8 +307,9 @@ public class Utilities {
String[] files = src.list();
for (String f : files) {
if (new CSFile(sourceFolder + File.separator + f).isDirectory()) {
if (!f.startsWith(".")) // ignore .git files...
if (!f.startsWith(".")) { // ignore .git files...
copyDirectory(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier);
}
} else {
if (notifier != null)
notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f);
@ -316,6 +318,31 @@ public class Utilities {
}
}
public static void copyDirectory2(String sourceFolder, String destFolder, FileNotifier2 notifier) throws IOException, FHIRException {
CSFile src = new CSFile(sourceFolder);
if (!src.exists())
throw new FHIRException("Folder " + sourceFolder + " not found");
createDirectory(destFolder);
String[] files = src.list();
for (String f : files) {
if (new CSFile(sourceFolder + File.separator + f).isDirectory()) {
if (!f.startsWith(".")) { // ignore .git files...
boolean doCopy = notifier != null ? notifier.copyFolder(sourceFolder + File.separator + f, destFolder + File.separator + f) : true;
if (doCopy) {
copyDirectory2(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier);
}
}
} else {
boolean doCopy = notifier != null ? notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f) : true;
if (doCopy) {
copyFile(new CSFile(sourceFolder + File.separator + f), new CSFile(destFolder + File.separator + f));
}
}
}
}
public static void copyFile(String source, String dest) throws IOException {
copyFile(new File(source), new File(dest));
}