Fix seed finder

This commit is contained in:
Olivier 'reivilibre' 2022-03-20 21:57:04 +00:00
parent 173b8a4de1
commit f6efc7a4e5
1 changed files with 18 additions and 2 deletions

View File

@ -1,11 +1,13 @@
use clap::Parser; use clap::Parser;
use std::borrow::{Borrow, BorrowMut}; use std::borrow::{Borrow, BorrowMut};
use std::ffi::OsStr;
use env_logger::Env; use env_logger::Env;
use anyhow::{anyhow, bail, Context}; use anyhow::{anyhow, bail, Context};
use colour::{dark_green_ln, dark_yellow, green, yellow_ln}; use colour::{dark_green_ln, dark_yellow, green, yellow_ln};
use log::warn;
use reqwest::{Client, Url}; use reqwest::{Client, Url};
use std::path::PathBuf; use std::path::PathBuf;
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -56,6 +58,9 @@ pub async fn main() -> anyhow::Result<()> {
let (seed_tx, seed_rx) = mpsc::channel(128); let (seed_tx, seed_rx) = mpsc::channel(128);
let seed_files = find_seed_files(config.seed_dir.clone()).await?; let seed_files = find_seed_files(config.seed_dir.clone()).await?;
eprintln!("{:?}", seed_files);
tokio::spawn(async move { tokio::spawn(async move {
seed_loader(seed_files, &seed_tx).await?; seed_loader(seed_files, &seed_tx).await?;
@ -155,10 +160,21 @@ async fn find_seed_files(seed_dir: PathBuf) -> anyhow::Result<Vec<PathBuf>> {
while let Some(entry) = dir.next_entry().await? { while let Some(entry) = dir.next_entry().await? {
let path = entry.path(); 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; continue;
} }
if path.ends_with(".seed") { if file_name.ends_with(".seed") {
seedfiles.push(path); seedfiles.push(path);
continue; continue;
} }