From 38cccfb057cbeaeab3f7cf23a74094679b635683 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 8 May 2015 15:08:13 -0400 Subject: [PATCH] cleanup and ban temp files going to jvm default location --- dev-tools/forbidden/all-signatures.txt | 4 ++++ src/main/java/org/elasticsearch/bootstrap/Security.java | 2 ++ src/main/java/org/elasticsearch/http/HttpServer.java | 6 ++---- .../java/org/elasticsearch/bootstrap/SecurityTests.java | 5 +++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dev-tools/forbidden/all-signatures.txt b/dev-tools/forbidden/all-signatures.txt index 8c82fee5239..3b5eb7a0b03 100644 --- a/dev-tools/forbidden/all-signatures.txt +++ b/dev-tools/forbidden/all-signatures.txt @@ -41,3 +41,7 @@ org.apache.lucene.search.PrefixFilter java.nio.file.Paths @ Use PathUtils.get instead. java.nio.file.FileSystems#getDefault() @ use PathUtils.getDefault instead. + +@defaultMessage Specify a location for the temp file/directory instead. +java.nio.file.Files#createTempDirectory(java.lang.String,java.nio.file.attribute.FileAttribute[]) +java.nio.file.Files#createTempFile(java.lang.String,java.lang.String,java.nio.file.attribute.FileAttribute[]) diff --git a/src/main/java/org/elasticsearch/bootstrap/Security.java b/src/main/java/org/elasticsearch/bootstrap/Security.java index 436e1ec699c..7874f8002b0 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Security.java +++ b/src/main/java/org/elasticsearch/bootstrap/Security.java @@ -19,6 +19,7 @@ package org.elasticsearch.bootstrap; +import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.env.Environment; import java.io.*; @@ -82,6 +83,7 @@ public class Security { } /** Simple checks that everything is ok */ + @SuppressForbidden(reason = "accesses jvm default tempdir as a self-test") public static void selfTest() { // check we can manipulate temporary files try { diff --git a/src/main/java/org/elasticsearch/http/HttpServer.java b/src/main/java/org/elasticsearch/http/HttpServer.java index 4967271fd81..a40fc96a29d 100644 --- a/src/main/java/org/elasticsearch/http/HttpServer.java +++ b/src/main/java/org/elasticsearch/http/HttpServer.java @@ -21,11 +21,8 @@ package org.elasticsearch.http; import com.google.common.collect.ImmutableMap; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.FileSystemUtils; -import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.node.service.NodeService; @@ -172,7 +169,8 @@ public class HttpServer extends AbstractLifecycleComponent { if (sitePath.length() == 0) { sitePath = "index.html"; } else { - while (sitePath.charAt(0) == '/') { + // remove extraneous leading slashes, its not an absolute path. + while (sitePath.length() > 0 && sitePath.charAt(0) == '/') { sitePath = sitePath.substring(1); } } diff --git a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java index a17e18ae51b..f50342b4e9e 100644 --- a/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java +++ b/src/test/java/org/elasticsearch/bootstrap/SecurityTests.java @@ -43,8 +43,8 @@ public class SecurityTests extends ElasticsearchTestCase { String realTmpDir = System.getProperty("java.io.tmpdir"); Permissions permissions; try { - Environment environment = new Environment(settings); System.setProperty("java.io.tmpdir", fakeTmpDir.toString()); + Environment environment = new Environment(settings); permissions = Security.createPermissions(environment); } finally { System.setProperty("java.io.tmpdir", realTmpDir); @@ -76,9 +76,10 @@ public class SecurityTests extends ElasticsearchTestCase { Path fakeTmpDir = createTempDir(); String realTmpDir = System.getProperty("java.io.tmpdir"); Permissions permissions; + Environment environment; try { - Environment environment = new Environment(settings); System.setProperty("java.io.tmpdir", fakeTmpDir.toString()); + environment = new Environment(settings); permissions = Security.createPermissions(environment); } finally { System.setProperty("java.io.tmpdir", realTmpDir);