Skip to content

Commit

Permalink
fix some logic errors with index lookup error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Sep 11, 2021
1 parent 0019f90 commit c3e7b54
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libmport/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,29 @@ fetch(mportInstance *mport, const char *url, const char *dest)
*/
int
mport_download(mportInstance *mport, const char *packageName, char **path) {
mportIndexEntry **indexEntry;
mportIndexEntry **indexEntry = NULL;
bool existed = true;
int retryCount = 0;

if (mport_index_lookup_pkgname(mport, packageName, &indexEntry) != MPORT_OK) {
RETURN_CURRENT_ERROR;
}

if (indexEntry == NULL || *indexEntry == NULL)
if (indexEntry == NULL || (*indexEntry) == NULL) {
SET_ERRORX(1, "Package %s not found in index.\n", packageName);
RETURN_CURRENT_ERROR;
}

if ((*indexEntry)->bundlefile == NULL) {
SET_ERRORX(1, "Package %s does not contain a bundle file.\n", packageName);
RETURN_CURRENT_ERROR;
}

asprintf(path, "%s/%s", MPORT_LOCAL_PKG_PATH, (*indexEntry)->bundlefile);
if (path == NULL) {
mport_index_entry_free_vec(indexEntry);
SET_ERRORX(1, "%s", "Unable to allocate memory for path.");
RETURN_CURRENT_ERROR;
}

getfile:
Expand All @@ -287,6 +295,7 @@ mport_download(mportInstance *mport, const char *packageName, char **path) {
free(*path);
mport_index_entry_free_vec(indexEntry);
SET_ERRORX(1, "Package %s fails hash verification.", packageName);
RETURN_CURRENT_ERROR;
}

if (!existed)
Expand Down

0 comments on commit c3e7b54

Please sign in to comment.