Skip to content

Commit

Permalink
lib: remove xbps_file_hash_check_dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncaen committed Jan 10, 2024
1 parent c3caff4 commit 70480d2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 71 deletions.
2 changes: 0 additions & 2 deletions include/xbps_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ int HIDDEN xbps_transaction_internalize(struct xbps_handle *, xbps_object_iterat

char HIDDEN *xbps_get_remote_repo_string(const char *);
int HIDDEN xbps_repo_sync(struct xbps_handle *, const char *);
int HIDDEN xbps_file_hash_check_dictionary(struct xbps_handle *,
xbps_dictionary_t, const char *, const char *);
int HIDDEN xbps_file_exec(struct xbps_handle *, const char *, ...);
void HIDDEN xbps_set_cb_fetch(struct xbps_handle *, off_t, off_t, off_t,
const char *, bool, bool, bool);
Expand Down
69 changes: 0 additions & 69 deletions lib/util_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,72 +209,3 @@ xbps_file_sha256_check(const char *file, const char *sha256)

return 0;
}

static const char *
file_hash_dictionary(xbps_dictionary_t d, const char *key, const char *file)
{
xbps_object_t obj;
xbps_object_iterator_t iter;
const char *curfile = NULL, *sha256 = NULL;

assert(xbps_object_type(d) == XBPS_TYPE_DICTIONARY);
assert(key != NULL);
assert(file != NULL);

iter = xbps_array_iter_from_dict(d, key);
if (iter == NULL) {
errno = ENOENT;
return NULL;
}
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj,
"file", &curfile);
if (strcmp(file, curfile) == 0) {
/* file matched */
xbps_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256);
break;
}
}
xbps_object_iterator_release(iter);
if (sha256 == NULL)
errno = ENOENT;

return sha256;
}

int HIDDEN
xbps_file_hash_check_dictionary(struct xbps_handle *xhp,
xbps_dictionary_t d,
const char *key,
const char *file)
{
const char *sha256d = NULL;
char *buf;
int rv;

assert(xbps_object_type(d) == XBPS_TYPE_DICTIONARY);
assert(key != NULL);
assert(file != NULL);

if ((sha256d = file_hash_dictionary(d, key, file)) == NULL) {
if (errno == ENOENT)
return 1; /* no match, file not found */

return -1; /* error */
}

if (strcmp(xhp->rootdir, "/") == 0) {
rv = xbps_file_sha256_check(file, sha256d);
} else {
buf = xbps_xasprintf("%s/%s", xhp->rootdir, file);
rv = xbps_file_sha256_check(buf, sha256d);
free(buf);
}
if (rv == 0)
return 0; /* matched */
else if (rv == ERANGE || rv == ENOENT)
return 1; /* no match */
else
return -1; /* error */
}

0 comments on commit 70480d2

Please sign in to comment.