return r;
}
+#define pakfire_stripper_debug_path(stripper, s, filename, build_id) \
+ __pakfire_stripper_debug_path(stripper, s, sizeof(s), filename, build_id)
+
+static int __pakfire_stripper_debug_path(struct pakfire_stripper* self,
+ char* buffer, size_t length, struct pakfire_file* file, const char* build_id) {
+ char debugpath[PATH_MAX];
+ int r;
+
+ // Make the path to the debug directory
+ r = pakfire_path_append(debugpath, self->path, "usr/lib/debug");
+ if (r < 0)
+ return r;
+
+ // If we have a Build ID, we will make the path using that
+ if (build_id)
+ return __pakfire_string_format(buffer, length,
+ "%s/.build-id/%c%c/%s.debug", debugpath, build_id[0], build_id[1], build_id + 2);
+
+ // Fetch the path of the file
+ const char* path = pakfire_file_get_path(file);
+ if (!path)
+ return -EINVAL;
+
+ // Otherwise we will have to fall pack to the name of the file
+ return __pakfire_string_format(buffer, length, "%s/%s.debug", debugpath, path);
+}
+
static int pakfire_stripper_extract_debuginfo(struct pakfire_stripper* self,
struct pakfire_file* file, struct pakfire_elf* elf, const char* build_id_path) {
int r;
static int pakfire_stripper_strip_debuginfo(struct pakfire_stripper* self,
struct pakfire_file* file, struct pakfire_elf* elf) {
- const char* build_id = NULL;
- char build_id_path[PATH_MAX];
+ char debugpath[PATH_MAX];
char tmppath[PATH_MAX] = "";
- const char* path = NULL;
+ char** argv = NULL;
FILE* f = NULL;
int r;
- char** argv = NULL;
-
int extract_debuginfo = 1;
+ // Fetch the path
+ const char* path = pakfire_file_get_abspath(file);
+
+ // Fetch the Build ID
+ const char* build_id = pakfire_elf_build_id(elf);
+
// Check whether we should extract debug information
switch (pakfire_elf_type(elf)) {
// Relocatable objects
break;
}
- // Fetch the path
- path = pakfire_file_get_abspath(file);
-
- // Fetch the Build ID
- build_id = pakfire_elf_build_id(elf);
- if (!build_id) {
- ERROR(self->ctx, "No Build ID\n");
- r = -ENOTSUP;
+ // pakfire_stripper_debug_path
+ r = pakfire_stripper_debug_path(self, debugpath, file, build_id);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not make the debug path for %s: %s\n", path, strerror(-r));
goto ERROR;
}
- // Make Build ID path
- r = pakfire_string_format(build_id_path, "%s/usr/lib/debug/.build-id/%c%c/%s.debug",
- self->path, build_id[0], build_id[1], build_id + 2);
- if (r < 0)
- goto ERROR;
-
// Make a path for a new temporary file
r = pakfire_path(self->pakfire, tmppath, "%s", PAKFIRE_TMP_DIR "/.pakfire-strip.XXXXXXX");
if (r < 0)
// Extract the debug information
if (extract_debuginfo) {
- r = pakfire_stripper_extract_debuginfo(self, file, elf, build_id_path);
+ r = pakfire_stripper_extract_debuginfo(self, file, elf, debugpath);
if (r < 0)
goto ERROR;
// Add the debuglink
- r = pakfire_strings_appendf(&argv, "--add-gnu-debuglink=%s", build_id_path);
+ r = pakfire_strings_appendf(&argv, "--add-gnu-debuglink=%s", debugpath);
if (r < 0)
goto ERROR;
}