diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-28 21:53:10 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-28 21:55:34 (EDT) |
commit | 31eb612c37cb15a8c08af5e3637b4183356ac1f7 (patch) | |
tree | eb0c971f77da8c0cf18fb236c66d8177f52c198d | |
parent | e8b9703043c49e49edd4d705b7ce198e92f0b79e (diff) |
opk: Merge most of seek func into read func
-rw-r--r-- | src/opk.c | 101 |
1 files changed, 34 insertions, 67 deletions
@@ -156,69 +156,34 @@ _opkg_opk_opk_free_inner(struct opkg_opk_opk *opk) } static int -_opkg_opk_opk_seek(struct opkg_opk_ustar *ustar, +_opkg_opk_opk_check_name(const char *member_name, struct _opkg_opk_opk_seek_name **head, struct _opkg_opk_opk_seek_name **tail) { - struct opkg_opk_ustar_member *member; - int found; struct _opkg_opk_opk_seek_name *seek_name; - for (;;) { - /* Get next header record. */ - if (opkg_opk_ustar_list(ustar, &member) != OPKG_OPK_OK) { - return OPKG_OPK_ERROR; /* Error or end (not found) */ - } + if (member_name[0] == '.' && member_name[1] == '/') { + member_name += 2; + } - /* Check each requested name. */ - found = 0; - for (seek_name = *head; seek_name != NULL; - seek_name = seek_name->next) { - if (strcmp(member->name, seek_name->name) == 0) { - if (seek_name->prev != NULL) { - seek_name->prev->next = seek_name->next; - } else { - /* This was the head. Update. */ - *head = seek_name->next; - } - if (seek_name->next != NULL) { - seek_name->next->prev = seek_name->prev; - } else { - /* This was the tail. Update. */ - *tail = seek_name->prev; - } - free(seek_name); - found = 1; - break; - } - if (member->name[0] == '.' && member->name[1] == '/' && - strcmp(member->name + 2, - seek_name->name) == 0) - { - if (seek_name->prev != NULL) { - seek_name->prev->next = seek_name->next; - } else { - /* This was the head. Update. */ - *head = seek_name->next; - } - if (seek_name->next != NULL) { - seek_name->next->prev = seek_name->prev; - } else { - /* This was the tail. Update. */ - *tail = seek_name->prev; - } - free(seek_name); - found = 1; - break; + /* Check each requested name. */ + for (seek_name = *head; seek_name != NULL; seek_name = seek_name->next) + { + if (strcmp(member_name, seek_name->name) == 0) { + if (seek_name->prev != NULL) { + seek_name->prev->next = seek_name->next; + } else { + /* This was the head. Update. */ + *head = seek_name->next; } - } - free(member); - if (found == 1) { - if (*head == NULL) { - /* All requested members found */ - return OPKG_OPK_END; + if (seek_name->next != NULL) { + seek_name->next->prev = seek_name->prev; + } else { + /* This was the tail. Update. */ + *tail = seek_name->prev; } - return OPKG_OPK_OK; /* Member found, but more remain */ + free(seek_name); + return OPKG_OPK_OK; } } @@ -228,10 +193,10 @@ _opkg_opk_opk_seek(struct opkg_opk_ustar *ustar, static int _opkg_opk_opk_read_control(struct opkg_opk_opk *opk) { - char *buffer; - size_t size; - int ret_seek; - int ret_read; + struct opkg_opk_ustar_member *member; + char *buffer; + size_t size; + int ret_read; if (opk->print_control_head == NULL) { /* No control files requested. */ @@ -242,11 +207,16 @@ _opkg_opk_opk_read_control(struct opkg_opk_opk *opk) return OPKG_OPK_ERROR; } - while ((ret_seek = _opkg_opk_opk_seek(opk->inner_ustar, + while (opkg_opk_ustar_list(opk->inner_ustar, &member) == OPKG_OPK_OK) { + if (_opkg_opk_opk_check_name(member->name, &opk->print_control_head, - &opk->print_control_tail)) != - OPKG_OPK_ERROR) - { + &opk->print_control_tail) != + OPKG_OPK_OK) { + /* Name not requested for printing. */ + free(member); + continue; + } + free(member); if (opk->previously_printed == 1) { puts(""); } @@ -267,11 +237,8 @@ _opkg_opk_opk_read_control(struct opkg_opk_opk *opk) return OPKG_OPK_ERROR; } opk->previously_printed = 1; - if (ret_seek == OPKG_OPK_END) { - break; - } } - if (ret_seek == OPKG_OPK_ERROR) { + if (opk->print_control_head != NULL) { fputs(_("Error: Failed to find control file\n"), stderr); _opkg_opk_opk_free_inner(opk); return OPKG_OPK_ERROR; |