Skip to content

Commit

Permalink
Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kimono-koans committed Sep 1, 2024
1 parent 15cbc7c commit af9500a
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 130 deletions.
4 changes: 3 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
edition = "2021"
imports_layout = "HorizontalVertical"
imports_granularity = "Module"
group_imports = "One"
group_imports = "One"
indent_style = "Block"
reorder_imports = true
3 changes: 1 addition & 2 deletions src/background/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ use std::fs::read_dir;
use std::os::unix::fs::MetadataExt;
use std::path::Path;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::sync::LazyLock;
use std::sync::{Arc, LazyLock};

static OPT_REQUESTED_DIR_DEV: LazyLock<u64> = LazyLock::new(|| {
GLOBAL_CONFIG
Expand Down
106 changes: 62 additions & 44 deletions src/config/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

use crate::config::install_hot_keys::install_hot_keys;
use crate::data::filesystem_info::FilesystemInfo;
use crate::data::paths::PathDeconstruction;
use crate::data::paths::{PathData, ZfsSnapPathGuard};
use crate::data::paths::{PathData, PathDeconstruction, ZfsSnapPathGuard};
use crate::library::results::{HttmError, HttmResult};
use crate::library::utility::{pwd, HttmIsDir};
use crate::lookup::file_mounts::MountDisplay;
Expand All @@ -27,12 +26,11 @@ use crate::ROOT_DIRECTORY;
use clap::parser::ValuesRef;
use clap::{crate_name, crate_version, Arg, ArgAction, ArgMatches};
use indicatif::ProgressBar;
use rayon::iter::ParallelBridge;
use rayon::iter::{ParallelBridge, ParallelIterator};
use std::io::Read;
use std::ops::Index;
use std::path::{Path, PathBuf};
use time::UtcOffset;
use rayon::iter::ParallelIterator;

#[derive(Debug, Clone)]
pub enum ExecMode {
Expand Down Expand Up @@ -642,28 +640,34 @@ impl Config {

// obtain a map of datasets, a map of snapshot directories, and possibly a map of
// alternate filesystems and map of aliases if the user requests
let mut opt_map_aliases: Option<Vec<String>> = matches.get_raw("MAP_ALIASES").map(|aliases| {
aliases
.map(|os_str| os_str.to_string_lossy().to_string())
.collect()
});

let opt_alt_store: Option<FilesystemType> = match matches.get_one::<String>("ALT_STORE").map(|inner| inner.as_str()) {
let mut opt_map_aliases: Option<Vec<String>> =
matches.get_raw("MAP_ALIASES").map(|aliases| {
aliases
.map(|os_str| os_str.to_string_lossy().to_string())
.collect()
});

let opt_alt_store: Option<FilesystemType> = match matches
.get_one::<String>("ALT_STORE")
.map(|inner| inner.as_str())
{
Some("timemachine") => Some(FilesystemType::Apfs),
Some("restic") => Some(FilesystemType::Restic(None)),
_ => None
_ => None,
};

if opt_alt_store.is_some() && opt_map_aliases.is_some() {
eprintln!("WARN: httm has disabled any MAP_ALIASES in preference to an ALT_STORE specified.");
eprintln!(
"WARN: httm has disabled any MAP_ALIASES in preference to an ALT_STORE specified."
);
opt_map_aliases = None;
}

let opt_alt_replicated = matches.get_flag("ALT_REPLICATED");
let opt_remote_dir = matches.get_one::<String>("REMOTE_DIR").cloned();
let opt_local_dir = matches.get_one::<String>("LOCAL_DIR").cloned();

let pwd_clone= pwd.clone();
let pwd_clone = pwd.clone();

let fs_handle = std::thread::spawn(move || {
FilesystemInfo::new(
Expand All @@ -673,7 +677,7 @@ impl Config {
opt_local_dir,
opt_map_aliases,
opt_alt_store,
pwd_clone
pwd_clone,
)
});

Expand Down Expand Up @@ -716,7 +720,10 @@ impl Config {
let opt_no_clones =
matches.get_flag("NO_CLONES") || std::env::var_os("HTTM_NO_CLONE").is_some();

let opt_last_snap = match matches.get_one::<String>("LAST_SNAP").map(|inner| inner.as_str()) {
let opt_last_snap = match matches
.get_one::<String>("LAST_SNAP")
.map(|inner| inner.as_str())
{
Some("" | "any") => Some(LastSnapMode::Any),
Some("none" | "without") => Some(LastSnapMode::Without),
Some("ditto") => Some(LastSnapMode::DittoOnly),
Expand All @@ -725,7 +732,10 @@ impl Config {
_ => None,
};

let opt_num_versions = match matches.get_one::<String>("NUM_VERSIONS").map(|inner| inner.as_str()) {
let opt_num_versions = match matches
.get_one::<String>("NUM_VERSIONS")
.map(|inner| inner.as_str())
{
Some("" | "all") => Some(NumVersionsMode::AllNumerals),
Some("graph") => Some(NumVersionsMode::AllGraph),
Some("single") => Some(NumVersionsMode::SingleAll),
Expand All @@ -741,20 +751,29 @@ impl Config {
return Err(HttmError::new("The NUM_VERSIONS graph mode and the RAW or ZEROS display modes are an invalid combination.").into());
}

let opt_mount_display = match matches.get_one::<String>("FILE_MOUNT").map(|inner| inner.as_str()) {
let opt_mount_display = match matches
.get_one::<String>("FILE_MOUNT")
.map(|inner| inner.as_str())
{
Some("" | "mount" | "target" | "directory") => Some(MountDisplay::Target),
Some("source" | "device" | "dataset") => Some(MountDisplay::Source),
Some("relative-path" | "relative" | "relpath") => Some(MountDisplay::RelativePath),
_ => None,
};

let opt_preview = match matches.get_one::<String>("PREVIEW").map(|inner| inner.as_str()) {
let opt_preview = match matches
.get_one::<String>("PREVIEW")
.map(|inner| inner.as_str())
{
Some("" | "default") => Some("default".to_owned()),
Some(user_defined) => Some(user_defined.to_string()),
None => None,
};

let mut opt_deleted_mode = match matches.get_one::<String>("DELETED").map(|inner| inner.as_str()) {
let mut opt_deleted_mode = match matches
.get_one::<String>("DELETED")
.map(|inner| inner.as_str())
{
Some("" | "all") => Some(DeletedMode::All),
Some("single") => Some(DeletedMode::DepthOfOne),
Some("only") => Some(DeletedMode::Only),
Expand All @@ -763,25 +782,22 @@ impl Config {

let opt_select_mode = matches.get_one::<String>("SELECT");
let opt_restore_mode = matches.get_one::<String>("RESTORE");

let opt_interactive_mode = if let Some(var_restore_mode) = opt_restore_mode {
let mut restore_mode = var_restore_mode.to_string();

if let Ok(env_restore_mode) = std::env::var("HTTM_RESTORE_MODE")
{

if let Ok(env_restore_mode) = std::env::var("HTTM_RESTORE_MODE") {
restore_mode = env_restore_mode;
}

match restore_mode.as_str() {
"guard" => Some(InteractiveMode::Restore(RestoreMode::Overwrite(
RestoreSnapGuard::Guarded,
))),
"overwrite" | "yolo" => Some(InteractiveMode::Restore(
RestoreMode::Overwrite(RestoreSnapGuard::NotGuarded),
)),
"copy-and-preserve" => {
Some(InteractiveMode::Restore(RestoreMode::CopyAndPreserve))
}
"overwrite" | "yolo" => Some(InteractiveMode::Restore(RestoreMode::Overwrite(
RestoreSnapGuard::NotGuarded,
))),
"copy-and-preserve" => Some(InteractiveMode::Restore(RestoreMode::CopyAndPreserve)),
_ => Some(InteractiveMode::Restore(RestoreMode::CopyOnly)),
}
} else if opt_select_mode.is_some() || opt_preview.is_some() {
Expand All @@ -798,8 +814,11 @@ impl Config {
None
};

let dedup_by = match matches.get_one::<String>("DEDUP_BY").map(|inner| inner.as_str()) {
_ if matches.get_flag("PRUNE") => DedupBy::Disable,
let dedup_by = match matches
.get_one::<String>("DEDUP_BY")
.map(|inner| inner.as_str())
{
_ if matches.get_flag("PRUNE") => DedupBy::Disable,
Some("all" | "no-filter" | "disable") => DedupBy::Disable,
Some("contents") => DedupBy::Contents,
Some("metadata" | _) => DedupBy::Metadata,
Expand Down Expand Up @@ -847,22 +866,19 @@ impl Config {
}

match matches.get_one::<String>("LIST_SNAPS") {
Some(value) if !value.is_empty() => {
Some(Self::snap_filters(value, select_mode)?)
},
_ => {
Some(ListSnapsFilters {
select_mode,
omit_num_snaps: 0usize,
name_filters: None,
})
}
Some(value) if !value.is_empty() => Some(Self::snap_filters(value, select_mode)?),
_ => Some(ListSnapsFilters {
select_mode,
omit_num_snaps: 0usize,
name_filters: None,
}),
}
} else {
None
};

let mut exec_mode = if let Some(full_snap_name) = matches.get_one::<String>("ROLL_FORWARD") {
let mut exec_mode = if let Some(full_snap_name) = matches.get_one::<String>("ROLL_FORWARD")
{
ExecMode::RollForward(full_snap_name.to_string())
} else if let Some(num_versions_mode) = opt_num_versions {
ExecMode::NumVersions(num_versions_mode)
Expand Down Expand Up @@ -939,7 +955,9 @@ impl Config {
);
}

let dataset_collection = fs_handle.join().expect("Background thread collecting filesystem info has panicked")?;
let dataset_collection = fs_handle
.join()
.expect("Background thread collecting filesystem info has panicked")?;

let config = Config {
paths,
Expand Down
9 changes: 3 additions & 6 deletions src/data/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
// For the full copyright and license information, please view the LICENSE file
// that was distributed with this source code.

use super::selection::SelectionCandidate;
use crate::background::recursive::PathProvenance;
use crate::config::generate::{DedupBy, PrintMode};
use crate::library::file_ops::HashFileContents;
use crate::library::results::{HttmError, HttmResult};
use crate::library::utility::{date_string, display_human_size, DateFormat};
use crate::parse::mounts::FilesystemType;
use crate::parse::mounts::MaxLen;
use crate::parse::mounts::{FilesystemType, MaxLen};
use crate::{GLOBAL_CONFIG, ZFS_SNAPSHOT_DIRECTORY};
use realpath_ext::{realpath, RealpathFlags};
use serde::ser::SerializeStruct;
Expand All @@ -31,12 +31,9 @@ use std::ffi::OsStr;
use std::fs::{symlink_metadata, DirEntry, FileType, Metadata};
use std::hash::Hash;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use std::sync::OnceLock;
use std::sync::{LazyLock, OnceLock};
use std::time::SystemTime;

use super::selection::SelectionCandidate;

static DATASET_MAX_LEN: LazyLock<usize> =
LazyLock::new(|| GLOBAL_CONFIG.dataset_collection.map_of_datasets.max_len());

Expand Down
6 changes: 2 additions & 4 deletions src/data/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ use crate::display_versions::wrapper::VersionsDisplayWrapper;
use crate::library::results::HttmResult;
use crate::library::utility::paint_string;
use crate::lookup::versions::Versions;
use crate::VersionsMap;
use crate::{Config, ExecMode, GLOBAL_CONFIG};
use crate::{Config, ExecMode, VersionsMap, GLOBAL_CONFIG};
use lscolors::Colorable;
use skim::prelude::*;
use std::fs::FileType;
use std::path::Path;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;

// these represent the items ready for selection and preview
Expand Down
3 changes: 1 addition & 2 deletions src/display_map/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
// that was distributed with this source code.

use crate::config::generate::PrintMode;
use crate::data::paths::PathData;
use crate::data::paths::ZfsSnapPathGuard;
use crate::data::paths::{PathData, ZfsSnapPathGuard};
use crate::display_versions::format::{NOT_SO_PRETTY_FIXED_WIDTH_PADDING, QUOTATION_MARKS_LEN};
use crate::library::utility::delimiter;
use crate::{MountsForFiles, SnapNameMap, VersionsMap, GLOBAL_CONFIG};
Expand Down
6 changes: 5 additions & 1 deletion src/display_versions/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
use crate::config::generate::{BulkExclusion, Config, PrintMode};
use crate::data::paths::{PathData, PHANTOM_DATE, PHANTOM_SIZE};
use crate::library::utility::{
date_string, delimiter, display_human_size, paint_string, DateFormat,
date_string,
delimiter,
display_human_size,
paint_string,
DateFormat,
};
use crate::lookup::versions::ProximateDatasetAndOptAlts;
use crate::parse::mounts::IsFilterDir;
Expand Down
3 changes: 1 addition & 2 deletions src/interactive/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
// that was distributed with this source code.

use crate::config::generate::ListSnapsFilters;
use crate::interactive::view_mode::MultiSelect;
use crate::interactive::view_mode::ViewMode;
use crate::interactive::view_mode::{MultiSelect, ViewMode};
use crate::library::results::{HttmError, HttmResult};
use crate::lookup::snap_names::SnapNameMap;
use crate::lookup::versions::VersionsMap;
Expand Down
3 changes: 1 addition & 2 deletions src/interactive/view_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

use crate::interactive::preview::PreviewSelection;
use crate::library::results::HttmError;
use crate::HttmResult;
use crate::GLOBAL_CONFIG;
use crate::{HttmResult, GLOBAL_CONFIG};
use skim::prelude::*;
use std::io::Cursor;

Expand Down
7 changes: 2 additions & 5 deletions src/library/diff_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@
// SOFTWARE.

use crate::data::paths::PathData;
use crate::library::results::HttmError;
use crate::library::results::HttmResult;
use crate::library::results::{HttmError, HttmResult};
use crate::zfs::run_command::RunZFSCommand;
use crate::ExecMode;
use crate::GLOBAL_CONFIG;
use crate::IN_BUFFER_SIZE;
use crate::{ExecMode, GLOBAL_CONFIG, IN_BUFFER_SIZE};
use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Seek, SeekFrom, Write};
use std::os::fd::{AsFd, BorrowedFd};
Expand Down
19 changes: 5 additions & 14 deletions src/library/file_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@
// For the full copyright and license information, please view the LICENSE file
// that was distributed with this source code.

use crate::data::paths::PathData;
use crate::data::paths::PathDeconstruction;
use crate::data::paths::{PathData, PathDeconstruction};
use crate::library::diff_copy::HttmCopy;
use crate::library::results::{HttmError, HttmResult};
use crate::GLOBAL_CONFIG;
use crate::IN_BUFFER_SIZE;
use crate::{GLOBAL_CONFIG, IN_BUFFER_SIZE};
use nix::sys::stat::SFlag;
use nu_ansi_term::Color::{Blue, Red};
use std::os::unix::fs::chown;
use std::os::unix::fs::FileTypeExt;
use std::os::unix::fs::MetadataExt;

use std::fs::{create_dir_all, read_dir, set_permissions};
use std::iter::Iterator;
use std::os::unix::fs::{chown, FileTypeExt, MetadataExt};
use std::path::Path;

const CHAR_KIND: SFlag = nix::sys::stat::SFlag::S_IFCHR;
Expand Down Expand Up @@ -290,13 +285,9 @@ impl Remove {
}
}

use std::hash::Hash;
use std::hash::Hasher;
use std::io::BufRead;
use std::io::BufReader;
use std::io::ErrorKind;

use super::utility::is_metadata_same;
use std::hash::{Hash, Hasher};
use std::io::{BufRead, BufReader, ErrorKind};

pub struct HashFileContents<'a> {
inner: &'a Path,
Expand Down
Loading

0 comments on commit af9500a

Please sign in to comment.