[niepce] db: Pass an optional filename to the library



commit 7af377ce59e1c84b19125dd934eee2e59ab9023a
Author: Hubert Figuière <hub figuiere net>
Date:   Wed Oct 17 20:38:19 2018 -0400

    db: Pass an optional filename to the library

 src/engine/db/library.rs        | 13 +++++++++----
 src/libraryclient/clientimpl.rs |  4 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/engine/db/library.rs b/src/engine/db/library.rs
index 136fbad..7eac768 100644
--- a/src/engine/db/library.rs
+++ b/src/engine/db/library.rs
@@ -77,9 +77,13 @@ pub struct Library {
 }
 
 impl Library {
-    pub fn new(dir: PathBuf, notif_id: u64) -> Library {
+    pub fn new(dir: PathBuf, name: Option<&str>, notif_id: u64) -> Library {
         let mut dbpath = dir.clone();
-        dbpath.push(DATABASENAME);
+        if let Some(filename) = name {
+            dbpath.push(filename);
+        } else {
+            dbpath.push(DATABASENAME);
+        }
         let mut lib = Library {
             // maindir: dir,
             dbpath: dbpath,
@@ -1025,11 +1029,12 @@ mod test {
         }
     }
 
+    use super::{Library, Managed};
+
     #[test]
     fn library_works() {
-        use super::{Library, Managed};
 
-        let lib = Library::new(PathBuf::from("."), 0);
+        let lib = Library::new(PathBuf::from("."), Some("library_works.db"), 0);
         let _autodelete = AutoDelete::new(lib.dbpath());
 
         assert!(lib.is_ok());
diff --git a/src/libraryclient/clientimpl.rs b/src/libraryclient/clientimpl.rs
index c2c4039..3e529e5 100644
--- a/src/libraryclient/clientimpl.rs
+++ b/src/libraryclient/clientimpl.rs
@@ -1,7 +1,7 @@
 /*
  * niepce - libraryclient/clientimpl.rs
  *
- * Copyright (C) 2017 Hubert Figuière
+ * Copyright (C) 2017-2018 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -52,7 +52,7 @@ impl ClientImpl {
         let terminate2 = terminate.clone();
 
         /* let thread = */ thread::spawn(move || {
-            let library = Library::new(dir, notif_id);
+            let library = Library::new(dir, None, notif_id);
             Self::main(&mut terminate, tasks, &library);
         });
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]