Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4288: Improve logging for FileDataSource (basePath, relative resources).

Dawid Weissb0cba0346b82
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 368492f0daf..ce0551422f5 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -299,6 +299,9 @@ Optimizations
Bug Fixes
----------------------
+* SOLR-4288: Improve logging for FileDataSource (basePath, relative
+ resources). (Dawid Weiss)
+
* SOLR-4007: Morfologik dictionaries not available in Solr field type
due to class loader lookup problems. (Lance Norskog, Dawid Weiss)
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java
index d9892186bb0..8001935e889 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java
@@ -92,22 +92,35 @@ public class FileDataSource extends DataSource<Reader> {
static File getFile(String basePath, String query) {
try {
- File file0 = new File(query);
- File file = file0;
+ File file = new File(query);
- if (!file.isAbsolute())
- file = new File(basePath + query);
+ // If it's not an absolute path, try relative from basePath.
+ if (!file.isAbsolute()) {
+ // Resolve and correct basePath.
+ File basePathFile;
+ if (basePath == null) {
+ basePathFile = new File(".").getAbsoluteFile();
+ LOG.warn("FileDataSource.basePath is empty. " +
+ "Resolving to: " + basePathFile.getAbsolutePath());
+ } else {
+ basePathFile = new File(basePath);
+ if (!basePathFile.isAbsolute()) {
+ basePathFile = basePathFile.getAbsoluteFile();
+ LOG.warn("FileDataSource.basePath is not absolute. Resolving to: "
+ + basePathFile.getAbsolutePath());
+ }
+ }
+
+ file = new File(basePathFile, query).getAbsoluteFile();
+ }
if (file.isFile() && file.canRead()) {
- LOG.debug("Accessing File: " + file.toString());
+ LOG.debug("Accessing File: " + file.getAbsolutePath());
return file;
- } else if (file != file0)
- if (file0.isFile() && file0.canRead()) {
- LOG.debug("Accessing File0: " + file0.toString());
- return file0;
- }
-
- throw new FileNotFoundException("Could not find file: " + query);
+ } else {
+ throw new FileNotFoundException("Could not find file: " + query +
+ " (resolved to: " + file.getAbsolutePath());
+ }
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}