file_is_kernel_package(const string& file_path,
file_type file_type);
+bool
+rpm_contains_file(const string& rpm_path,
+ const string& file_name);
+
bool
file_is_kernel_debuginfo_package(const string& file_path,
file_type file_type);
// for vmlinux.ctfa should be provided with --debug-info-dir
// option.
for (const auto& path : debug_info_root_paths())
- {
- ctfa_dirname = *path;
- ctfa_file = ctfa_dirname + "/vmlinux.ctfa";
- if (file_exists(ctfa_file))
- return true;
- }
+ if (tools_utils::find_file_under_dir(*path, "vmlinux.ctfa", ctfa_file))
+ return true;
return false;
}
&& corpus_group())
{
tools_utils::base_name(corpus_path(), dict_name);
-
- if (dict_name != "vmlinux")
- // remove .ko suffix
- dict_name.erase(dict_name.length() - 3, 3);
+ // remove .* suffix
+ std::size_t pos = dict_name.find(".");
+ if (pos != string::npos)
+ dict_name.erase(pos);
std::replace(dict_name.begin(), dict_name.end(), '-', '_');
}
// vmlinux.ctfa could be provided with --debug-info-dir
for (const auto& path : debug_info_root_paths)
- if (dir_contains_ctf_archive(*path, vmlinux))
+ if (find_file_under_dir(*path, "vmlinux.ctfa", vmlinux))
return true;
return false;
/// Tests if a given file name designates a kernel package.
///
-/// @param file_name the file name to consider.
+/// @param file_path the path to the file to consider.
///
/// @param file_type the type of the file @p file_name.
///
/// @return true iff @p file_name of kind @p file_type designates a
/// kernel package.
bool
-file_is_kernel_package(const string& file_name, file_type file_type)
+file_is_kernel_package(const string& file_path, file_type file_type)
{
bool result = false;
- string package_name;
if (file_type == FILE_TYPE_RPM)
{
- if (!get_rpm_name(file_name, package_name))
- return false;
- result = (package_name == "kernel");
+ if (rpm_contains_file(file_path, "vmlinuz"))
+ result = true;
}
else if (file_type == FILE_TYPE_DEB)
{
- if (!get_deb_name(file_name, package_name))
- return false;
- result = (string_begins_with(package_name, "linux-image"));
+ string file_name;
+ base_name(file_path, file_name);
+ string package_name;
+ if (get_deb_name(file_name, package_name))
+ result = (string_begins_with(package_name, "linux-image"));
}
return result;
}
+/// Test if an RPM package contains a given file.
+///
+/// @param rpm_path the path to the RPM package.
+///
+/// @param file_name the file name to test the presence for in the
+/// rpm.
+///
+/// @return true iff the file named @file_name is present in the RPM.
+bool
+rpm_contains_file(const string& rpm_path, const string& file_name)
+{
+ vector<string> query_output;
+ // We don't check the return value of this command because on some
+ // system, the command can issue errors but still emit a valid
+ // output. We'll rather rely on the fact that the command emits a
+ // valid output or not.
+ execute_command_and_get_output("rpm -qlp "
+ + rpm_path + " 2> /dev/null",
+ query_output);
+
+ for (auto& line : query_output)
+ {
+ line = trim_white_space(line);
+ if (string_ends_with(line, file_name))
+ return true;
+ }
+
+ return false;
+}
+
/// Tests if a given file name designates a kernel debuginfo package.
///
/// @param file_name the file name to consider.
vector<char**> di_roots;
di_roots.push_back(&di_root_ptr);
+#ifdef WITH_CTF
+ shared_ptr<char> di_root_ctf;
+ if (requested_fe_kind & corpus::CTF_ORIGIN)
+ {
+ di_root_ctf = make_path_absolute(root.c_str());
+ char *di_root_ctf_ptr = di_root_ctf.get();
+ di_roots.push_back(&di_root_ctf_ptr);
+ }
+#endif
+
abigail::elf_based_reader_sptr reader =
create_best_elf_based_reader(vmlinux,
di_roots,
if (pkg.type() != abigail::tools_utils::FILE_TYPE_RPM)
return false;
- string pkg_name = pkg.base_name();
- bool is_linux_kernel_package = file_is_kernel_package(pkg_name, pkg.type());
+ bool is_linux_kernel_package = file_is_kernel_package(pkg.path(),
+ pkg.type());
if (!is_linux_kernel_package)
return false;
return false;
string rpm_arch;
- if (!get_rpm_arch(pkg_name, rpm_arch))
+ if (!get_rpm_arch(pkg.base_name(), rpm_arch))
return false;
string kabi_wl_path = kabi_wl_pkg->extracted_dir_path();
// if package is linux kernel package and its associated debug
// info package looks like a kernel debuginfo package, then try to
// go find the vmlinux file in that debug info file.
- string pkg_name = package.base_name();
- bool is_linux_kernel_package = file_is_kernel_package(pkg_name,
+ bool is_linux_kernel_package = file_is_kernel_package(package.path(),
package.type());
if (is_linux_kernel_package)
{
{
abidiff_status status = abigail::tools_utils::ABIDIFF_OK;
- if (abigail::tools_utils::file_is_kernel_package(first_package.base_name(),
+ if (abigail::tools_utils::file_is_kernel_package(first_package.path(),
first_package.type()))
{
opts.show_symbols_not_referenced_by_debug_info = false;
| abigail::tools_utils::ABIDIFF_ERROR);
}
- if (file_is_kernel_package(first_package->base_name(),
+ if (file_is_kernel_package(first_package->path(),
abigail::tools_utils::FILE_TYPE_RPM)
- || file_is_kernel_package(second_package->base_name(),
+ || file_is_kernel_package(second_package->path(),
abigail::tools_utils::FILE_TYPE_RPM))
{
- if (file_is_kernel_package(first_package->base_name(),
+ if (file_is_kernel_package(first_package->path(),
abigail::tools_utils::FILE_TYPE_RPM)
- != file_is_kernel_package(second_package->base_name(),
+ != file_is_kernel_package(second_package->path(),
abigail::tools_utils::FILE_TYPE_RPM))
{
emit_prefix("abipkgdiff", cerr)