Changed from deleting existing physical files to recreating the table structure when data was too old

Former-commit-id: 5ef2a1a496c75accfdc185910d1a49677fe82e42
This commit is contained in:
Jeremy Long
2014-01-03 08:58:39 -05:00
parent bc66d4b0e7
commit 93f94b65f1

View File

@@ -18,16 +18,13 @@
*/ */
package org.owasp.dependencycheck.data.update; package org.owasp.dependencycheck.data.update;
import java.io.File;
import java.io.IOException;
import org.owasp.dependencycheck.data.CachedWebDataSource; import org.owasp.dependencycheck.data.CachedWebDataSource;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.owasp.dependencycheck.data.UpdateException; import org.owasp.dependencycheck.data.UpdateException;
import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
import org.owasp.dependencycheck.utils.DownloadFailedException; import org.owasp.dependencycheck.utils.DownloadFailedException;
import org.owasp.dependencycheck.utils.FileUtils;
import org.owasp.dependencycheck.utils.Settings;
/** /**
* Class responsible for updating the CPE and NVDCVE data stores. * Class responsible for updating the CPE and NVDCVE data stores.
@@ -50,9 +47,10 @@ public class DatabaseUpdater implements CachedWebDataSource {
if (task.isUpdateNeeded()) { if (task.isUpdateNeeded()) {
if (task.shouldDeleteAndRecreate()) { if (task.shouldDeleteAndRecreate()) {
try { try {
deleteExistingData(); task.recreateTables();
} catch (IOException ex) { } catch (DatabaseException ex) {
Logger.getLogger(DatabaseUpdater.class.getName()).log(Level.WARNING, "Unable to delete the existing data directory"); final String msg = "Unable to update the database schema";
Logger.getLogger(DatabaseUpdater.class.getName()).log(Level.SEVERE, msg);
Logger.getLogger(DatabaseUpdater.class.getName()).log(Level.FINE, null, ex); Logger.getLogger(DatabaseUpdater.class.getName()).log(Level.FINE, null, ex);
} }
} }
@@ -68,20 +66,16 @@ public class DatabaseUpdater implements CachedWebDataSource {
Logger.getLogger(DatabaseUpdater.class.getName()).log(Level.FINE, null, ex); Logger.getLogger(DatabaseUpdater.class.getName()).log(Level.FINE, null, ex);
} }
} }
//
/** // /**
* Deletes the existing data directories. // * Deletes the existing data directories.
* // *
* @throws IOException thrown if the directory cannot be deleted // * @throws IOException thrown if the directory cannot be deleted
*/ // */
protected void deleteExistingData() throws IOException { // protected void deleteExistingData() throws IOException {
File data = Settings.getDataFile(Settings.KEYS.CVE_DATA_DIRECTORY); // File data = Settings.getDataFile(Settings.KEYS.CVE_DATA_DIRECTORY);
if (data.exists()) { // if (data.exists()) {
FileUtils.delete(data); // FileUtils.delete(data);
} // }
data = DataStoreMetaInfo.getPropertiesFile(); // }
if (data.exists()) {
FileUtils.delete(data);
}
}
} }