diff --git a/SpiceQL/src/inventoryimpl.cpp b/SpiceQL/src/inventoryimpl.cpp index c41c0b6..71d17b6 100644 --- a/SpiceQL/src/inventoryimpl.cpp +++ b/SpiceQL/src/inventoryimpl.cpp @@ -152,7 +152,7 @@ namespace SpiceQL { m_required_kernels.load(lsk_json); for (auto &[mission, kernels] : json_kernels.items()) { - fmt::print("mission: {}\n", mission); + SPDLOG_TRACE("MISSION: {}", mission); json sclk_json = getLatestKernels(config[mission].getRecursive("sclk")); SPDLOG_TRACE("{} SCLKs: {}", mission, sclk_json.dump(4)); diff --git a/SpiceQL/src/query.cpp b/SpiceQL/src/query.cpp index b6a74b8..efa3c50 100644 --- a/SpiceQL/src/query.cpp +++ b/SpiceQL/src/query.cpp @@ -70,6 +70,14 @@ namespace SpiceQL { } } + // Comparator function for kernel paths + bool fileNameComp(string a, string b) { + string fna = static_cast(a).filename(); + string fnb = static_cast(b).filename(); + int comp = fna.compare(fnb); + SPDLOG_TRACE("Comparing {} and {}: {}", fna, fnb, comp); + return comp < 0; + } vector getLatestKernel(vector kernels) { if(kernels.empty()) { @@ -88,17 +96,25 @@ namespace SpiceQL { } bool foundList = false; for (int i = 0; i < files.size(); i++) { + const fs::path &firstVecElem = files[i][0]; string fileName = firstVecElem.filename(); string kernelName = k.filename(); + SPDLOG_TRACE("filename: {}", fileName); + SPDLOG_TRACE("kernel name: {}", kernelName); + int findRes = fileName.find_first_of("0123456789"); if (findRes != string::npos) { fileName = fileName.erase(findRes); } + findRes = kernelName.find_first_of("0123456789"); if (findRes != string::npos) { kernelName = kernelName.erase(findRes); } + SPDLOG_TRACE("Truncated filename: {}", fileName); + SPDLOG_TRACE("Truncated kernel name: {}", kernelName); + if (fileName == kernelName) { files[i].push_back(k); foundList = true; @@ -112,7 +128,7 @@ namespace SpiceQL { vector outKernels = {}; for (auto kernelList : files) { - outKernels.push_back(*(max_element(kernelList.begin(), kernelList.end()))); + outKernels.push_back(*(max_element(kernelList.begin(), kernelList.end(), fileNameComp))); } return outKernels; @@ -120,11 +136,13 @@ namespace SpiceQL { json getLatestKernels(json kernels) { - + SPDLOG_TRACE("Looking for kernels to get Latest: {}", kernels.dump(2)); vector kptrs = findKeyInJson(kernels, "kernels", true); vector> lastest; for (json::json_pointer &ptr : kptrs) { + SPDLOG_TRACE("Getting Latest Kernels from: {}", ptr.to_string()); + SPDLOG_TRACE("JSON: {}", kernels[ptr]); vector> kvect = json2DArrayTo2DVector(kernels[ptr]); vector> newLatest; diff --git a/SpiceQL/tests/QueryTests.cpp b/SpiceQL/tests/QueryTests.cpp index ca90e17..972befd 100644 --- a/SpiceQL/tests/QueryTests.cpp +++ b/SpiceQL/tests/QueryTests.cpp @@ -27,6 +27,27 @@ TEST(QueryTests, UnitTestGetLatestKernel) { EXPECT_EQ(getLatestKernel(kernels)[0], "test/iak.0004.ti"); } + +TEST(QueryTests, UnitTestGetLatestKernelDuplicateFileNames) { + vector kernels = { + "/base/kernels/spk/mar080.bsp", + "/base/kernels/spk/mar097.bsp", + "/mro/kernels/spk/mar063.bsp", + "/odyssey/kernels/spk/mar063.bsp", + "/tgo/kernels/spk/mar085.bsp", + "/tgo/kernels/spk/mar097.bsp", + "/tgo/kernels/tspk/mar085.bsp", + "/tgo/kernels/tspk/mar097.bsp", + "/viking1/kernels/spk/mar033.bsp", + "/viking2/kernels/spk/mar033.bsp", + "/base/kernels/spk/mar097.bsp" + }; + + // which one doesn't matter, as long as we get mar097.bsp + EXPECT_EQ(static_cast(getLatestKernel(kernels)[0]).filename(), "mar097.bsp"); +} + + TEST(QueryTests, getKernelStringValue){ unique_ptr k(new Kernel("data/msgr_mdis_v010.ti")); // INS-236810_CCD_CENTER = ( 511.5, 511.5 )