You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2013/01/16 15:44:57 UTC

svn commit: r1433957 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/CHANGES.txt solr/contrib/ solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java

Author: sarowe
Date: Wed Jan 16 14:44:56 2013
New Revision: 1433957

URL: http://svn.apache.org/viewvc?rev=1433957&view=rev
Log:
SOLR-4288: Improve logging for FileDataSource (basePath, relative resources). (merged trunk r1433849)

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/contrib/   (props changed)
    lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1433957&r1=1433956&r2=1433957&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Wed Jan 16 14:44:56 2013
@@ -276,6 +276,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)
 

Modified: lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java?rev=1433957&r1=1433956&r2=1433957&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java (original)
+++ lucene/dev/branches/branch_4x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/FileDataSource.java Wed Jan 16 14:44:56 2013
@@ -92,22 +92,35 @@ public class FileDataSource extends Data
 
   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);
     }