Skip to content

Commit 18ef626

Browse files
juuz0kelson42
authored andcommitted
fixup! Introduce Manager::addBooksFromDirectory()
1 parent a3780f9 commit 18ef626

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

include/manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ class Manager
156156
const bool checkMetaData = false);
157157

158158
/**
159-
* Add books from a directory into the libary.
159+
* Add all books from the directory tree into the library.
160160
*
161161
* @param path The path of the directory to scan.
162-
* @param path If the function should stop for an invalid file.
162+
* @param skipInvalid If the function should stop for an invalid file.
163163
* @param verboseFlag Verbose logs flag.
164164
*/
165165
void addBooksFromDirectory(const std::string& path,

src/manager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,15 @@ void Manager::addBooksFromDirectory(const std::string& path,
263263
std::set<std::string> iteratedDirs;
264264
std::queue<std::string> dirQueue;
265265
dirQueue.push(fs::absolute(path).u8string());
266+
int totalBooksAdded = 0;
267+
if (verboseFlag)
268+
std::cout << "Starting BFS traversal at root directory: " << dirQueue.front() << std::endl;
266269

267270
while (!dirQueue.empty()) {
268271
const auto currentPath = dirQueue.front();
269272
dirQueue.pop();
270273
if (verboseFlag)
271-
std::cout << "Iterating over directory: " << currentPath << std::endl;
274+
std::cout << "Visiting directory: " << currentPath << std::endl;
272275
for (const auto& dirEntry : fs::directory_iterator(currentPath)) {
273276
auto resolvedPath = dirEntry.path();
274277
if (fs::is_symlink(dirEntry)) {
@@ -287,13 +290,17 @@ void Manager::addBooksFromDirectory(const std::string& path,
287290
else {
288291
throw std::runtime_error("Unable to add file: " + pathString + " into the library.");
289292
}
293+
} else if (verboseFlag) {
294+
std::cout << "Added " << pathString << " into the library." << std::endl;
295+
totalBooksAdded++;
290296
}
291297
}
292298
}
293-
if (verboseFlag)
294-
std::cout << "Completed iterating over directory: " << currentPath << std::endl;
295299
iteratedDirs.insert(currentPath);
296300
}
301+
302+
if (verboseFlag)
303+
std::cout << "Traversal completed. Total books added: " << totalBooksAdded << std::endl;
297304
}
298305

299306
bool Manager::readBookFromPath(const std::string& path, kiwix::Book* book)

0 commit comments

Comments
 (0)