mirror of
https://gitlab.com/news-flash/article_scraper.git
synced 2025-07-07 16:15:32 +02:00
simplify iterating over dir
This commit is contained in:
parent
309a60c5d0
commit
37d317ad86
1 changed files with 17 additions and 7 deletions
|
@ -43,13 +43,11 @@ impl ConfigCollection {
|
|||
}
|
||||
|
||||
if let Ok(mut dir) = tokio::fs::read_dir(directory).await {
|
||||
while let Ok(entry) = dir.next_entry().await {
|
||||
if let Some(entry) = entry {
|
||||
if Util::check_extension(&entry, "txt") {
|
||||
if let Ok(config) = ConfigEntry::parse_path(&entry.path()).await {
|
||||
let file_name = entry.file_name().to_string_lossy().into_owned();
|
||||
user_entries.insert(file_name, config);
|
||||
}
|
||||
while let Ok(Some(entry)) = dir.next_entry().await {
|
||||
if Util::check_extension(&entry, "txt") {
|
||||
if let Ok(config) = ConfigEntry::parse_path(&entry.path()).await {
|
||||
let file_name = entry.file_name().to_string_lossy().into_owned();
|
||||
user_entries.insert(file_name, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,3 +68,15 @@ impl ConfigCollection {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
use super::ConfigCollection;
|
||||
|
||||
#[tokio::test]
|
||||
async fn read_dir() {
|
||||
let path = Path::new("~/.local/share/news-flash/ftr-site-config");
|
||||
let _collection = ConfigCollection::parse(Some(path)).await;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue