Skip to content

Commit

Permalink
Replace dirs-next crate with etcetera crate
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarshgupta137 authored and sharkdp committed Jun 14, 2023
1 parent a0370aa commit 3ae0454
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 90 deletions.
91 changes: 21 additions & 70 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ctrlc = "3.2"
humantime = "2.1"
globset = "0.4"
anyhow = "1.0"
dirs-next = "2.0"
etcetera = "0.8"
normpath = "1.1.1"
crossbeam-channel = "0.5.8"
clap_complete = {version = "4.3.0", optional = true}
Expand Down
30 changes: 11 additions & 19 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{borrow::Cow, io::Write};

use anyhow::{anyhow, Result};
use crossbeam_channel::{bounded, Receiver, RecvTimeoutError, Sender};
use etcetera::BaseStrategy;
use ignore::overrides::OverrideBuilder;
use ignore::{self, WalkBuilder};
use regex::bytes::Regex;
Expand Down Expand Up @@ -89,26 +90,17 @@ pub fn scan(paths: &[PathBuf], patterns: Arc<Vec<Regex>>, config: Arc<Config>) -
}

if config.read_global_ignore {
#[cfg(target_os = "macos")]
let config_dir_op = std::env::var_os("XDG_CONFIG_HOME")
.map(PathBuf::from)
.filter(|p| p.is_absolute())
.or_else(|| dirs_next::home_dir().map(|d| d.join(".config")));

#[cfg(not(target_os = "macos"))]
let config_dir_op = dirs_next::config_dir();

if let Some(global_ignore_file) = config_dir_op
.map(|p| p.join("fd").join("ignore"))
.filter(|p| p.is_file())
{
let result = walker.add_ignore(global_ignore_file);
match result {
Some(ignore::Error::Partial(_)) => (),
Some(err) => {
print_error(format!("Malformed pattern in global ignore file. {}.", err));
if let Ok(basedirs) = etcetera::choose_base_strategy() {
let global_ignore_file = basedirs.config_dir().join("fd").join("ignore");
if global_ignore_file.is_file() {
let result = walker.add_ignore(global_ignore_file);
match result {
Some(ignore::Error::Partial(_)) => (),
Some(err) => {
print_error(format!("Malformed pattern in global ignore file. {}.", err));
}
None => (),
}
None => (),
}
}
}
Expand Down

0 comments on commit 3ae0454

Please sign in to comment.