]> git.proxmox.com Git - proxmox-backup.git/commitdiff
datastore: add generic open_index
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 28 Feb 2019 09:21:56 +0000 (10:21 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 28 Feb 2019 14:26:40 +0000 (15:26 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/backup/datastore.rs

index f21588aa837d1774ee71f594656eafa54a184c0f..85d1645692029ad3570058b619dbe205030f612c 100644 (file)
@@ -13,6 +13,7 @@ use crate::config::datastore;
 use super::chunk_store::*;
 use super::fixed_index::*;
 use super::dynamic_index::*;
+use super::index::*;
 
 use chrono::{Utc, TimeZone};
 
@@ -134,6 +135,20 @@ impl DataStore {
         Ok(index)
     }
 
+    pub fn open_index<P>(&self, filename: P) -> Result<Box<dyn IndexFile + Send>, Error>
+    where
+        P: AsRef<Path>,
+    {
+        let filename = filename.as_ref();
+        let out: Box<dyn IndexFile + Send> =
+            match filename.extension().and_then(|ext| ext.to_str()) {
+                Some("didx") => Box::new(self.open_dynamic_reader(filename)?),
+                Some("fidx") => Box::new(self.open_fixed_reader(filename)?),
+                _ => bail!("cannot open index file of unknown type: {:?}", filename),
+            };
+        Ok(out)
+    }
+
     pub fn base_path(&self) -> PathBuf {
         self.chunk_store.base_path()
     }