eh: replaced the manual directory traversal with walkdir
Some checks failed
Rust / build (push) Has been cancelled
Some checks failed
Rust / build (push) Has been cancelled
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I537cc9b6ab7110c47f9884f1793b07596a6a6964
This commit is contained in:
parent
91e5063bc8
commit
185403436b
5 changed files with 50 additions and 19 deletions
29
Cargo.lock
generated
29
Cargo.lock
generated
|
|
@ -79,6 +79,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"walkdir",
|
||||||
"yansi",
|
"yansi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -174,6 +175,15 @@ version = "0.8.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "same-file"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sharded-slab"
|
name = "sharded-slab"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
|
|
@ -298,6 +308,25 @@ version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "walkdir"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||||
|
dependencies = [
|
||||||
|
"same-file",
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-link"
|
name = "windows-link"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ regex = "1.12.2"
|
||||||
thiserror = "2.0.17"
|
thiserror = "2.0.17"
|
||||||
tracing = "0.1.41"
|
tracing = "0.1.41"
|
||||||
tracing-subscriber = "0.3.20"
|
tracing-subscriber = "0.3.20"
|
||||||
|
walkdir = "2.5.0"
|
||||||
yansi = "1.0.1"
|
yansi = "1.0.1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ authors.workspace = true
|
||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "eh"
|
|
||||||
crate-type = [ "lib" ]
|
crate-type = [ "lib" ]
|
||||||
|
name = "eh"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap.workspace = true
|
clap.workspace = true
|
||||||
|
|
@ -16,4 +16,5 @@ regex.workspace = true
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber.workspace = true
|
||||||
|
walkdir.workspace = true
|
||||||
yansi.workspace = true
|
yansi.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
use walkdir::WalkDir;
|
||||||
use yansi::Paint;
|
use yansi::Paint;
|
||||||
|
|
||||||
pub trait HashExtractor {
|
pub trait HashExtractor {
|
||||||
|
|
@ -54,21 +55,20 @@ impl NixFileFixer for DefaultNixFileFixer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_nix_files(&self) -> Result<Vec<PathBuf>> {
|
fn find_nix_files(&self) -> Result<Vec<PathBuf>> {
|
||||||
let mut files = Vec::new();
|
let files: Vec<PathBuf> = WalkDir::new(".")
|
||||||
let mut stack = vec![PathBuf::from(".")];
|
.into_iter()
|
||||||
while let Some(dir) = stack.pop() {
|
.filter_map(|entry| entry.ok())
|
||||||
let entries = fs::read_dir(&dir)?;
|
.filter(|entry| {
|
||||||
for entry in entries.flatten() {
|
entry.file_type().is_file()
|
||||||
let path = entry.path();
|
&& entry
|
||||||
if path.is_dir() {
|
.path()
|
||||||
stack.push(path);
|
.extension()
|
||||||
} else if let Some(ext) = path.extension()
|
.map(|ext| ext.eq_ignore_ascii_case("nix"))
|
||||||
&& ext.eq_ignore_ascii_case("nix")
|
.unwrap_or(false)
|
||||||
{
|
})
|
||||||
files.push(path);
|
.map(|entry| entry.path().to_path_buf())
|
||||||
}
|
.collect();
|
||||||
}
|
|
||||||
}
|
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
Err(EhError::NoNixFilesFound)
|
Err(EhError::NoNixFilesFound)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue