Ensure the book's path is absolute.

We must use absolute path whenever possible.
Relative path has sense only related to the "interaction" with the user
(current directory, library location, ...).
This commit is contained in:
Matthieu Gautier
2019-02-07 15:22:33 +01:00
parent 432f9c30a3
commit 35d812a5f7

View File

@ -208,12 +208,16 @@ bool Manager::addBookFromPath(const std::string& pathToOpen,
bool Manager::readBookFromPath(const std::string& path, kiwix::Book* book)
{
std::string tmp_path = path;
if (isRelativePath(path)) {
tmp_path = computeAbsolutePath(getCurrentDirectory(), path);
}
try {
kiwix::Reader reader(path);
kiwix::Reader reader(tmp_path);
book->update(reader);
book->setPathValid(true);
} catch (const std::exception& e) {
std::cerr << "Invalid " << path << " : " << e.what() << std::endl;
std::cerr << "Invalid " << tmp_path << " : " << e.what() << std::endl;
book->setPathValid(false);
return false;
}