From 6af3dbf6b11e5f95b76224e67b2b5ed89449f958 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 23 Oct 2014 19:43:23 +0100 Subject: [PATCH] Fixed API loot_load_lists bugs. The userlist path was being ignored, and the masterlist loaded again as the userlist. The function now errors if either of the given paths does not exist. --- src/api/api.cpp | 8 +++++++- src/tests/api/api.h | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 55a56c52..6f5c789d 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -303,6 +303,9 @@ LOOT_API unsigned int loot_load_lists(loot_db db, const char * const masterlistP // We don't want to update the masterlist too. temp.MetadataList::Load(masterlistPath); } + else { + return c_error(loot_error_path_not_found, std::string("The given masterlist path does not exist: ") + masterlistPath); + } } catch (std::exception& e) { return c_error(loot_error_parse_fail, e.what()); @@ -311,7 +314,10 @@ LOOT_API unsigned int loot_load_lists(loot_db db, const char * const masterlistP try { if (userlistPath != nullptr) { if (boost::filesystem::exists(userlistPath)) { - userTemp.Load(masterlistPath); + userTemp.Load(userlistPath); + } + else { + return c_error(loot_error_path_not_found, std::string("The given userlist path does not exist: ") + userlistPath); } } } diff --git a/src/tests/api/api.h b/src/tests/api/api.h index 9b3894f3..2d306a58 100644 --- a/src/tests/api/api.h +++ b/src/tests/api/api.h @@ -149,12 +149,13 @@ TEST_F(OblivionAPIOperationsTest, LoadLists) { EXPECT_EQ(loot_error_invalid_args, loot_load_lists(NULL, masterlistPath.string().c_str(), NULL)); EXPECT_EQ(loot_error_invalid_args, loot_load_lists(db, NULL, NULL)); + EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), NULL)); bool updated; ASSERT_EQ(loot_ok, loot_update_masterlist(db, masterlistPath.string().c_str(), "https://github.com/loot/oblivion.git", "master", &updated)); - EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), NULL)); - - ASSERT_NO_THROW(boost::filesystem::copy(masterlistPath, userlistPath)); EXPECT_EQ(loot_error_path_not_found, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str())); + + ASSERT_NO_THROW(boost::filesystem::copy(masterlistPath, userlistPath)); + EXPECT_EQ(loot_ok, loot_load_lists(db, masterlistPath.string().c_str(), userlistPath.string().c_str())); } TEST_F(OblivionAPIOperationsTest, EvalLists) {