-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: replace xbps_file_hash_check_dictionary with transaction_file lookup #359
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,26 @@ | |
#define __arraycount(x) (sizeof(x) / sizeof(*x)) | ||
#endif | ||
|
||
typedef enum transaction_file_type { | ||
TYPE_LINK = 1, | ||
TYPE_DIR, | ||
TYPE_FILE, | ||
TYPE_CONFFILE, | ||
} transaction_file_type_t; | ||
|
||
struct transaction_file { | ||
const char *pkgname; | ||
const char *pkgver; | ||
char *sha256; | ||
const char *target; | ||
uint64_t size; | ||
transaction_file_type_t type; | ||
Comment on lines
+106
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would these first 6 be the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we need two struct a |
||
unsigned int index; | ||
bool preserve; | ||
bool update; | ||
bool removepkg; | ||
}; | ||
|
||
/** | ||
* @private | ||
*/ | ||
|
@@ -135,14 +155,15 @@ bool HIDDEN xbps_transaction_store(struct xbps_handle *, xbps_array_t, xbps_dict | |
int HIDDEN xbps_transaction_init(struct xbps_handle *); | ||
int HIDDEN xbps_transaction_files(struct xbps_handle *, | ||
xbps_object_iterator_t); | ||
void xbps_transaction_files_free(void); | ||
int HIDDEN xbps_transaction_fetch(struct xbps_handle *, | ||
xbps_object_iterator_t); | ||
int HIDDEN xbps_transaction_pkg_deps(struct xbps_handle *, xbps_array_t, xbps_dictionary_t); | ||
|
||
struct transaction_file *xbps_transaction_file_new(struct xbps_handle *, const char *); | ||
|
||
Comment on lines
+158
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming is a bit confusing, in that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the _new does not actually create anything, it gives you a reference to a file struct that already exists from collecting all files in the transaction, "_new" because it returns the new file as opposed to the old file. Not sure how this should be done exactly, something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the parameter helps avoid duplicated logic, so I'm in favor of that. |
||
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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,7 @@ unpack_archive(struct xbps_handle *xhp, | |
* Unpack all files on archive now. | ||
*/ | ||
for (;;) { | ||
struct transaction_file *file; | ||
ar_rv = archive_read_next_header(ar, &entry); | ||
if (ar_rv == ARCHIVE_EOF || ar_rv == ARCHIVE_FATAL) | ||
break; | ||
|
@@ -342,15 +343,17 @@ unpack_archive(struct xbps_handle *xhp, | |
continue; | ||
} | ||
|
||
assert(*entry_pname == '.'); | ||
file = xbps_transaction_file_new(xhp, entry_pname+1); | ||
assert(file); | ||
|
||
/* | ||
* Check if current entry is a configuration file, | ||
* that should be kept. | ||
*/ | ||
if (!force && (entry_type == AE_IFREG)) { | ||
buf = strchr(entry_pname, '.') + 1; | ||
assert(buf != NULL); | ||
keep_conf_file = xbps_entry_is_a_conf_file(binpkg_filesd, buf); | ||
} | ||
keep_conf_file = !force | ||
&& (entry_type == AE_IFREG) | ||
&& file->type == TYPE_CONFFILE; | ||
|
||
/* | ||
* If file to be extracted does not match the file type of | ||
|
@@ -387,8 +390,9 @@ unpack_archive(struct xbps_handle *xhp, | |
} | ||
rv = 0; | ||
} else { | ||
rv = xbps_file_hash_check_dictionary( | ||
xhp, binpkg_filesd, "files", buf); | ||
xbps_dbg_printf(xhp, "%s: %s\n", entry_pname, file->sha256); | ||
assert(file->sha256); | ||
Comment on lines
+393
to
+394
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be nice to make it clear that a
|
||
rv = xbps_file_sha256_check(entry_pname, file->sha256); | ||
if (rv == -1) { | ||
/* error */ | ||
xbps_dbg_printf(xhp, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,28 +33,10 @@ | |
#include "xbps_api_impl.h" | ||
#include "uthash.h" | ||
|
||
enum type { | ||
TYPE_LINK = 1, | ||
TYPE_DIR, | ||
TYPE_FILE, | ||
TYPE_CONFFILE, | ||
}; | ||
|
||
struct item { | ||
char *file; | ||
size_t len; | ||
struct { | ||
const char *pkgname; | ||
const char *pkgver; | ||
char *sha256; | ||
const char *target; | ||
uint64_t size; | ||
enum type type; | ||
unsigned int index; | ||
bool preserve; | ||
bool update; | ||
bool removepkg; | ||
} old, new; | ||
struct transaction_file old, new; | ||
bool deleted; | ||
UT_hash_handle hh; | ||
}; | ||
|
@@ -114,7 +96,7 @@ addItem(const char *file) | |
} | ||
|
||
static const char * | ||
typestr(enum type typ) | ||
typestr(transaction_file_type_t typ) | ||
{ | ||
switch (typ) { | ||
case TYPE_LINK: return "symlink"; | ||
|
@@ -420,8 +402,8 @@ collect_obsoletes(struct xbps_handle *xhp) | |
static int | ||
collect_file(struct xbps_handle *xhp, const char *file, size_t size, | ||
const char *pkgname, const char *pkgver, unsigned int idx, | ||
const char *sha256, enum type type, bool update, bool removepkg, | ||
bool preserve, bool removefile, const char *target) | ||
const char *sha256, transaction_file_type_t type, bool update, | ||
bool removepkg, bool preserve, bool removefile, const char *target) | ||
{ | ||
struct item *item; | ||
|
||
|
@@ -526,6 +508,8 @@ collect_file(struct xbps_handle *xhp, const char *file, size_t size, | |
item->new.update = update; | ||
item->new.removepkg = removepkg; | ||
item->new.target = target; | ||
if (sha256) | ||
item->new.sha256 = strdup(sha256); | ||
Comment on lines
+511
to
+512
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally everything is zero initialized, IMHO not doing that by default when initializing the memory should only be done if you know you overwrite it immediately. |
||
} | ||
if (item->old.type && item->new.type) { | ||
/* | ||
|
@@ -565,8 +549,7 @@ collect_files(struct xbps_handle *xhp, xbps_dictionary_t d, | |
for (i = 0; i < xbps_array_count(a); i++) { | ||
filed = xbps_array_get(a, i); | ||
xbps_dictionary_get_cstring_nocopy(filed, "file", &file); | ||
if (removefile) | ||
xbps_dictionary_get_cstring_nocopy(filed, "sha256", &sha256); | ||
xbps_dictionary_get_cstring_nocopy(filed, "sha256", &sha256); | ||
size = 0; | ||
xbps_dictionary_get_uint64(filed, "size", &size); | ||
rv = collect_file(xhp, file, size, pkgname, pkgver, idx, sha256, | ||
|
@@ -585,8 +568,7 @@ collect_files(struct xbps_handle *xhp, xbps_dictionary_t d, | |
xbps_dictionary_get_cstring_nocopy(filed, "file", &file); | ||
size = 0; | ||
xbps_dictionary_get_uint64(filed, "size", &size); | ||
if (removefile) | ||
xbps_dictionary_get_cstring_nocopy(filed, "sha256", &sha256); | ||
xbps_dictionary_get_cstring_nocopy(filed, "sha256", &sha256); | ||
#if 0 | ||
/* XXX: how to handle conf_file size */ | ||
if (removefile && stat(file, &st) != -1 && size != (uint64_t)st.st_size) | ||
|
@@ -746,8 +728,8 @@ pathcmp(const void *l1, const void *l2) | |
return (a->len < b->len) - (b->len < a->len); | ||
} | ||
|
||
static void | ||
cleanup(void) | ||
void | ||
xbps_transaction_files_free(void) | ||
{ | ||
struct item *item, *itmp; | ||
|
||
|
@@ -798,7 +780,8 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter) | |
|
||
update = (ttype == XBPS_TRANS_UPDATE); | ||
|
||
if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_UPDATE) { | ||
if (ttype == XBPS_TRANS_INSTALL || ttype == XBPS_TRANS_UPDATE | ||
|| ttype == XBPS_TRANS_REINSTALL) { | ||
xbps_set_cb_state(xhp, XBPS_STATE_FILES, 0, pkgver, | ||
"%s: collecting files...", pkgver); | ||
rv = collect_binpkg_files(xhp, obj, idx, update); | ||
|
@@ -858,6 +841,16 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter) | |
return rv; | ||
|
||
rv = collect_obsoletes(xhp); | ||
cleanup(); | ||
return rv; | ||
} | ||
|
||
struct transaction_file HIDDEN * | ||
xbps_transaction_file_new(struct xbps_handle *xhp UNUSED, const char *path) | ||
{ | ||
struct item *item; | ||
|
||
if ((item = lookupItem(path)) == NULL) | ||
return NULL; | ||
|
||
return &item->new; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically speaking
*_t
is reserved for libc (https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html), but everyone uses it anyway.