From b5aefab37c25d5da114bb78768defc79fc709e29 Mon Sep 17 00:00:00 2001 From: tknall Date: Thu, 12 Jun 2008 08:19:49 +0000 Subject: A new check for the existence of a configuration has been implemented. The extraction is skipped if any files or folders would be overwritten. Files like log- or temp-files may exist and do not prevent the deployment of the default configuration. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@283 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/gv/egiz/pdfas/utils/ConfigUtils.java | 47 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java') 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. * -- cgit v1.2.3