implementing the purge feature as requested in issue #328

This commit is contained in:
Jeremy Long
2015-08-30 07:02:26 -04:00
parent 29626666a7
commit e630c484ff
8 changed files with 191 additions and 11 deletions

View File

@@ -37,6 +37,7 @@ import org.owasp.dependencycheck.utils.Settings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.core.FileAppender;
import java.util.logging.Level;
import org.slf4j.impl.StaticLoggerBinder;
/**
@@ -90,7 +91,28 @@ public class App {
prepareLogger(cli.getVerboseLog());
}
if (cli.isGetVersion()) {
if (cli.isPurge()) {
if (cli.getConnectionString() != null) {
LOGGER.error("Unable to purge the database when using a non-default connection string");
} else {
populateSettings(cli);
File db;
try {
db = new File(Settings.getDataDirectory(), "dc.h2.db");
if (db.exists()) {
if (db.delete()) {
LOGGER.info("Database file purged; local copy of the NVD has been removed");
} else {
LOGGER.error("Unable to delete '{}'; please delete the file manually", db.getAbsolutePath());
}
} else {
LOGGER.error("Unable to purge database; the database file does not exists: {}", db.getAbsolutePath());
}
} catch (IOException ex) {
LOGGER.error("Unable to delete the database");
}
}
} else if (cli.isGetVersion()) {
cli.printVersionInfo();
} else if (cli.isUpdateOnly()) {
populateSettings(cli);

View File

@@ -987,7 +987,7 @@ public final class CliParser {
/**
* The long CLI argument name specifying that only the update phase should be executed; no scan should be run.
*/
public static final String PURGE_NVD = "purgelocalnvd";
public static final String PURGE_NVD = "purge";
/**
* The long CLI argument name specifying the directory to write the reports to.
*/