1
0
forked from mirrors/pacman

Compare commits

...

9 Commits

Author SHA1 Message Date
morganamilo
a61c500557 pacman: add -Q --backup
pacman -Q -w/--backup will print the modified backup files of a system
(passing twice will print all backup files). This could be useful for
backup/moving system config files.
2021-10-02 00:12:52 +01:00
Allan McRae
39c3cbdf56 _alpm_key_import: Initialise fetch_key
Prevents build warning.

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-05 09:58:18 +10:00
morganamilo
165e492485 pacman: don't run hooks when using --dbonly
--dbonly is meant to only touch the database and not the actual system.
However hooks still run which can leave files in place or run commands
you may not want.

The hooks being run also means `fakeroot pacman -S --dbpath test/ foo --dbonly`
fails because alpm tries to chroot for hooks which requires real root.

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 20:46:57 +10:00
morganamilo
be76f8bf06 libalpm: add ALPM_TRANS_FLAG_NOHOOKS
Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 20:46:47 +10:00
morganamilo
625f3d645b libalpm: don't use alpm_pgpkey_t in import question
When constructing an import question we never really used a proper gpg
key. We just zero initialize the key, set the uid and fingerprint, and
sent that to the front end.

Instead lets just give the import question a uid and fingerprint field.

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 20:43:16 +10:00
morganamilo
e187aa9b48 libalpm: use else when setting fingerprint
The docs [1] say keyid will always be there, so no need to check if it
exists.

[1] https://www.gnupg.org/documentation/manuals/gpgme/Key-objects.html

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 19:52:23 +10:00
morganamilo
c5c6633dd1 libalpm: rename __foo tyes to _foo
__foo is reserved in c and should not be used.

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 19:52:23 +10:00
morganamilo
2109de613a libalpm: take alpm_trans_t out of the public API
this type is only used internally by alpm

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 19:52:23 +10:00
Allan McRae
fbb29b5047 repo-add: add --include-sigs option
Pacman now downloads the signature files for all packages when present in a
repository.  That makes distributing signatures within repository databases
redundant and costly.

Do not distribute the package signature files within the repo databases by
default and add an --include-sigs to revert to the old behaviour.

Signed-off-by: Allan McRae <allan@archlinux.org>
2021-09-04 19:52:23 +10:00
20 changed files with 121 additions and 46 deletions

View File

@@ -364,6 +364,9 @@ Query Options (apply to '-Q')[[QO]]
replacements are not checked here. This option works best if the sync
database is refreshed using '-Sy'.
*-w, \--backup*::
List all modified backup files owened by a given package. Multiple packages can
be specified on the command line. Pass twice to print all backup files.
Remove Options (apply to '-R')[[RO]]
------------------------------------

View File

@@ -70,6 +70,8 @@ repo-add Options
Remove old package files from the disk when updating their entry in the
database.
*\--include-sigs*::
Include package PGP signatures in the repository database (if available)
Example
-------

View File

@@ -78,7 +78,7 @@ extern "C" {
* This struct represents an instance of libalpm.
* @ingroup libalpm_handle
*/
typedef struct __alpm_handle_t alpm_handle_t;
typedef struct _alpm_handle_t alpm_handle_t;
/** A database.
*
@@ -98,7 +98,7 @@ typedef struct __alpm_handle_t alpm_handle_t;
* Databases are automatically unregistered when the \link alpm_handle_t \endlink is released.
* @ingroup libalpm_databases
*/
typedef struct __alpm_db_t alpm_db_t;
typedef struct _alpm_db_t alpm_db_t;
/** A package.
@@ -111,13 +111,7 @@ typedef struct __alpm_db_t alpm_db_t;
* to be added or removed from the system.
* @ingroup libalpm_packages
*/
typedef struct __alpm_pkg_t alpm_pkg_t;
/** Transaction structure used internally by libalpm
* @ingroup libalpm_trans
* */
typedef struct __alpm_trans_t alpm_trans_t;
typedef struct _alpm_pkg_t alpm_pkg_t;
/** The time type used by libalpm. Represents a unix time stamp
* @ingroup libalpm_misc */
@@ -1080,8 +1074,10 @@ typedef struct _alpm_question_import_key_t {
alpm_question_type_t type;
/** Answer: whether or not to import key */
int import;
/** The key to import */
alpm_pgpkey_t *key;
/** UID of the key to import */
const char *uid;
/** Fingerprint the key to import */
const char *fingerprint;
} alpm_question_import_key_t;
/**
@@ -2719,7 +2715,8 @@ typedef enum _alpm_transflag_t {
ALPM_TRANS_FLAG_RECURSE = (1 << 5),
/** Modify database but do not commit changes to the filesystem. */
ALPM_TRANS_FLAG_DBONLY = (1 << 6),
/* (1 << 7) flag can go here */
/** Do not run hooks during a transaction */
ALPM_TRANS_FLAG_NOHOOKS = (1 << 7),
/** Use ALPM_PKG_REASON_DEPEND when installing packages. */
ALPM_TRANS_FLAG_ALLDEPS = (1 << 8),
/** Only download packages and do not actually install. */

View File

@@ -48,13 +48,13 @@ extern "C" {
*/
/** A doubly linked list */
typedef struct __alpm_list_t {
typedef struct _alpm_list_t {
/** data held by the list node */
void *data;
/** pointer to the previous node */
struct __alpm_list_t *prev;
struct _alpm_list_t *prev;
/** pointer to the next node */
struct __alpm_list_t *next;
struct _alpm_list_t *next;
} alpm_list_t;
/** Frees a list and its contents */

View File

@@ -62,7 +62,7 @@ struct db_operations {
};
/* Database */
struct __alpm_db_t {
struct _alpm_db_t {
alpm_handle_t *handle;
char *treename;
/* do not access directly, use _alpm_db_path(db) for lazy access */

View File

@@ -43,7 +43,7 @@ enum mount_fsinfo {
MOUNT_FSINFO_FAIL,
};
typedef struct __alpm_mountpoint_t {
typedef struct _alpm_mountpoint_t {
/* mount point information */
char *mount_dir;
size_t mount_dir_len;

View File

@@ -23,19 +23,19 @@
#include "alpm_list.h"
enum __alpm_graph_vertex_state {
enum _alpm_graph_vertex_state {
ALPM_GRAPH_STATE_UNPROCESSED,
ALPM_GRAPH_STATE_PROCESSING,
ALPM_GRAPH_STATE_PROCESSED
};
typedef struct __alpm_graph_t {
typedef struct _alpm_graph_t {
void *data;
struct __alpm_graph_t *parent; /* where did we come from? */
struct _alpm_graph_t *parent; /* where did we come from? */
alpm_list_t *children;
alpm_list_t *iterator; /* used for DFS without recursion */
off_t weight; /* weight of the node */
enum __alpm_graph_vertex_state state;
enum _alpm_graph_vertex_state state;
} alpm_graph_t;
alpm_graph_t *_alpm_graph_new(void);

View File

@@ -26,6 +26,7 @@
#include "alpm_list.h"
#include "alpm.h"
#include "trans.h"
#ifdef HAVE_LIBCURL
#include <curl/curl.h>
@@ -50,7 +51,7 @@ do { \
} \
} while(0)
struct __alpm_handle_t {
struct _alpm_handle_t {
/* internal usage */
alpm_db_t *db_local; /* local db pointer */
alpm_list_t *dbs_sync; /* List of (alpm_db_t *) */

View File

@@ -85,7 +85,7 @@ struct pkg_operations {
*/
extern const struct pkg_operations default_pkg_ops;
struct __alpm_pkg_t {
struct _alpm_pkg_t {
unsigned long name_hash;
char *filename;
char *base;

View File

@@ -32,7 +32,7 @@
* A combination of a hash table and a list, allowing for fast look-up
* by package name but also iteration over the packages.
*/
struct __alpm_pkghash_t {
struct _alpm_pkghash_t {
/** data held by the hash table */
alpm_list_t **hash_table;
/** head node of the hash table data in normal list format */
@@ -45,7 +45,7 @@ struct __alpm_pkghash_t {
unsigned int limit;
};
typedef struct __alpm_pkghash_t alpm_pkghash_t;
typedef struct _alpm_pkghash_t alpm_pkghash_t;
alpm_pkghash_t *_alpm_pkghash_create(unsigned int size);

View File

@@ -350,7 +350,7 @@ static int key_search_keyserver(alpm_handle_t *handle, const char *fpr,
pgpkey->data = key;
if(key->subkeys->fpr) {
pgpkey->fingerprint = key->subkeys->fpr;
} else if(key->subkeys->keyid) {
} else {
pgpkey->fingerprint = key->subkeys->keyid;
}
pgpkey->uid = key->uids->uid;
@@ -504,19 +504,15 @@ int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
return -1;
}
STRDUP(fetch_key.uid, uid, return -1);
STRDUP(fetch_key.fingerprint, fpr, free(fetch_key.uid); return -1);
alpm_question_import_key_t question = {
.type = ALPM_QUESTION_IMPORT_KEY,
.import = 0,
.key = &fetch_key
.uid = uid,
.fingerprint = fpr
};
QUESTION(handle, &question);
free(fetch_key.uid);
free(fetch_key.fingerprint);
if(question.import) {
/* Try to import the key from a WKD first */
if(email_from_uid(uid, &email) == 0) {

View File

@@ -198,7 +198,8 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
}
}
if(_alpm_hook_run(handle, ALPM_HOOK_PRE_TRANSACTION) != 0) {
if(!(trans->flags & ALPM_TRANS_FLAG_NOHOOKS) &&
_alpm_hook_run(handle, ALPM_HOOK_PRE_TRANSACTION) != 0) {
RET_ERR(handle, ALPM_ERR_TRANS_HOOK_FAILED, -1);
}
@@ -232,7 +233,10 @@ int SYMEXPORT alpm_trans_commit(alpm_handle_t *handle, alpm_list_t **data)
event.type = ALPM_EVENT_TRANSACTION_DONE;
EVENT(handle, (void *)&event);
alpm_logaction(handle, ALPM_CALLER_PREFIX, "transaction completed\n");
_alpm_hook_run(handle, ALPM_HOOK_POST_TRANSACTION);
if(!(trans->flags & ALPM_TRANS_FLAG_NOHOOKS)) {
_alpm_hook_run(handle, ALPM_HOOK_POST_TRANSACTION);
}
}
trans->state = STATE_COMMITED;

View File

@@ -36,7 +36,7 @@ typedef enum _alpm_transstate_t {
} alpm_transstate_t;
/* Transaction */
struct __alpm_trans_t {
typedef struct _alpm_trans_t {
/* bitfield of alpm_transflag_t flags */
int flags;
alpm_transstate_t state;
@@ -44,7 +44,7 @@ struct __alpm_trans_t {
alpm_list_t *add; /* list of (alpm_pkg_t *) */
alpm_list_t *remove; /* list of (alpm_pkg_t *) */
alpm_list_t *skip_remove; /* list of (char *) */
};
} alpm_trans_t;
void _alpm_trans_free(alpm_trans_t *trans);
/* flags is a bitfield of alpm_transflag_t flags */

View File

@@ -42,6 +42,7 @@ LOCKFILE=
CLEAN_LOCK=0
USE_COLOR='y'
PREVENT_DOWNGRADE=0
INCLUDE_SIGS=0
# Import libmakepkg
source "$LIBRARY"/util/compress.sh
@@ -260,7 +261,7 @@ db_write_entry() {
fi
# compute base64'd PGP signature
if [[ -f "$pkgfile.sig" ]]; then
if (( INCLUDE_SIGS )) && [[ -f "$pkgfile.sig" ]]; then
if grep -q 'BEGIN PGP SIGNATURE' "$pkgfile.sig"; then
error "$(gettext "Cannot use armored signatures for packages: %s")" "$pkgfile.sig"
return 1
@@ -622,6 +623,9 @@ while (( $# )); do
-p|--prevent-downgrade)
PREVENT_DOWNGRADE=1
;;
--include-sigs)
INCLUDE_SIGS=1
;;
*)
args+=("$1")
;;

View File

@@ -541,12 +541,12 @@ void cb_question(void *ctx, alpm_question_t *question)
{
alpm_question_import_key_t *q = &question->import_key;
/* the uid is unknown with db signatures */
if (q->key->uid == NULL) {
if (q->uid == NULL) {
q->import = yesno(_("Import PGP key %s?"),
q->key->fingerprint);
q->fingerprint);
} else {
q->import = yesno(_("Import PGP key %s, \"%s\"?"),
q->key->fingerprint, q->key->uid);
q->fingerprint, q->uid);
}
}
break;

View File

@@ -83,6 +83,7 @@ typedef struct __config_t {
unsigned short op_q_upgrade;
unsigned short op_q_check;
unsigned short op_q_locality;
unsigned short op_q_backup;
unsigned short op_s_clean;
unsigned short op_s_downloadonly;
@@ -180,6 +181,7 @@ enum {
OP_DBPATH,
OP_CASCADE,
OP_CHANGELOG,
OP_BACKUP,
OP_CLEAN,
OP_NODEPS,
OP_DEPS,

View File

@@ -348,7 +348,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
/* Print additional package info if info flag passed more than once */
if(from == ALPM_PKG_FROM_LOCALDB && extra) {
dump_pkg_backups(pkg);
dump_backup_status(pkg);
}
/* final newline to separate packages */
@@ -359,6 +359,34 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
alpm_list_free(validation);
}
static int get_backup_file_changed(const char *root,
const alpm_backup_t *backup)
{
char path[PATH_MAX];
int ret = 0;
snprintf(path, PATH_MAX, "%s%s", root, backup->name);
/* if we find the file, calculate checksums, otherwise it is missing */
if(access(path, R_OK) == 0) {
char *md5sum = alpm_compute_md5sum(path);
if(md5sum == NULL) {
pm_printf(ALPM_LOG_ERROR,
_("could not calculate checksums for %s\n"), path);
return 0;
}
/* if checksums don't match, file has been modified */
ret = strcmp(md5sum, backup->hash) != 0;
free(md5sum);
} else if(errno != ENOENT) {
pm_printf(ALPM_LOG_ERROR,
_("could not read %s: %s\n"), path, strerror(errno));
}
return ret;
}
static const char *get_backup_file_status(const char *root,
const alpm_backup_t *backup)
{
@@ -401,7 +429,7 @@ static const char *get_backup_file_status(const char *root,
/* Display list of backup files and their modification states
*/
void dump_pkg_backups(alpm_pkg_t *pkg)
void dump_backup_status(alpm_pkg_t *pkg)
{
alpm_list_t *i;
const char *root = alpm_option_get_root(config->handle);
@@ -450,6 +478,32 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet)
fflush(stdout);
}
void dump_pkg_backups(alpm_pkg_t *pkg, int quiet, int all)
{
const char *pkgname, *root;
alpm_list_t *backups;
alpm_list_t *i;
pkgname = alpm_pkg_get_name(pkg);
backups = alpm_pkg_get_backup(pkg);
root = alpm_option_get_root(config->handle);
for(i = backups; i; i = i->next) {
alpm_backup_t *backup = i->data;
if(!all && backup->hash && !get_backup_file_changed(root, backup)) {
continue;
}
if(!quiet) {
printf("%s%s%s ", config->colstr.title, pkgname, config->colstr.nocolor);
}
printf("%s%s\n", root, backup->name);
}
fflush(stdout);
}
/* Display the changelog of a package
*/
void dump_pkg_changelog(alpm_pkg_t *pkg)

View File

@@ -24,7 +24,8 @@
void dump_pkg_full(alpm_pkg_t *pkg, int extra);
void dump_pkg_backups(alpm_pkg_t *pkg);
void dump_backup_status(alpm_pkg_t *pkg);
void dump_pkg_backups(alpm_pkg_t *pkg, int quiet, int all);
void dump_pkg_files(alpm_pkg_t *pkg, int quiet);
void dump_pkg_changelog(alpm_pkg_t *pkg);

View File

@@ -150,6 +150,7 @@ static void usage(int op, const char * const myname)
addlist(_(" -t, --unrequired list packages not (optionally) required by any\n"
" package (-tt to ignore optdepends) [filter]\n"));
addlist(_(" -u, --upgrades list outdated packages [filter]\n"));
addlist(_(" -w, --backup list modified backup files of a package (-xx for all backup files)\n"));
} else if(op == PM_OP_SYNC) {
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
printf("%s:\n", str_opt);
@@ -516,6 +517,10 @@ static int parsearg_query(int opt)
case 'c':
config->op_q_changelog = 1;
break;
case OP_BACKUP:
case 'w':
(config->op_q_backup)++;
break;
case OP_DEPS:
case 'd':
config->op_q_deps = 1;
@@ -583,6 +588,7 @@ static void checkargs_query_display_opts(const char *opname) {
invalid_opt(config->op_q_check, opname, "--check");
invalid_opt(config->op_q_info, opname, "--info");
invalid_opt(config->op_q_list, opname, "--list");
invalid_opt(config->op_q_backup, opname, "--backup");
}
static void checkargs_query_filter_opts(const char *opname) {
@@ -634,6 +640,7 @@ static int parsearg_trans(int opt)
case OP_DBONLY:
config->flags |= ALPM_TRANS_FLAG_DBONLY;
config->flags |= ALPM_TRANS_FLAG_NOSCRIPTLET;
config->flags |= ALPM_TRANS_FLAG_NOHOOKS;
break;
case OP_NOPROGRESSBAR:
config->noprogressbar = 1;
@@ -895,6 +902,7 @@ static int parseargs(int argc, char *argv[])
{"dbpath", required_argument, 0, OP_DBPATH},
{"cascade", no_argument, 0, OP_CASCADE},
{"changelog", no_argument, 0, OP_CHANGELOG},
{"backup", no_argument, 0, OP_BACKUP},
{"clean", no_argument, 0, OP_CLEAN},
{"nodeps", no_argument, 0, OP_NODEPS},
{"deps", no_argument, 0, OP_DEPS},

View File

@@ -315,6 +315,9 @@ static int display(alpm_pkg_t *pkg)
if(config->op_q_list) {
dump_pkg_files(pkg, config->quiet);
}
if(config->op_q_backup) {
dump_pkg_backups(pkg, config->quiet, config->op_q_backup != 1);
}
if(config->op_q_changelog) {
dump_pkg_changelog(pkg);
}
@@ -325,8 +328,8 @@ static int display(alpm_pkg_t *pkg)
ret = check_pkg_full(pkg);
}
}
if(!config->op_q_info && !config->op_q_list
&& !config->op_q_changelog && !config->op_q_check) {
if(!config->op_q_info && !config->op_q_list && !config->op_q_changelog
&& !config->op_q_check && !config->op_q_backup) {
if(!config->quiet) {
const colstr_t *colstr = &config->colstr;
printf("%s%s %s%s%s", colstr->title, alpm_pkg_get_name(pkg),
@@ -431,7 +434,7 @@ int pacman_query(alpm_list_t *targets)
db_local = alpm_get_localdb(config->handle);
/* operations on all packages in the local DB
* valid: no-op (plain -Q), list, info, check
* valid: no-op (plain -Q), list, info, check, backup
* invalid: isfile, owns */
if(targets == NULL) {
if(config->op_q_isfile || config->op_q_owns) {