Run cargo fmt

This commit is contained in:
Jacob Hinkle 2022-10-27 15:23:52 -04:00
parent feab22026d
commit 12b669d591
4 changed files with 40 additions and 25 deletions

View File

@ -13,9 +13,9 @@ use rusqlite::Connection;
use rusqlite_migration::{Error as RMError, Migrations, SchemaVersion, M}; use rusqlite_migration::{Error as RMError, Migrations, SchemaVersion, M};
use uuid; use uuid;
use std::collections::{HashSet}; use std::collections::HashSet;
use std::num::NonZeroUsize; // for describing schema versions use std::num::NonZeroUsize; // for describing schema versions
use std::path::{PathBuf}; use std::path::PathBuf;
static MIGRATIONS: Lazy<Migrations<'static>> = Lazy::new(|| { static MIGRATIONS: Lazy<Migrations<'static>> = Lazy::new(|| {
Migrations::new(vec![M::up(include_str!( Migrations::new(vec![M::up(include_str!(
@ -77,9 +77,7 @@ pub struct SchemaUpdateResult {
pub updated: bool, pub updated: bool,
} }
/// Ensure that the schema in conn is current. /// Ensure that the schema in conn is current.
pub fn ensure_schema( pub fn ensure_schema(conn: &mut Connection) -> Result<SchemaUpdateResult, SchemaError> {
conn: &mut Connection,
) -> Result<SchemaUpdateResult, SchemaError> {
let old_version = schema_version(conn)?; let old_version = schema_version(conn)?;
let current_version = unsafe { NonZeroUsize::new_unchecked(CURRENT_SCHEMA_VERSION) }; let current_version = unsafe { NonZeroUsize::new_unchecked(CURRENT_SCHEMA_VERSION) };
Ok(SchemaUpdateResult { Ok(SchemaUpdateResult {
@ -122,16 +120,22 @@ pub enum FindDatasetError {
NotImplemented, NotImplemented,
} }
impl From<std::io::Error> for FindDatasetError { impl From<std::io::Error> for FindDatasetError {
fn from(e: std::io::Error) -> FindDatasetError { FindDatasetError::PathError(e) } fn from(e: std::io::Error) -> FindDatasetError {
FindDatasetError::PathError(e)
}
} }
/// Given a collection of paths, find a common directory containing them. /// Given a collection of paths, find a common directory containing them.
/// ///
/// Returns `Ok(path)` if `path` is the only dataset found and it contains all given search paths. /// Returns `Ok(path)` if `path` is the only dataset found and it contains all given search paths.
pub fn find_dataset_dir(paths: &[PathBuf]) -> Result<PathBuf, FindDatasetError> { pub fn find_dataset_dir(paths: &[PathBuf]) -> Result<PathBuf, FindDatasetError> {
let mut ds_dirs: HashSet<PathBuf> = HashSet::new(); let mut ds_dirs: HashSet<PathBuf> = HashSet::new();
let first_path = paths.iter().next().ok_or(FindDatasetError::NoPathsProvided)?.canonicalize()?; let first_path = paths
.iter()
.next()
.ok_or(FindDatasetError::NoPathsProvided)?
.canonicalize()?;
log::debug!("First path is {:?}", first_path); log::debug!("First path is {:?}", first_path);
let mut common_path = first_path.to_path_buf(); let mut common_path = first_path.to_path_buf();
@ -184,14 +188,17 @@ pub fn find_dataset_dir(paths: &[PathBuf]) -> Result<PathBuf, FindDatasetError>
if ds_dirs.len() == 0 { if ds_dirs.len() == 0 {
Err(FindDatasetError::NoDataset(common_path)) Err(FindDatasetError::NoDataset(common_path))
} else if ds_dirs.len() == 1 { } else if ds_dirs.len() == 1 {
let d = ds_dirs.iter().next().expect("ds_dirs has exactly one value"); let d = ds_dirs
.iter()
.next()
.expect("ds_dirs has exactly one value");
if some_not_in_ds { if some_not_in_ds {
Err(FindDatasetError::SomeNotInDataset) Err(FindDatasetError::SomeNotInDataset)
} else { } else {
Ok(d.to_path_buf()) Ok(d.to_path_buf())
} }
} else {
} else { // ds_dirs.len() > 1 // ds_dirs.len() > 1
Err(FindDatasetError::MultipleDatasets { Err(FindDatasetError::MultipleDatasets {
datasets: ds_dirs.into_iter().collect(), datasets: ds_dirs.into_iter().collect(),
some_paths_not_in_dataset: some_not_in_ds, some_paths_not_in_dataset: some_not_in_ds,

View File

@ -9,6 +9,10 @@ pub enum RecordError {
} }
pub fn record(path: &Path, message: &String) -> Result<(), RecordError> { pub fn record(path: &Path, message: &String) -> Result<(), RecordError> {
log::info!("Recording path {:?} with user-provided message \"{}\"", path, message); log::info!(
"Recording path {:?} with user-provided message \"{}\"",
path,
message
);
Err(RecordError::NotImplemented) Err(RecordError::NotImplemented)
} }

View File

@ -63,8 +63,10 @@ fn main() {
Err(nancy::db::FindDatasetError::NoDataset(path)) => { Err(nancy::db::FindDatasetError::NoDataset(path)) => {
log::info!("No dataset at or above nearest ancestor path: {:?}", path); log::info!("No dataset at or above nearest ancestor path: {:?}", path);
if !initialize { if !initialize {
log::error!("Refusing to initialize a new dataset at {path:?}. \ log::error!(
Pass the -i or --initialize flag to request initialization."); "Refusing to initialize a new dataset at {path:?}. \
Pass the -i or --initialize flag to request initialization."
);
process::exit(1); process::exit(1);
} }
let dbpath = &path.join("nancy.db"); let dbpath = &path.join("nancy.db");
@ -82,10 +84,7 @@ fn main() {
c.pragma_update(None, "foreign_keys", &"ON").unwrap(); c.pragma_update(None, "foreign_keys", &"ON").unwrap();
match nancy::db::init(&mut c) { match nancy::db::init(&mut c) {
Err(e) => { Err(e) => {
log::error!( log::error!("Encountered error in initializing schema: {:?}", e);
"Encountered error in initializing schema: {:?}",
e
);
process::exit(1); process::exit(1);
} }
Ok(dataset_uuid) => { Ok(dataset_uuid) => {
@ -109,11 +108,11 @@ fn main() {
} }
} }
c c
}, }
Err(e) => { Err(e) => {
log::error!("Could not determine dataset directory: {:?}", e); log::error!("Could not determine dataset directory: {:?}", e);
process::exit(1); process::exit(1);
}, }
Ok(path) => { Ok(path) => {
// existing // existing
log::info!("Found existing dataset at path: {:?}", path); log::info!("Found existing dataset at path: {:?}", path);
@ -142,7 +141,7 @@ fn main() {
} }
} }
c c
}, }
}; };
if let Err(e) = nancy::program::with_program(&mut conn, "RECORD", message, |prog| { if let Err(e) = nancy::program::with_program(&mut conn, "RECORD", message, |prog| {

View File

@ -2,7 +2,7 @@ use log;
use rusqlite::{Connection, Error as RSQLError, Transaction}; use rusqlite::{Connection, Error as RSQLError, Transaction};
extern crate derive_more; extern crate derive_more;
use derive_more::From; use derive_more::From;
use uuid::{Uuid}; use uuid::Uuid;
use std::time::{Instant, SystemTime}; use std::time::{Instant, SystemTime};
@ -38,8 +38,8 @@ impl Program {
} }
} }
pub fn perform_task<R, F>(self: &Program, inputs: &[TaskInput], f: F) -> R pub fn perform_task<R, F>(self: &Program, inputs: &[TaskInput], f: F) -> R
where where
F: FnOnce(&Task) -> R F: FnOnce(&Task) -> R,
{ {
let start = Instant::now(); let start = Instant::now();
let u = Uuid::new_v4(); let u = Uuid::new_v4();
@ -79,7 +79,12 @@ pub fn with_program<E, F: FnOnce(Program) -> Result<(), E>>(
let log_target = &format!("nancy.program ({})", name); let log_target = &format!("nancy.program ({})", name);
log::info!(target: log_target, "Preparing program {} ({})", name, message); log::info!(
target: log_target,
"Preparing program {} ({})",
name,
message
);
// start transaction // start transaction
let txres = conn.transaction(); let txres = conn.transaction();