Browse Source

put crawler_*.properties in temp dir and add session id prefix

Shinsuke Sugaya 9 năm trước cách đây
mục cha
commit
32d92e9397

+ 4 - 0
src/main/java/org/codelibs/fess/Constants.java

@@ -364,4 +364,8 @@ public class Constants extends CoreLibConstants {
     public static final String LDAP_INITIAL_CONTEXT_FACTORY = "ldap.initial.context.factory";
     public static final String LDAP_INITIAL_CONTEXT_FACTORY = "ldap.initial.context.factory";
 
 
     public static final String LDAP_ACCOUNT_FILTER = "ldap.account.filter";
     public static final String LDAP_ACCOUNT_FILTER = "ldap.account.filter";
+
+    public static final String CRAWLER_SESSION_ID_PREFIX = "C";
+
+    public static final String SUGGEST_SESSION_ID_PREFIX = "S";
 }
 }

+ 6 - 4
src/main/java/org/codelibs/fess/job/CrawlJob.java

@@ -166,7 +166,7 @@ public class CrawlJob {
 
 
         if (sessionId == null) { // create session id
         if (sessionId == null) { // create session id
             final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
             final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-            sessionId = sdf.format(new Date());
+            sessionId = Constants.CRAWLER_SESSION_ID_PREFIX + sdf.format(new Date());
         }
         }
         resultBuf.append("Session Id: ").append(sessionId).append("\n");
         resultBuf.append("Session Id: ").append(sessionId).append("\n");
         resultBuf.append("Web  Config Id:");
         resultBuf.append("Web  Config Id:");
@@ -344,11 +344,10 @@ public class CrawlJob {
             cmdList.add(Integer.toString(documentExpires));
             cmdList.add(Integer.toString(documentExpires));
         }
         }
 
 
+        File propFile = null;
         try {
         try {
             cmdList.add("-p");
             cmdList.add("-p");
-            File propFile =
-                    new File(ownTmpDir != null ? ownTmpDir.getAbsolutePath() : tmpDir, "crawler_" + systemHelper.getCurrentTimeAsLong()
-                            + ".properties");
+            propFile = File.createTempFile("crawler_", ".properties");
             cmdList.add(propFile.getAbsolutePath());
             cmdList.add(propFile.getAbsolutePath());
             try (FileOutputStream out = new FileOutputStream(propFile)) {
             try (FileOutputStream out = new FileOutputStream(propFile)) {
                 Properties prop = new Properties();
                 Properties prop = new Properties();
@@ -392,6 +391,9 @@ public class CrawlJob {
             try {
             try {
                 jobHelper.destroyProcess(sessionId);
                 jobHelper.destroyProcess(sessionId);
             } finally {
             } finally {
+                if (propFile != null && !propFile.delete()) {
+                    logger.warn("Failed to delete {}.", propFile.getAbsolutePath());
+                }
                 deleteTempDir(ownTmpDir);
                 deleteTempDir(ownTmpDir);
             }
             }
         }
         }

+ 6 - 6
src/main/java/org/codelibs/fess/job/SuggestJob.java

@@ -32,7 +32,6 @@ import org.codelibs.fess.Constants;
 import org.codelibs.fess.exception.FessSystemException;
 import org.codelibs.fess.exception.FessSystemException;
 import org.codelibs.fess.exec.SuggestCreator;
 import org.codelibs.fess.exec.SuggestCreator;
 import org.codelibs.fess.helper.JobHelper;
 import org.codelibs.fess.helper.JobHelper;
-import org.codelibs.fess.helper.SystemHelper;
 import org.codelibs.fess.mylasta.direction.FessConfig;
 import org.codelibs.fess.mylasta.direction.FessConfig;
 import org.codelibs.fess.util.ComponentUtil;
 import org.codelibs.fess.util.ComponentUtil;
 import org.codelibs.fess.util.InputStreamThread;
 import org.codelibs.fess.util.InputStreamThread;
@@ -100,7 +99,7 @@ public class SuggestJob {
 
 
         if (sessionId == null) { // create session id
         if (sessionId == null) { // create session id
             final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
             final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-            sessionId = sdf.format(new Date());
+            sessionId = Constants.SUGGEST_SESSION_ID_PREFIX + sdf.format(new Date());
         }
         }
         resultBuf.append("Session Id: ").append(sessionId).append("\n");
         resultBuf.append("Session Id: ").append(sessionId).append("\n");
         if (jobExecutor != null) {
         if (jobExecutor != null) {
@@ -123,7 +122,6 @@ public class SuggestJob {
         final List<String> cmdList = new ArrayList<>();
         final List<String> cmdList = new ArrayList<>();
         final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
         final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
         final ServletContext servletContext = SingletonLaContainer.getComponent(ServletContext.class);
         final ServletContext servletContext = SingletonLaContainer.getComponent(ServletContext.class);
-        final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
         final JobHelper jobHelper = ComponentUtil.getJobHelper();
         final JobHelper jobHelper = ComponentUtil.getJobHelper();
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
         final FessConfig fessConfig = ComponentUtil.getFessConfig();
 
 
@@ -218,11 +216,10 @@ public class SuggestJob {
         cmdList.add("--sessionId");
         cmdList.add("--sessionId");
         cmdList.add(sessionId);
         cmdList.add(sessionId);
 
 
+        File propFile = null;
         try {
         try {
             cmdList.add("-p");
             cmdList.add("-p");
-            File propFile =
-                    new File(ownTmpDir != null ? ownTmpDir.getAbsolutePath() : tmpDir, "crawler_" + systemHelper.getCurrentTimeAsLong()
-                            + ".properties");
+            propFile = File.createTempFile("crawler_", ".properties");
             cmdList.add(propFile.getAbsolutePath());
             cmdList.add(propFile.getAbsolutePath());
             try (FileOutputStream out = new FileOutputStream(propFile)) {
             try (FileOutputStream out = new FileOutputStream(propFile)) {
                 Properties prop = new Properties();
                 Properties prop = new Properties();
@@ -266,6 +263,9 @@ public class SuggestJob {
             try {
             try {
                 jobHelper.destroyProcess(sessionId);
                 jobHelper.destroyProcess(sessionId);
             } finally {
             } finally {
+                if (propFile != null && !propFile.delete()) {
+                    logger.warn("Failed to delete {}.", propFile.getAbsolutePath());
+                }
                 deleteTempDir(ownTmpDir);
                 deleteTempDir(ownTmpDir);
             }
             }
         }
         }