Skip to content

Commit

Permalink
cleanup and ban temp files going to jvm default location
Browse files Browse the repository at this point in the history
  • Loading branch information
rmuir committed May 8, 2015
1 parent 51c71c2 commit 38cccfb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions dev-tools/forbidden/all-signatures.txt
Expand Up @@ -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[])
2 changes: 2 additions & 0 deletions src/main/java/org/elasticsearch/bootstrap/Security.java
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.bootstrap;

import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.env.Environment;

import java.io.*;
Expand Down Expand Up @@ -82,6 +83,7 @@ public static void addPath(Permissions policy, Path path, String permissions) th
}

/** 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 {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/elasticsearch/http/HttpServer.java
Expand Up @@ -21,11 +21,8 @@

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;
Expand Down Expand Up @@ -172,7 +169,8 @@ void handlePluginSite(HttpRequest request, HttpChannel channel) throws IOExcepti
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);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/elasticsearch/bootstrap/SecurityTests.java
Expand Up @@ -43,8 +43,8 @@ public void testGeneratedPermissions() throws Exception {
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);
Expand Down Expand Up @@ -76,9 +76,10 @@ public void testEnvironmentPaths() throws Exception {
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);
Expand Down

0 comments on commit 38cccfb

Please sign in to comment.