[jsword-svn] r2232 - trunk/jsword/src/main/java/org/crosswire/jsword/book/sword

dmsmith at crosswire.org dmsmith at crosswire.org
Sun Feb 19 18:21:42 MST 2012


Author: dmsmith
Date: 2012-02-19 18:21:42 -0700 (Sun, 19 Feb 2012)
New Revision: 2232

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
Log:
Fix for JS-208: Deleting a Bible module with a DataPath not having a trailing path caused all ztext Bibles to be deleted.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java	2012-02-08 22:19:14 UTC (rev 2231)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java	2012-02-20 01:21:42 UTC (rev 2232)
@@ -205,10 +205,11 @@
         cet.add(ConfigEntryType.LIBRARY_URL, library.toString());
         super.setLibrary(library);
 
-        // Currently all DATA_PATH entries end in / to indicate dirs or not to
-        // indicate file prefixes
+        // Previously, all DATA_PATH entries end in / to indicate dirs
+        // or not to indicate file prefixes.
+        // This is no longer true.
+        // Now we need to test the file/url to see if it exists and is a directory.
         String datapath = (String) getProperty(ConfigEntryType.DATA_PATH);
-
         int lastSlash = datapath.lastIndexOf('/');
 
         // There were modules that did not have a valid datapath.
@@ -217,8 +218,26 @@
             return;
         }
 
-        datapath = datapath.substring(0, lastSlash);
+        // DataPath typically ends in a '/' to indicate a directory.
+        // If so remove it.
+        if (lastSlash == datapath.length() - 1) {
+            datapath = datapath.substring(0, lastSlash);
+        }
+
         URI location = NetUtil.lengthenURI(library, datapath);
+        File bookDir = new File(location.getPath());
+        // For some modules, the last element of the DataPath
+        // is a prefix for file names.
+        if (!bookDir.isDirectory()) {
+            // Shorten it by one segment and test again.
+            lastSlash = datapath.lastIndexOf('/');
+            datapath = datapath.substring(0, lastSlash);
+            location = NetUtil.lengthenURI(library, datapath);
+            bookDir = new File(location.getPath());
+            if (!bookDir.isDirectory()) {
+                return;
+            }
+        }
 
         cet.add(ConfigEntryType.LOCATION_URL, location.toString());
         super.setLocation(location);




More information about the jsword-svn mailing list