From f6efc7a4e59b34790b61d59909c641de89f80f5f Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 20 Mar 2022 21:57:04 +0000 Subject: [PATCH] Fix seed finder --- quickpeep_raker/src/bin/qp-seedrake.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/quickpeep_raker/src/bin/qp-seedrake.rs b/quickpeep_raker/src/bin/qp-seedrake.rs index cc7cca1..31ebe8f 100644 --- a/quickpeep_raker/src/bin/qp-seedrake.rs +++ b/quickpeep_raker/src/bin/qp-seedrake.rs @@ -1,11 +1,13 @@ use clap::Parser; use std::borrow::{Borrow, BorrowMut}; +use std::ffi::OsStr; use env_logger::Env; use anyhow::{anyhow, bail, Context}; use colour::{dark_green_ln, dark_yellow, green, yellow_ln}; +use log::warn; use reqwest::{Client, Url}; use std::path::PathBuf; use tokio::sync::mpsc; @@ -56,6 +58,9 @@ pub async fn main() -> anyhow::Result<()> { let (seed_tx, seed_rx) = mpsc::channel(128); let seed_files = find_seed_files(config.seed_dir.clone()).await?; + + eprintln!("{:?}", seed_files); + tokio::spawn(async move { seed_loader(seed_files, &seed_tx).await?; @@ -155,10 +160,21 @@ async fn find_seed_files(seed_dir: PathBuf) -> anyhow::Result> { while let Some(entry) = dir.next_entry().await? { let path = entry.path(); - if path.starts_with(".") { + let file_name = match path + .file_name() + .map(|osstr: &OsStr| osstr.to_str()) + .flatten() + { + None => { + warn!("Skipping non-UTF-8 name."); + continue; + } + Some(file_name) => file_name, + }; + if file_name.starts_with(".") { continue; } - if path.ends_with(".seed") { + if file_name.ends_with(".seed") { seedfiles.push(path); continue; }