From 147af49eb86ad312864f57b541aaa354c46e2969 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Tue, 26 Apr 2022 21:44:25 +0200 Subject: [PATCH] Warn the user on duplicate folder names See #31 --- CHANGELOG.md | 5 ++++- src/ilias/folder.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fcde83..da36371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] - +### Added +- Display a warning if two or more courses/folders have the same name ([#31]) + ## [0.3.3] - 2022-03-21 ### Addded - `--all` flag to download all courses ([#30]) @@ -153,6 +155,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.1.0] - 2020-04-21 (undocumented) +[#31]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/31 [#30]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/30 [#28]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/pull/28 [#27]: https://github.com/FliegendeWurst/KIT-ILIAS-downloader/issues/27 diff --git a/src/ilias/folder.rs b/src/ilias/folder.rs index 962192a..92cbfb2 100644 --- a/src/ilias/folder.rs +++ b/src/ilias/folder.rs @@ -1,4 +1,4 @@ -use std::{path::Path, sync::Arc}; +use std::{path::Path, sync::Arc, collections::HashSet}; use anyhow::{Context, Result}; @@ -20,11 +20,17 @@ pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { .context("failed to write folder page html")?; } } + let mut names = HashSet::new(); for item in content.0 { let item = item?; - let path = path.join(file_escape( + let item_name = file_escape( ilias.course_names.get(item.name()).map(|x| &**x).unwrap_or(item.name()), - )); + ); + if names.contains(&item_name) { + warning!(format => "folder {} contains duplicated folder {:?}", path.display(), item_name); + } + names.insert(item_name.clone()); + let path = path.join(item_name); let ilias = Arc::clone(&ilias); spawn(process_gracefully(ilias, path, item)); }