Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15973: Fix TestSchemaDesignerConfigSetHelper#testDownloadAndZip failure on Windows

Kevin Risden0b18725ea291
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
index abf23ffa0dc..d3ff712ee90 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ConfigSetsHandler.java
@@ -225,26 +225,22 @@ public class ConfigSetsHandler extends RequestHandlerBase implements PermissionN
// For creating the baseZnode, the cleanup parameter is only allowed to be true when singleFilePath is not passed.
createBaseNode(configSetService, overwritesExisting, requestIsTrusted, configSetName);
- ZipInputStream zis = new ZipInputStream(inputStream, StandardCharsets.UTF_8);
- ZipEntry zipEntry = null;
- boolean hasEntry = false;
- while ((zipEntry = zis.getNextEntry()) != null) {
- hasEntry = true;
- String filePath = zipEntry.getName();
- if (filePath.endsWith("/")) {
- filesToDelete.remove(filePath.substring(0, filePath.length() - 1));
- } else {
+ try(ZipInputStream zis = new ZipInputStream(inputStream, StandardCharsets.UTF_8)) {
+ boolean hasEntry = false;
+ ZipEntry zipEntry;
+ while ((zipEntry = zis.getNextEntry()) != null) {
+ hasEntry = true;
+ String filePath = zipEntry.getName();
filesToDelete.remove(filePath);
+ if (!zipEntry.isDirectory()) {
+ configSetService.uploadFileToConfig(configSetName, filePath, IOUtils.toByteArray(zis), true);
+ }
}
- if (!zipEntry.isDirectory()) {
- configSetService.uploadFileToConfig(configSetName, zipEntry.getName(), IOUtils.toByteArray(zis), true);
+ if (!hasEntry) {
+ throw new SolrException(ErrorCode.BAD_REQUEST,
+ "Either empty zipped data, or non-zipped data was uploaded. In order to upload a configSet, you must zip a non-empty directory to upload.");
}
}
- zis.close();
- if (!hasEntry) {
- throw new SolrException(ErrorCode.BAD_REQUEST,
- "Either empty zipped data, or non-zipped data was uploaded. In order to upload a configSet, you must zip a non-empty directory to upload.");
- }
deleteUnusedFiles(configSetService, configSetName, filesToDelete);
// If the request is doing a full trusted overwrite of an untrusted configSet (overwrite=true, cleanup=true), then trust the configSet.
diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java
index d25d0551184..cb96303a538 100644
--- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java
+++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerConfigSetHelper.java
@@ -126,9 +126,11 @@ public class TestSchemaDesignerConfigSetHelper extends SolrCloudTestCase impleme
ZipEntry entry;
while ((entry = stream.getNextEntry()) != null) {
- if ("solrconfig.xml".equals(entry.getName())) {
+ // ZipEntry names have file separators that are OS specific. This normalizes to forward slash.
+ String entryName = entry.getName().replace('\\', '/');
+ if ("solrconfig.xml".equals(entryName)) {
foundSolrConfig = true;
- } else if ("lang/stopwords_en.txt".equals(entry.getName())) {
+ } else if ("lang/stopwords_en.txt".equals(entryName)) {
foundStopWords = true;
}
}