summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-05 07:20:25 +0000
committerLars Wirzenius <liw@liw.fi>2021-12-05 07:20:25 +0000
commitfff45f4865a4144fdeaa879bf655fa204b2fb45d (patch)
treeb6e7fa191612046e9978f1cc5df47511ca5cb839
parent7dc514d0baecbb0a4190a701ff1266f7d6a096d2 (diff)
parent496cedc9dfdad1c894a91ca0f39c022ac1bd9fb1 (diff)
downloadobnam2-fff45f4865a4144fdeaa879bf655fa204b2fb45d.tar.gz
Merge branch 'tidy-up' into 'main'
tidy up Closes #169 See merge request obnam/obnam!198
-rw-r--r--src/cmd/restore.rs16
-rw-r--r--src/generation.rs11
-rw-r--r--src/index.rs23
-rw-r--r--subplot/client.yaml4
4 files changed, 15 insertions, 39 deletions
diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs
index e9e89b5..9848caf 100644
--- a/src/cmd/restore.rs
+++ b/src/cmd/restore.rs
@@ -75,22 +75,6 @@ impl Restore {
}
}
-#[derive(Debug, StructOpt)]
-#[structopt(name = "obnam-backup", about = "Simplistic backup client")]
-struct Opt {
- #[structopt(parse(from_os_str))]
- config: PathBuf,
-
- #[structopt()]
- gen_id: String,
-
- #[structopt(parse(from_os_str))]
- dbname: PathBuf,
-
- #[structopt(parse(from_os_str))]
- to: PathBuf,
-}
-
#[derive(Debug, thiserror::Error)]
pub enum RestoreError {
#[error("Could not create named pipe (FIFO) {0}")]
diff --git a/src/generation.rs b/src/generation.rs
index 6613c02..71821d8 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -344,7 +344,7 @@ mod sql {
pub fn meta(conn: &Connection) -> Result<HashMap<String, String>, LocalGenerationError> {
let mut stmt = conn.prepare("SELECT key, value FROM meta")?;
- let iter = stmt.query_map(params![], |row| row_to_key_value(row))?;
+ let iter = stmt.query_map(params![], row_to_key_value)?;
let mut map = HashMap::new();
for r in iter {
let (key, value) = r?;
@@ -414,9 +414,9 @@ mod sql {
// a "fallible iterator" is.)
//
// The iterator is only valid for the lifetime of the associated SQLite statement; we
- // call this lifetime 'stmt, and use it both both on the reference and the returned iterator.
+ // call this lifetime 'stmt, and use it both both on the reference and the returned Now.
//
- // Now we're in a pickle: all named lifetimes have to be declared _somewhere_, but we can't add
+ // we iterator're in a pickle: all named lifetimes have to be declared _somewhere_, but we can't add
// 'stmt to the signature of `CreateIterFn` because then we'll have to specify it when we
// define the function. Obviously, at that point we won't yet have a `Statement`, and thus we
// would have no idea what its lifetime is going to be. So we can't put the 'stmt lifetime into
@@ -460,7 +460,7 @@ mod sql {
conn,
"SELECT * FROM files",
Box::new(|stmt| {
- let iter = stmt.query_map(params![], |row| row_to_entry(row))?;
+ let iter = stmt.query_map(params![], row_to_entry)?;
let iter = iter.map(|x| match x {
Ok((fileno, json, reason)) => serde_json::from_str(&json)
.map(|entry| BackedUpFile::new(fileno, entry, &reason))
@@ -515,8 +515,7 @@ mod sql {
filename: &Path,
) -> Result<Option<(FileId, FilesystemEntry, String)>, LocalGenerationError> {
let mut stmt = conn.prepare("SELECT * FROM files WHERE filename = ?1")?;
- let mut iter =
- stmt.query_map(params![path_into_blob(filename)], |row| row_to_entry(row))?;
+ let mut iter = stmt.query_map(params![path_into_blob(filename)], row_to_entry)?;
match iter.next() {
None => Ok(None),
Some(Err(e)) => {
diff --git a/src/index.rs b/src/index.rs
index d548396..d76e4a3 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -2,8 +2,7 @@ use crate::checksummer::Checksum;
use crate::chunkid::ChunkId;
use crate::chunkmeta::ChunkMeta;
use rusqlite::Connection;
-use std::collections::HashMap;
-use std::path::{Path, PathBuf};
+use std::path::Path;
/// A chunk index.
///
@@ -11,11 +10,7 @@ use std::path::{Path, PathBuf};
/// string key/value pair, or whether they are generations.
#[derive(Debug)]
pub struct Index {
- filename: PathBuf,
conn: Connection,
- map: HashMap<(String, String), Vec<ChunkId>>,
- generations: Vec<ChunkId>,
- metas: HashMap<ChunkId, ChunkMeta>,
}
/// All the errors that may be returned for `Index`.
@@ -42,13 +37,7 @@ impl Index {
} else {
sql::create_db(&filename)?
};
- Ok(Self {
- filename,
- conn,
- map: HashMap::new(),
- generations: vec![],
- metas: HashMap::new(),
- })
+ Ok(Self { conn })
}
pub fn insert_meta(&mut self, id: ChunkId, meta: ChunkMeta) -> Result<(), IndexError> {
@@ -209,7 +198,7 @@ mod sql {
pub fn lookup(conn: &Connection, id: &ChunkId) -> Result<ChunkMeta, IndexError> {
let mut stmt = conn.prepare("SELECT * FROM chunks WHERE id IS ?1")?;
- let iter = stmt.query_map(params![id], |row| row_to_meta(row))?;
+ let iter = stmt.query_map(params![id], row_to_meta)?;
let mut metas: Vec<ChunkMeta> = vec![];
for meta in iter {
let meta = meta?;
@@ -230,7 +219,7 @@ mod sql {
pub fn find_by_256(conn: &Connection, sha256: &str) -> Result<Vec<ChunkId>, IndexError> {
let mut stmt = conn.prepare("SELECT id FROM chunks WHERE sha256 IS ?1")?;
- let iter = stmt.query_map(params![sha256], |row| row_to_id(row))?;
+ let iter = stmt.query_map(params![sha256], row_to_id)?;
let mut ids = vec![];
for x in iter {
let x = x?;
@@ -241,7 +230,7 @@ mod sql {
pub fn find_generations(conn: &Connection) -> Result<Vec<ChunkId>, IndexError> {
let mut stmt = conn.prepare("SELECT id FROM chunks WHERE generation IS 1")?;
- let iter = stmt.query_map(params![], |row| row_to_id(row))?;
+ let iter = stmt.query_map(params![], row_to_id)?;
let mut ids = vec![];
for x in iter {
let x = x?;
@@ -252,7 +241,7 @@ mod sql {
pub fn find_chunk_ids(conn: &Connection) -> Result<Vec<ChunkId>, IndexError> {
let mut stmt = conn.prepare("SELECT id FROM chunks WHERE generation IS 0")?;
- let iter = stmt.query_map(params![], |row| row_to_id(row))?;
+ let iter = stmt.query_map(params![], row_to_id)?;
let mut ids = vec![];
for x in iter {
let x = x?;
diff --git a/subplot/client.yaml b/subplot/client.yaml
index ec41344..104f479 100644
--- a/subplot/client.yaml
+++ b/subplot/client.yaml
@@ -14,11 +14,15 @@
impl:
python:
function: configure_client_with_init
+ types:
+ filename: file
- given: "a client config, without passphrase, based on {filename}"
impl:
python:
function: configure_client_without_init
+ types:
+ filename: file
- when: "I invoke obnam restore <{genid}> {todir}"
impl: