diff options
-rw-r--r-- | debuginfod/debuginfod.cxx | 12 | ||||
-rw-r--r-- | doc/debuginfod-find.1 | 1 | ||||
-rwxr-xr-x | tests/run-debuginfod-find-metadata.sh | 7 |
3 files changed, 12 insertions, 8 deletions
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 6efc4fea..000820fe 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -2572,11 +2572,11 @@ handle_metadata (MHD_Connection* conn, string sql = string( // explicit query r_de and f_de once here, rather than the query_d and query_e // separately, because they scan the same tables, so we'd double the work - "select d1.executable_p, d1.debuginfo_p, 0 as source_p, b1.hex, f1.name as file " - "from " BUILDIDS "_r_de d1, " BUILDIDS "_files f1, " BUILDIDS "_buildids b1 " - "where f1.id = d1.content and d1.buildid = b1.id and f1.name " + op + " ? " + "select d1.executable_p, d1.debuginfo_p, 0 as source_p, b1.hex, f1.name as file, a1.name as archive " + "from " BUILDIDS "_r_de d1, " BUILDIDS "_files f1, " BUILDIDS "_buildids b1, " BUILDIDS "_files a1 " + "where f1.id = d1.content and a1.id = d1.file and d1.buildid = b1.id and f1.name " + op + " ? " "union all \n" - "select d2.executable_p, d2.debuginfo_p, 0, b2.hex, f2.name " + "select d2.executable_p, d2.debuginfo_p, 0, b2.hex, f2.name, NULL " "from " BUILDIDS "_f_de d2, " BUILDIDS "_files f2, " BUILDIDS "_buildids b2 " "where f2.id = d2.file and d2.buildid = b2.id and f2.name " + op + " ? "); // NB: we could query source file names too, thusly: @@ -2624,13 +2624,14 @@ handle_metadata (MHD_Connection* conn, int m_source_p = sqlite3_column_int (*pp, 2); string m_buildid = (const char*) sqlite3_column_text (*pp, 3) ?: ""; // should always be non-null string m_file = (const char*) sqlite3_column_text (*pp, 4) ?: ""; + string m_archive = (const char*) sqlite3_column_text (*pp, 5) ?: ""; // Confirm that m_file matches in the fnmatch(FNM_PATHNAME) // sense, since sqlite's GLOB operator is a looser filter. if (key == "glob" && fnmatch(value.c_str(), m_file.c_str(), FNM_PATHNAME) != 0) continue; - auto add_metadata = [metadata, m_buildid, m_file](const string& type) { + auto add_metadata = [metadata, m_buildid, m_file, m_archive](const string& type) { json_object* entry = json_object_new_object(); if (NULL == entry) throw libc_exception (ENOMEM, "cannot allocate json"); defer_dtor<json_object*,int> entry_d(entry, json_object_put); @@ -2647,6 +2648,7 @@ handle_metadata (MHD_Connection* conn, add_entry_metadata("type", type.c_str()); add_entry_metadata("buildid", m_buildid); add_entry_metadata("file", m_file); + if (m_archive != "") add_entry_metadata("archive", m_archive); if (verbose > 3) obatched(clog) << "metadata found local " << json_object_to_json_string_ext(entry, diff --git a/doc/debuginfod-find.1 b/doc/debuginfod-find.1 index 58ac2d7d..6652539c 100644 --- a/doc/debuginfod-find.1 +++ b/doc/debuginfod-find.1 @@ -148,6 +148,7 @@ NAME TYPE DESCRIPTION \fBbuildid\fP string hexadecimal buildid associated with the file \fBtype\fP string one of \fBdebuginfo\fP or \fBexecutable\fP \fBfile\fP string matched file name, outside or inside the archive +\fBarchive\fP string archive containing matched file name, if any .TE .SH "OPTIONS" diff --git a/tests/run-debuginfod-find-metadata.sh b/tests/run-debuginfod-find-metadata.sh index 2928f9a4..c378bcdd 100755 --- a/tests/run-debuginfod-find-metadata.sh +++ b/tests/run-debuginfod-find-metadata.sh @@ -26,7 +26,7 @@ type curl 2>/dev/null || { echo "need curl"; exit 77; } type jq 2>/dev/null || { echo "need jq"; exit 77; } pkg-config json-c libcurl || { echo "one or more libraries are missing (libjson-c, libcurl)"; exit 77; } -debuginfod-find --help 2>&1 | grep metadata || { echo "compiled without metadata support"; exit 77; } +env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${VALGRIND_CMD} ${abs_builddir}/../debuginfod/debuginfod-find --help 2>&1 | grep metadata || { echo "compiled without metadata support"; exit 77; } DB=${PWD}/.debuginfod_tmp.sqlite @@ -79,9 +79,10 @@ test $N_FOUND -eq 2 # Query via the webapi as well -EXPECTED='[ { "type": "executable", "buildid": "f17a29b5a25bd4960531d82aa6b07c8abe84fa66", "file": "/usr/bin/hithere"} ]' curl http://127.0.0.1:$PORT2'/metadata?key=glob&value=/usr/bin/*hi*' -test `curl http://127.0.0.1:$PORT2'/metadata?key=glob&value=/usr/bin/*hi*' | jq ". == $EXPECTED" ` = 'true' +test `curl -s http://127.0.0.1:$PORT2'/metadata?key=glob&value=/usr/bin/*hi*' | jq '.[0].buildid == "f17a29b5a25bd4960531d82aa6b07c8abe84fa66"'` = 'true' +test `curl -s http://127.0.0.1:$PORT2'/metadata?key=glob&value=/usr/bin/*hi*' | jq '.[0].file == "/usr/bin/hithere"'` = 'true' +test `curl -s http://127.0.0.1:$PORT2'/metadata?key=glob&value=/usr/bin/*hi*' | jq '.[0].archive | test(".*hithere.*deb")'` = 'true' # An empty array is returned on server error or if the file DNE RESULTF=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod-find metadata file "/this/isnt/there"` |