struct stat st;
char buff[BUFFER_SIZE];
int len;
- int fd;
#ifdef ENABLE_LIBDEBUGINFOD
/* Initialize a debuginfod client. */
static unique_ptr <debuginfod_client, void (*)(debuginfod_client*)>
int missing_files = 0;
for (const auto &pair : debug_sourcefiles)
{
- fd = -1;
+ int fd = -1;
const std::string &file_path = pair.first;
+ struct archive_entry *entry = NULL;
+ string entry_name;
/* Attempt to query debuginfod client to fetch source files. */
#ifdef ENABLE_LIBDEBUGINFOD
if (!no_backup)
#endif /* ENABLE_LIBDEBUGINFOD */
- /* Files could not be located using debuginfod, search locally */
- if (fd < 0)
- fd = open(file_path.c_str(), O_RDONLY);
+ /* Files could not be located using debuginfod, search locally */
+ if (fd < 0)
+ fd = open(file_path.c_str(), O_RDONLY);
if (fd < 0)
{
if (verbose)
missing_files++;
if (verbose)
cerr << "Error: Failed to get file status for " << file_path << ": " << strerror(errno) << endl;
- continue;
+ goto next;
}
- struct archive_entry *entry = archive_entry_new();
+ entry = archive_entry_new();
/* Removing first "/"" to make the path "relative" before zipping, otherwise warnings are raised when unzipping. */
- string entry_name = file_path.substr(file_path.find_first_of('/') + 1);
+ entry_name = file_path.substr(file_path.find_first_of('/') + 1);
archive_entry_set_pathname(entry, entry_name.c_str());
archive_entry_copy_stat(entry, &st);
if (archive_write_header(a, entry) != ARCHIVE_OK)
missing_files++;
if (verbose)
cerr << "Error: failed to write header for " << file_path << ": " << archive_error_string(a) << endl;
- continue;
+ goto next;
}
/* Write the file to the zip. */
missing_files++;
if (verbose)
cerr << "Error: Failed to open file: " << file_path << ": " << strerror(errno) <<endl;
- continue;
+ goto next;
}
while (len > 0)
{
}
len = read(fd, buff, sizeof(buff));
}
- close(fd);
- archive_entry_free(entry);
+
+next:
+ if (fd >= 0)
+ close(fd);
+ if (entry != NULL)
+ archive_entry_free(entry);
}
if (verbose && missing_files > 0 )
cerr << missing_files << " file(s) listed above could not be found. " << endl;