Skip to content

Commit 91a63a1

Browse files
committed
lib: extend xbps_transaction_file_get to return old and new files
1 parent b1831a6 commit 91a63a1

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

include/xbps_api_impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ int HIDDEN xbps_transaction_init(struct xbps_handle *);
107107
int HIDDEN xbps_transaction_files(struct xbps_handle *,
108108
xbps_object_iterator_t);
109109
void HIDDEN xbps_transaction_files_free(struct xbps_handle *);
110-
const struct xbps_file HIDDEN *xbps_transaction_file_get(struct xbps_handle *xhp, const char *path);
110+
int HIDDEN xbps_transaction_file_get(struct xbps_handle *xhp, const char *path,
111+
const struct xbps_file **oldp, const struct xbps_file **newp);
111112
int HIDDEN xbps_transaction_fetch(struct xbps_handle *,
112113
xbps_object_iterator_t);
113114
int HIDDEN xbps_transaction_pkg_deps(struct xbps_handle *, xbps_array_t, xbps_dictionary_t);

lib/package_unpack.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ unpack_archive(struct xbps_handle *xhp,
8686
const char *fname,
8787
struct archive *ar)
8888
{
89-
const struct xbps_file *file;
89+
const struct xbps_file *old = NULL, *new = NULL;
9090
xbps_dictionary_t binpkg_filesd, pkg_filesd, obsd;
9191
xbps_array_t array, obsoletes;
9292
xbps_trans_type_t ttype;
@@ -292,19 +292,19 @@ unpack_archive(struct xbps_handle *xhp,
292292
continue;
293293
}
294294

295-
file = xbps_transaction_file_get(xhp, entry_pname+1);
296-
if (!file) {
295+
rv = xbps_transaction_file_get(xhp, entry_pname+1, &old, &new);
296+
if (rv < 0) {
297297
xbps_error_printf("unknown file in binary package: %s: %s\n",
298298
pkgver, entry_pname+1);
299-
rv = EINVAL;
299+
rv = -rv;
300300
goto out;
301301
}
302302

303303
/*
304304
* Check if current entry is a configuration file,
305305
* that should be kept.
306306
*/
307-
keep_conf_file = (file->flags & XBPS_FILE_CONF) != 0;
307+
keep_conf_file = (new->flags & XBPS_FILE_CONF) != 0;
308308

309309
/*
310310
* If file to be extracted does not match the file type of
@@ -341,13 +341,13 @@ unpack_archive(struct xbps_handle *xhp,
341341
}
342342
rv = 0;
343343
} else {
344-
if (!file->sha256) {
344+
if (!new->sha256) {
345345
xbps_error_printf("missing checksum in binary package"
346346
": %s: %s\n", pkgver, entry_pname+1);
347347
rv = EINVAL;
348348
goto out;
349349
}
350-
rv = xbps_file_sha256_check(entry_pname, file->sha256);
350+
rv = xbps_file_sha256_check(entry_pname, new->sha256);
351351
if (rv == -1) {
352352
/* error */
353353
xbps_dbg_printf(

lib/transaction_files.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,19 @@ xbps_transaction_files_free(struct xbps_handle *xhp UNUSED)
901901
free(items);
902902
}
903903

904-
const struct xbps_file HIDDEN *
905-
xbps_transaction_file_get(struct xbps_handle *xhp UNUSED, const char *path)
904+
int HIDDEN
905+
xbps_transaction_file_get(struct xbps_handle *xhp UNUSED, const char *path,
906+
const struct xbps_file **oldp,
907+
const struct xbps_file **newp)
906908
{
907909
struct item *item;
908910

909911
item = lookupItem(path);
910912
if (!item)
911-
return NULL;
912-
return &item->new.file;
913+
return -ENOENT;
914+
if (oldp)
915+
*oldp = item->old.pkgver ? &item->old.file : NULL;
916+
if (newp)
917+
*newp = item->new.pkgver ? &item->new.file : NULL;
918+
return 0;
913919
}

0 commit comments

Comments
 (0)