Apache Lucene open-source search software
SOLR-14028: Fix test permissions for TestSolrCLIRunExample
Kevin Risden7c8635d600b6
diff --git a/lucene/common-build.xml b/lucene/common-build.xmlindex 5f0353fa284..c76dd545168 100644--- a/lucene/common-build.xml+++ b/lucene/common-build.xml@@ -1094,7 +1094,6 @@<!-- Restrict access to certain Java features and install security manager: --><sysproperty key="common.dir" file="${common.dir}" />- <sysproperty key="common-solr.dir" file="${common.dir}/../solr" /><sysproperty key="ant.library.dir" file="${ant.library.dir}" /><sysproperty key="clover.db.dir" file="${clover.db.dir}" /><syspropertyset>diff --git a/lucene/tools/junit4/solr-tests.policy b/lucene/tools/junit4/solr-tests.policyindex 88beda03dbd..7de5660027f 100644--- a/lucene/tools/junit4/solr-tests.policy+++ b/lucene/tools/junit4/solr-tests.policy@@ -21,7 +21,7 @@ grant {// contain read access to only what we need:// 3rd party jar resources (where symlinks are not supported), test-files/ resourcespermission java.io.FilePermission "${common.dir}${/}-", "read";- permission java.io.FilePermission "${common-solr.dir}${/}-", "read";+ permission java.io.FilePermission "${common.dir}${/}..${/}solr${/}-", "read";// 3rd party jar resources (where symlinks are supported)permission java.io.FilePermission "${user.home}${/}.ivy2${/}cache${/}-", "read";// system jar resourcesdiff --git a/solr/core/src/java/org/apache/solr/util/SimplePostTool.java b/solr/core/src/java/org/apache/solr/util/SimplePostTool.javaindex 590ec4a990f..54ec6b2999e 100644--- a/solr/core/src/java/org/apache/solr/util/SimplePostTool.java+++ b/solr/core/src/java/org/apache/solr/util/SimplePostTool.java@@ -42,6 +42,7 @@ import java.nio.BufferOverflowException;import java.nio.ByteBuffer;import java.nio.charset.Charset;import java.nio.charset.StandardCharsets;+import java.nio.file.InvalidPathException;import java.security.GeneralSecurityException;import java.text.SimpleDateFormat;import java.util.ArrayList;@@ -434,6 +435,15 @@ public class SimplePostTool {"The web mode is a simple crawler following links within domain, default delay=10s.");}+ private boolean checkIsValidPath(File srcFile) {+ try {+ srcFile.toPath();+ return true;+ } catch (InvalidPathException e) {+ return false;+ }+ }+/** Post all filenames provided in args* @param args array of file names* @param startIndexInArgs offset to start@@ -446,21 +456,13 @@ public class SimplePostTool {int filesPosted = 0;for (int j = startIndexInArgs; j < args.length; j++) {File srcFile = new File(args[j]);- if(srcFile.isDirectory() && srcFile.canRead()) {+ boolean isValidPath = checkIsValidPath(srcFile);+ if(isValidPath && srcFile.isDirectory() && srcFile.canRead()) {filesPosted += postDirectory(srcFile, out, type);- } else if (srcFile.isFile() && srcFile.canRead()) {+ } else if (isValidPath && srcFile.isFile() && srcFile.canRead()) {filesPosted += postFiles(new File[] {srcFile}, out, type);} else {- File parent = srcFile.getParentFile();- if(parent == null) parent = new File(".");- String fileGlob = srcFile.getName();- GlobFileFilter ff = new GlobFileFilter(fileGlob, false);- File[] files = parent.listFiles(ff);- if(files == null || files.length == 0) {- warn("No files or directories matching "+srcFile);- continue;- }- filesPosted += postFiles(parent.listFiles(ff), out, type);+ filesPosted += handleGlob(srcFile, out, type);}}return filesPosted;@@ -477,21 +479,13 @@ public class SimplePostTool {reset();int filesPosted = 0;for (File srcFile : files) {- if(srcFile.isDirectory() && srcFile.canRead()) {+ boolean isValidPath = checkIsValidPath(srcFile);+ if(isValidPath && srcFile.isDirectory() && srcFile.canRead()) {filesPosted += postDirectory(srcFile, out, type);- } else if (srcFile.isFile() && srcFile.canRead()) {+ } else if (isValidPath && srcFile.isFile() && srcFile.canRead()) {filesPosted += postFiles(new File[] {srcFile}, out, type);} else {- File parent = srcFile.getParentFile();- if(parent == null) parent = new File(".");- String fileGlob = srcFile.getName();- GlobFileFilter ff = new GlobFileFilter(fileGlob, false);- File[] fileList = parent.listFiles(ff);- if(fileList == null || fileList.length == 0) {- warn("No files or directories matching "+srcFile);- continue;- }- filesPosted += postFiles(fileList, out, type);+ filesPosted += handleGlob(srcFile, out, type);}}return filesPosted;@@ -539,6 +533,28 @@ public class SimplePostTool {return filesPosted;}+ /**+ * This only handles file globs not full path globbing.+ * @param globFile file holding glob path+ * @param out outputStream to write results to+ * @param type default content-type to use when posting (may be overridden in auto mode)+ * @return number of files posted+ */+ int handleGlob(File globFile, OutputStream out, String type) {+ int filesPosted = 0;+ File parent = globFile.getParentFile();+ if (parent == null) parent = new File(".");+ String fileGlob = globFile.getName();+ GlobFileFilter ff = new GlobFileFilter(fileGlob, false);+ File[] fileList = parent.listFiles(ff);+ if (fileList == null || fileList.length == 0) {+ warn("No files or directories matching " + globFile);+ } else {+ filesPosted = postFiles(fileList, out, type);+ }+ return filesPosted;+ }+/*** This method takes as input a list of start URL strings for crawling,* adds each one to a backlog and then starts crawling