struct pakfire_ctx* ctx, void* data, char* buffer, size_t length) {
struct pakfire_find_deps_ctx* p = (struct pakfire_find_deps_ctx*)data;
struct pakfire_file* file = NULL;
+ const char* path = NULL;
int r = 0;
- // Check if we have reached the end of the filelist
- if (p->i >= pakfire_filelist_length(p->filelist))
- return 0;
+ for (;;) {
+ // Check if we have reached the end of the filelist
+ if (p->i >= pakfire_filelist_length(p->filelist))
+ return 0;
- // Fetch the next file
- file = pakfire_filelist_get(p->filelist, p->i);
- if (!file) {
- DEBUG(ctx, "Could not fetch file %u: %m\n", p->i);
- r = -errno;
- goto ERROR;
- }
+ // Fetch the next file
+ file = pakfire_filelist_get(p->filelist, p->i);
+ if (!file) {
+ DEBUG(ctx, "Could not fetch file %u: %m\n", p->i);
+ r = -errno;
+ goto ERROR;
+ }
- // Fetch the path of the file
- const char* path = pakfire_file_get_path(file);
- if (!path) {
- ERROR(ctx, "Received a file with an empty path\n");
- r = -errno;
- goto ERROR;
- }
+ // Skip files that don't match what we are looking for
+ if (p->class && !pakfire_file_matches_class(file, p->class))
+ goto SKIP;
- // Skip files that don't match what we are looking for
- if (p->class && !pakfire_file_matches_class(file, p->class)) {
- r = -EAGAIN;
- goto SKIP;
- }
+ // Fetch the path of the file
+ path = pakfire_file_get_path(file);
+ if (!path) {
+ ERROR(ctx, "Received a file with an empty path\n");
+ r = -errno;
+ goto ERROR;
+ }
- // Write path to stdin
- r = snprintf(buffer, length, "%s\n", path);
- if (r < 0)
- goto ERROR;
+ // Write path to the buffer
+ r = snprintf(buffer, length, "%s\n", path);
+ if (r < 0)
+ goto ERROR;
- // If the output could not be written, we ask to be called again later
- else if (r >= (ssize_t)length) {
- r = -EAGAIN;
- goto ERROR;
- }
+ // If the output could not be written, we ask to be called again later
+ else if (r >= (ssize_t)length) {
+ r = -EAGAIN;
+ goto ERROR;
+ }
SKIP:
- // Move on to the next file
- p->i++;
+ // Move on to the next file
+ p->i++;
+
+ pakfire_file_unref(file);
+ file = NULL;
+ }
ERROR:
if (file)