Run cargo fmt
This commit is contained in:
parent
feab22026d
commit
12b669d591
29
src/db.rs
29
src/db.rs
@ -13,9 +13,9 @@ use rusqlite::Connection;
|
||||
use rusqlite_migration::{Error as RMError, Migrations, SchemaVersion, M};
|
||||
use uuid;
|
||||
|
||||
use std::collections::{HashSet};
|
||||
use std::collections::HashSet;
|
||||
use std::num::NonZeroUsize; // for describing schema versions
|
||||
use std::path::{PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
static MIGRATIONS: Lazy<Migrations<'static>> = Lazy::new(|| {
|
||||
Migrations::new(vec![M::up(include_str!(
|
||||
@ -77,9 +77,7 @@ pub struct SchemaUpdateResult {
|
||||
pub updated: bool,
|
||||
}
|
||||
/// Ensure that the schema in conn is current.
|
||||
pub fn ensure_schema(
|
||||
conn: &mut Connection,
|
||||
) -> Result<SchemaUpdateResult, SchemaError> {
|
||||
pub fn ensure_schema(conn: &mut Connection) -> Result<SchemaUpdateResult, SchemaError> {
|
||||
let old_version = schema_version(conn)?;
|
||||
let current_version = unsafe { NonZeroUsize::new_unchecked(CURRENT_SCHEMA_VERSION) };
|
||||
Ok(SchemaUpdateResult {
|
||||
@ -122,16 +120,22 @@ pub enum FindDatasetError {
|
||||
NotImplemented,
|
||||
}
|
||||
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.
|
||||
///
|
||||
///
|
||||
/// 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> {
|
||||
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);
|
||||
|
||||
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 {
|
||||
Err(FindDatasetError::NoDataset(common_path))
|
||||
} 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 {
|
||||
Err(FindDatasetError::SomeNotInDataset)
|
||||
} else {
|
||||
Ok(d.to_path_buf())
|
||||
}
|
||||
|
||||
} else { // ds_dirs.len() > 1
|
||||
} else {
|
||||
// ds_dirs.len() > 1
|
||||
Err(FindDatasetError::MultipleDatasets {
|
||||
datasets: ds_dirs.into_iter().collect(),
|
||||
some_paths_not_in_dataset: some_not_in_ds,
|
||||
|
||||
@ -9,6 +9,10 @@ pub enum 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)
|
||||
}
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@ -63,8 +63,10 @@ fn main() {
|
||||
Err(nancy::db::FindDatasetError::NoDataset(path)) => {
|
||||
log::info!("No dataset at or above nearest ancestor path: {:?}", path);
|
||||
if !initialize {
|
||||
log::error!("Refusing to initialize a new dataset at {path:?}. \
|
||||
Pass the -i or --initialize flag to request initialization.");
|
||||
log::error!(
|
||||
"Refusing to initialize a new dataset at {path:?}. \
|
||||
Pass the -i or --initialize flag to request initialization."
|
||||
);
|
||||
process::exit(1);
|
||||
}
|
||||
let dbpath = &path.join("nancy.db");
|
||||
@ -82,10 +84,7 @@ fn main() {
|
||||
c.pragma_update(None, "foreign_keys", &"ON").unwrap();
|
||||
match nancy::db::init(&mut c) {
|
||||
Err(e) => {
|
||||
log::error!(
|
||||
"Encountered error in initializing schema: {:?}",
|
||||
e
|
||||
);
|
||||
log::error!("Encountered error in initializing schema: {:?}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
Ok(dataset_uuid) => {
|
||||
@ -109,11 +108,11 @@ fn main() {
|
||||
}
|
||||
}
|
||||
c
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Could not determine dataset directory: {:?}", e);
|
||||
process::exit(1);
|
||||
},
|
||||
}
|
||||
Ok(path) => {
|
||||
// existing
|
||||
log::info!("Found existing dataset at path: {:?}", path);
|
||||
@ -142,7 +141,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
c
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = nancy::program::with_program(&mut conn, "RECORD", message, |prog| {
|
||||
|
||||
@ -2,7 +2,7 @@ use log;
|
||||
use rusqlite::{Connection, Error as RSQLError, Transaction};
|
||||
extern crate derive_more;
|
||||
use derive_more::From;
|
||||
use uuid::{Uuid};
|
||||
use uuid::Uuid;
|
||||
|
||||
use std::time::{Instant, SystemTime};
|
||||
|
||||
@ -38,8 +38,8 @@ impl Program {
|
||||
}
|
||||
}
|
||||
pub fn perform_task<R, F>(self: &Program, inputs: &[TaskInput], f: F) -> R
|
||||
where
|
||||
F: FnOnce(&Task) -> R
|
||||
where
|
||||
F: FnOnce(&Task) -> R,
|
||||
{
|
||||
let start = Instant::now();
|
||||
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);
|
||||
|
||||
log::info!(target: log_target, "Preparing program {} ({})", name, message);
|
||||
log::info!(
|
||||
target: log_target,
|
||||
"Preparing program {} ({})",
|
||||
name,
|
||||
message
|
||||
);
|
||||
|
||||
// start transaction
|
||||
let txres = conn.transaction();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user