aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
index 627e611..a7bca3f 100644
--- a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
+++ b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
@@ -71,9 +71,11 @@ public final class ConfigUtils {
*/
private static boolean deployFromZIP(String destination, boolean overwriteExisting) throws ConfigUtilsException {
try {
- File destinationFolder = new File(destination);
- if (destinationFolder.exists() && !overwriteExisting) {
- return false;
+ if (!overwriteExisting) {
+ if (configurationAlreadyExists(destination)) {
+ logger_.debug("There is at least one file or folder that would be overwritten at destination path \"" + destination + "\". Skipping extraction.");
+ return false;
+ }
}
InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream(Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE);
if (in == null) {
@@ -81,6 +83,7 @@ public final class ConfigUtils {
}
ZipInputStream zis = new ZipInputStream(in);
ZipEntry ze;
+ File destinationFolder = new File(destination);
destinationFolder.mkdirs();
logger_.debug("Extracting default configuration to folder \"" + destinationFolder.getCanonicalPath() + "\".");
while ((ze = zis.getNextEntry()) != null) {
@@ -102,6 +105,44 @@ public final class ConfigUtils {
}
}
+ private static boolean configurationAlreadyExists(String destination) throws ConfigUtilsException, IOException {
+ logger_.debug("Checking configuration \"" + destination + "\" already exists (resp. if there are any directories or files that would be overwritten).");
+ File destinationFolder = new File(destination);
+ if (destinationFolder == null || !destinationFolder.exists()) {
+ return false;
+ }
+ InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream(Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE);
+ if (in == null) {
+ throw new ConfigUtilsException("Unable to find default configuration resource \"" + Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE + "\".");
+ }
+ ZipInputStream zis = new ZipInputStream(in);
+ ZipEntry ze;
+ while ((ze = zis.getNextEntry()) != null) {
+ if (ze.isDirectory()) {
+ File newFolder = new File(destinationFolder, ze.getName());
+ logger_.debug("Checking if folder \"" + newFolder.getPath() + "\" already exists.");
+ if (newFolder.exists()) {
+ logger_.debug("YES !");
+ return true;
+ } else {
+ logger_.debug("no");
+ }
+ } else {
+ File destFile = new File(destinationFolder, ze.getName());
+ logger_.trace("Checking if file \"" + destFile.getName() + "\" already exists.");
+ if (destFile.exists()) {
+ logger_.trace("YES !");
+ return true;
+ } else {
+ logger_.trace("no");
+ }
+ }
+ zis.closeEntry();
+ }
+ zis.close();
+ return false;
+ }
+
/**
* Deploys the default configuration to the given destination folder.
*