Browse Source

Fixed find_files, search by extension.

ends_with was matching NKJV against KJV.  Fixed.
Steve Thielemann 1 month ago
parent
commit
70e4996912
1 changed files with 13 additions and 8 deletions
  1. 13 8
      src/main.rs

+ 13 - 8
src/main.rs

@@ -168,11 +168,12 @@ static BOOK_MAP: LazyLock<HashMap<&str, usize>> =
 fn find_files(base_dir: &str, version: &str) -> Vec<String> {
     let paths = std::fs::read_dir(base_dir).unwrap();
     let mut result = Vec::<String>::new();
+    let version_ext = ".".to_string() + version;
 
     for path in paths {
         if let Ok(dir) = path {
             let filename = dir.file_name().to_string_lossy().to_string();
-            if filename.ends_with(version) {
+            if filename.ends_with(&version_ext) {
                 result.push(filename);
             }
         }
@@ -379,8 +380,10 @@ fn main() -> Result<()> {
                 // This outputs the books in a random order (according to how
                 // the String keys are arranged in the HashMap).
                 // I would like them to be in order.
-                
-                for (book, info) in json_output.book {
+
+                for book in json_output.books {
+                // for (book, info) in json_output.book {
+                    let info = json_output.book.get(&book).unwrap();
                     // Find the index # we need.
 
                     let mut bid: usize = 0;
@@ -457,13 +460,15 @@ fn main() -> Result<()> {
                                     text
                                 ));
                             }
-                            // Output the insert statement
-                            if !collection.is_empty() {
-                                let _ = writeln!(file, "{} {};", base, collection.join(","));
-                                collection.clear();
-                            }
                         }
+                        // Output the insert statement
+                        if !collection.is_empty() {
+                            let _ = writeln!(file, "{} {};", base, collection.join(","));
+                            collection.clear();
+                        }
+
                         let _ = writeln!(file, "COMMIT;");
+                        collection.clear();
                     }
                 }
             }