hatch base dir keys() lookup repair
authorBill Erickson <berick@esilibrary.com>
Mon, 5 May 2014 17:01:06 +0000 (13:01 -0400)
committerJeff Godin <jgodin@tadl.org>
Fri, 3 Jun 2016 20:38:50 +0000 (16:38 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/org/evergreen_ils/hatch/FileIO.java

index 861c05c..0aa2fc7 100644 (file)
@@ -76,12 +76,9 @@ public class FileIO {
     }
 
     /**
-     * Locates the requested file by name within our configured base path.
-     *
-     * @param key The relative file name (key)
-     * @return The File object if found.
+     * Returns the base directory as a File for all file IO actions
      */
-    protected File getFile(String key) {
+    protected File baseDir() {
 
         // basePath directory
         File dir = new File(basePath);
@@ -100,10 +97,22 @@ public class FileIO {
                 return null;
             }
         }
-                
-        logger.info("working with directory: " + subDir.getName());
+
+        logger.info("baseDir: " + subDir.getName());
+        return subDir;
+    }
+
+    /**
+     * Locates the requested file by name within our configured base path.
+     *
+     * @param key The relative file name (key)
+     * @return The File object if found.
+     */
+    protected File getFile(String key) {
+        File baseDir = baseDir();
+        if (baseDir == null) return null;
         key = cleanFileName(key);
-        return new File(subDir, key);
+        return new File(baseDir, key);
     }
 
     /**
@@ -254,8 +263,9 @@ public class FileIO {
     public String[] keys(String prefix) {
         logger.info("keys => " + prefix);
 
-        File dir = new File(basePath);
-        if (!dir.exists()) return new String[0];
+        File dir = baseDir();
+        if (dir == null || !dir.exists()) 
+            return new String[0];
 
         LinkedList<String> nameList = new LinkedList<String>();
         File[] files = dir.listFiles();