Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ class Library: public std::enable_shared_from_this<Library>
std::string getBestTargetBookId(const std::string& bookName, const std::string& preferedFlavour="", const std::string& minDate="") const;

// XXX: This is a non-thread-safe operation
const Book& getBookById(const std::string& id) const;
Book getBookById(const std::string& id) const;
// XXX: This is a non-thread-safe operation
const Book& getBookByPath(const std::string& path) const;
Book getBookByPath(const std::string& path) const;

Book getBookByIdThreadSafe(const std::string& id) const;

Expand Down
2 changes: 1 addition & 1 deletion src/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ std::shared_ptr<Download> Downloader::getDownload(const std::string& did)
return m_knownDownloads[gid];
}
}
throw e;
throw;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ std::string Library::getBestFromBookCollection(BookIdCollection books, const Boo
}

sort(books, DATE, false);
stable_sort(books.begin(), books.end(), [&](const std::string& bookId1, const std::string& bookId2) {
const auto& book1 = getBookById(bookId1);
const auto& book2 = getBookById(bookId2);
std::stable_sort(books.begin(), books.end(), [&](const std::string& bookId1, const std::string& bookId2) {
const auto book1 = getBookById(bookId1);
const auto book2 = getBookById(bookId2);
bool same_flavour1 = book1.getFlavour() == bookmark.getBookFlavour();
bool same_flavour2 = book2.getFlavour() == bookmark.getBookFlavour();
// return True if bookId1 is before bookId2, ie if same_flavour1 and not same_flavour2
Expand All @@ -215,7 +215,7 @@ std::string Library::getBestFromBookCollection(BookIdCollection books, const Boo
return books[0];
} else {
for (const auto& bookId: books) {
const auto& book = getBookById(bookId);
const auto book = getBookById(bookId);
if (book.getDate() >= bookmark.getDate()) {
return bookId;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ uint32_t Library::removeBooksNotUpdatedSince(Revision libraryRevision)
return countOfRemovedBooks;
}

const Book& Library::getBookById(const std::string& id) const
Book Library::getBookById(const std::string& id) const
{
// XXX: Doesn't make sense to lock this operation since it cannot
// XXX: guarantee thread-safety because of its return type
Expand All @@ -374,7 +374,7 @@ Book Library::getBookByIdThreadSafe(const std::string& id) const
return getBookById(id);
}

const Book& Library::getBookByPath(const std::string& path) const
Book Library::getBookByPath(const std::string& path) const
{
// XXX: Doesn't make sense to lock this operation since it cannot
// XXX: guarantee thread-safety because of its return type
Expand Down
4 changes: 2 additions & 2 deletions src/name_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace kiwix {

HumanReadableNameMapper::HumanReadableNameMapper(const kiwix::Library& library, bool withAlias) {
for (auto& bookId: library.filter(kiwix::Filter())) {
auto& currentBook = library.getBookById(bookId);
auto currentBook = library.getBookById(bookId);
auto bookName = currentBook.getHumanReadableIdFromPath();
m_idToName[bookId] = bookName;
mapName(library, bookName, bookId);
Expand All @@ -45,7 +45,7 @@ void HumanReadableNameMapper::mapName(const Library& library, std::string name,
if (m_nameToId.find(name) == m_nameToId.end()) {
m_nameToId[name] = bookId;
} else {
const auto& currentBook = library.getBookById(bookId);
const auto currentBook = library.getBookById(bookId);
auto alreadyPresentPath = library.getBookById(m_nameToId[name]).getPath();
std::cerr << "Path collision: '" << alreadyPresentPath
<< "' and '" << currentBook.getPath()
Expand Down
4 changes: 1 addition & 3 deletions src/server/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,7 @@ HTTP500Response::HTTP500Response(const RequestContext& request,
std::unique_ptr<Response> Response::build_416(size_t resourceLength)
{
auto response = Response::build();
// [FIXME] (compile with recent enough version of libmicrohttpd)
// response->set_code(MHD_HTTP_RANGE_NOT_SATISFIABLE);
response->set_code(416);
response->set_code(MHD_HTTP_RANGE_NOT_SATISFIABLE);
std::ostringstream oss;
oss << "bytes */" << resourceLength;
response->add_header(MHD_HTTP_HEADER_CONTENT_RANGE, oss.str());
Expand Down
5 changes: 5 additions & 0 deletions src/tools/networkTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,18 @@ std::map<std::string, IpAddress> getNetworkInterfacesWin() {
// Successively allocate the required memory until GetAdaptersAddresses does not
// results in ERROR_BUFFER_OVERFLOW for a maximum of max_tries
do{
if (interfacesHead) {
free(interfacesHead);
interfacesHead = NULL;
}
interfacesHead = (IP_ADAPTER_ADDRESSES *) malloc(outBufLen);
if (interfacesHead == NULL) {
std::cerr << "Memory allocation failed for IP_ADAPTER_ADDRESSES struct" << std::endl;
return interfaces;
}

dwRetVal = GetAdaptersAddresses(family, flags, NULL, interfacesHead, &outBufLen);
Iterations++;
} while ((dwRetVal == ERROR_BUFFER_OVERFLOW) && (Iterations < max_tries));

if (dwRetVal == NO_ERROR) {
Expand Down
5 changes: 2 additions & 3 deletions src/tools/stringTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ std::string kiwix::removeAccents(const std::string& text)
loadICUExternalTables();
ucnv_setDefaultName("UTF-8");
UErrorCode status = U_ZERO_ERROR;
auto removeAccentsTrans = icu::Transliterator::createInstance(
"Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status);
std::unique_ptr<icu::Transliterator> removeAccentsTrans(icu::Transliterator::createInstance(
"Lower; NFD; [:M:] remove; NFC", UTRANS_FORWARD, status));
icu::UnicodeString ustring(text.c_str());
removeAccentsTrans->transliterate(ustring);
delete removeAccentsTrans;
std::string unaccentedText;
ustring.toUTF8String(unaccentedText);
return unaccentedText;
Expand Down
Loading