diff --git a/include/manager.h b/include/manager.h index 4b66e1d2..fe1083ae 100644 --- a/include/manager.h +++ b/include/manager.h @@ -156,10 +156,10 @@ class Manager const bool checkMetaData = false); /** - * Add books from a directory into the libary. + * Add all books from the directory tree into the library. * * @param path The path of the directory to scan. - * @param path If the function should stop for an invalid file. + * @param skipInvalid If the function should stop for an invalid file. * @param verboseFlag Verbose logs flag. */ void addBooksFromDirectory(const std::string& path, diff --git a/src/manager.cpp b/src/manager.cpp index 0c254443..75bc4074 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -263,12 +263,15 @@ void Manager::addBooksFromDirectory(const std::string& path, std::set iteratedDirs; std::queue dirQueue; dirQueue.push(fs::absolute(path).u8string()); + int totalBooksAdded = 0; + if (verboseFlag) + std::cout << "Starting BFS traversal at root directory: " << dirQueue.front() << std::endl; while (!dirQueue.empty()) { const auto currentPath = dirQueue.front(); dirQueue.pop(); if (verboseFlag) - std::cout << "Iterating over directory: " << currentPath << std::endl; + std::cout << "Visiting directory: " << currentPath << std::endl; for (const auto& dirEntry : fs::directory_iterator(currentPath)) { auto resolvedPath = dirEntry.path(); if (fs::is_symlink(dirEntry)) { @@ -287,13 +290,17 @@ void Manager::addBooksFromDirectory(const std::string& path, else { throw std::runtime_error("Unable to add file: " + pathString + " into the library."); } + } else if (verboseFlag) { + std::cout << "Added " << pathString << " into the library." << std::endl; + totalBooksAdded++; } } } - if (verboseFlag) - std::cout << "Completed iterating over directory: " << currentPath << std::endl; iteratedDirs.insert(currentPath); } + + if (verboseFlag) + std::cout << "Traversal completed. Total books added: " << totalBooksAdded << std::endl; } bool Manager::readBookFromPath(const std::string& path, kiwix::Book* book)