From 1d082fd0485ee01561b39c82b25bfd8f8aaa1dc8 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 5 Dec 2021 08:58:53 +0200 Subject: chore: tidy up things found by newer Rust toolchain Sponsored-by: author --- src/cmd/restore.rs | 16 ---------------- src/generation.rs | 11 +++++------ src/index.rs | 8 ++++---- 3 files changed, 9 insertions(+), 26 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, 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, 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..dae9b78 100644 --- a/src/index.rs +++ b/src/index.rs @@ -209,7 +209,7 @@ mod sql { pub fn lookup(conn: &Connection, id: &ChunkId) -> Result { 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 = vec![]; for meta in iter { let meta = meta?; @@ -230,7 +230,7 @@ mod sql { pub fn find_by_256(conn: &Connection, sha256: &str) -> Result, 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 +241,7 @@ mod sql { pub fn find_generations(conn: &Connection) -> Result, 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 +252,7 @@ mod sql { pub fn find_chunk_ids(conn: &Connection) -> Result, 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?; -- cgit v1.2.1 From e4398288579c27c1eb83a893a781301051e68930 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 5 Dec 2021 09:00:49 +0200 Subject: chore: add missing capture types for Subplot Subplot now checks that all embedded files in the markdown file are actually used by scenarios. To do this, it needs the scenario step bindings to declare that a captured part of the scenario step is the name of an embedded file. Add the couple of such type declarations that were missing in Obnam. Sponsored-by: author --- subplot/client.yaml | 4 ++++ 1 file changed, 4 insertions(+) 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: -- cgit v1.2.1 From 496cedc9dfdad1c894a91ca0f39c022ac1bd9fb1 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 5 Dec 2021 09:12:22 +0200 Subject: chore: drop unused fields in struct Index At this point, I don't know why the fields were there, but they are now not used at all, so they can be dropped. Sponsored-by: author --- src/index.rs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/index.rs b/src/index.rs index dae9b78..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>, - generations: Vec, - metas: HashMap, } /// 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> { -- cgit v1.2.1