diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-12-31 15:32:51 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-12-31 17:25:42 +0200 |
commit | 6171b3c2eb8ec9a7734e8ce00c81999500b5fbe6 (patch) | |
tree | 9388040e96f3a42679860f70c4540aedceff329d /src/generation.rs | |
parent | 85d0ce236677c35c85d76bfc345e36d29f585390 (diff) | |
download | obnam2-6171b3c2eb8ec9a7734e8ce00c81999500b5fbe6.tar.gz |
feat: incremental backup
This uses the previous, latest generation as a guideline to see what
is new or changed.
Diffstat (limited to 'src/generation.rs')
-rw-r--r-- | src/generation.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/generation.rs b/src/generation.rs index 4e7589c..7a4b71b 100644 --- a/src/generation.rs +++ b/src/generation.rs @@ -1,4 +1,5 @@ use crate::chunkid::ChunkId; +use crate::error::ObnamError; use crate::fsentry::FilesystemEntry; use rusqlite::{params, Connection, OpenFlags, Row, Transaction}; use std::path::Path; @@ -184,4 +185,35 @@ impl LocalGeneration { } Ok(ids) } + + pub fn get_file(&self, filename: &Path) -> anyhow::Result<Option<FilesystemEntry>> { + match self.get_file_and_fileno(filename)? { + None => Ok(None), + Some((_, e)) => Ok(Some(e)), + } + } + + pub fn get_fileno(&self, filename: &Path) -> anyhow::Result<Option<u64>> { + match self.get_file_and_fileno(filename)? { + None => Ok(None), + Some((id, _)) => Ok(Some(id)), + } + } + + fn get_file_and_fileno( + &self, + filename: &Path, + ) -> anyhow::Result<Option<(u64, FilesystemEntry)>> { + let files = self.files()?; + let files: Vec<(u64, FilesystemEntry)> = files + .iter() + .filter(|(_, e)| e.pathbuf() == filename) + .map(|(id, e)| (*id, e.clone())) + .collect(); + match files.len() { + 0 => Ok(None), + 1 => Ok(Some((files[0].0, files[0].1.clone()))), + _ => return Err(ObnamError::TooManyFiles(filename.to_path_buf()).into()), + } + } } |