From 3555733bbf228451c95f7e6b025b27852a5761a9 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 12 Dec 2017 07:09:16 -0500 Subject: [PATCH] updated console output per issue #1000 --- .../owasp/dependencycheck/utils/H2DBLock.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/H2DBLock.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/H2DBLock.java index bd065bd58..608b00914 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/H2DBLock.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/H2DBLock.java @@ -68,7 +68,7 @@ public class H2DBLock { * A random string used to validate the lock. */ private final String magic; - + private H2DBCleanupHook hook = null; /** @@ -102,16 +102,7 @@ public class H2DBLock { try { final File dir = settings.getDataDirectory(); lockFile = new File(dir, "dc.update.lock"); - if (!lockFile.getParentFile().isDirectory() && !lockFile.mkdir()) { - throw new H2DBLockException("Unable to create path to data directory."); - } - if (lockFile.isFile() && getFileAge(lockFile) > 30) { - LOGGER.debug("An old db update lock file was found: {}", lockFile.getAbsolutePath()); - if (!lockFile.delete()) { - LOGGER.warn("An old db update lock file was found but the system was unable to delete " - + "the file. Consider manually deleting {}", lockFile.getAbsolutePath()); - } - } + checkState(); int ctr = 0; do { try { @@ -165,6 +156,24 @@ public class H2DBLock { } } + private void checkState() throws H2DBLockException { + if (!lockFile.getParentFile().isDirectory() && !lockFile.mkdir()) { + throw new H2DBLockException("Unable to create path to data directory."); + } + if (lockFile.isFile()) { + if (getFileAge(lockFile) > 30) { + LOGGER.debug("An old db update lock file was found: {}", lockFile.getAbsolutePath()); + if (!lockFile.delete()) { + LOGGER.warn("An old db update lock file was found but the system was unable to delete " + + "the file. Consider manually deleting {}", lockFile.getAbsolutePath()); + } + } else { + LOGGER.info("Lock file found `{}`", lockFile); + LOGGER.info("Existing update in progress; waiting for update to complete"); + } + } + } + /** * Releases the lock on the H2 database. */ @@ -217,14 +226,14 @@ public class H2DBLock { LOGGER.debug("Lock file age is {} minutes", time); return time; } - + private void addShutdownHook() { if (hook == null) { hook = new H2DBCleanupHook(this); Runtime.getRuntime().addShutdownHook(hook); } } - + private void removeShutdownHook() { if (hook != null) { try {