[pacman-dev] [PATCH 07/23] doc: document callbacks

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 439 -
 1 file changed, 271 insertions(+), 168 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ea99a8b3..a8d48432 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -617,105 +617,12 @@ void alpm_conflict_free(alpm_conflict_t *conflict);
 /* End of alpm_depends */
 /** @} */
 
-/*
- * Enumerations
- * These ones are used in multiple contexts, so are forward-declared.
- */
-
-/** Package install reasons. */
-typedef enum _alpm_pkgreason_t {
-   /** Explicitly requested by the user. */
-   ALPM_PKG_REASON_EXPLICIT = 0,
-   /** Installed as a dependency for another package. */
-   ALPM_PKG_REASON_DEPEND = 1
-} alpm_pkgreason_t;
-
-/** Location a package object was loaded from. */
-typedef enum _alpm_pkgfrom_t {
-   ALPM_PKG_FROM_FILE = 1,
-   ALPM_PKG_FROM_LOCALDB,
-   ALPM_PKG_FROM_SYNCDB
-} alpm_pkgfrom_t;
-
-/** Method used to validate a package. */
-typedef enum _alpm_pkgvalidation_t {
-   ALPM_PKG_VALIDATION_UNKNOWN = 0,
-   ALPM_PKG_VALIDATION_NONE = (1 << 0),
-   ALPM_PKG_VALIDATION_MD5SUM = (1 << 1),
-   ALPM_PKG_VALIDATION_SHA256SUM = (1 << 2),
-   ALPM_PKG_VALIDATION_SIGNATURE = (1 << 3)
-} alpm_pkgvalidation_t;
-
-/*
- * Structures
- */
-
-/** Package group */
-typedef struct _alpm_group_t {
-   /** group name */
-   char *name;
-   /** list of alpm_pkg_t packages */
-   alpm_list_t *packages;
-} alpm_group_t;
 
-/** File in a package */
-typedef struct _alpm_file_t {
-   char *name;
-   off_t size;
-   mode_t mode;
-} alpm_file_t;
-
-/** Package filelist container */
-typedef struct _alpm_filelist_t {
-   size_t count;
-   alpm_file_t *files;
-} alpm_filelist_t;
-
-/** Local package or package file backup entry */
-typedef struct _alpm_backup_t {
-   char *name;
-   char *hash;
-} alpm_backup_t;
-
-/*
- * Hooks
- */
-
-typedef enum _alpm_hook_when_t {
-   ALPM_HOOK_PRE_TRANSACTION = 1,
-   ALPM_HOOK_POST_TRANSACTION
-} alpm_hook_when_t;
-
-/*
- * Logging facilities
- */
-
-/** \addtogroup alpm_log Logging Functions
- * @brief Functions to log using libalpm
+/** \addtogroup alpm_cb Callbacks
+ * @brief Functions and structures for libalpm's callbacks
  * @{
  */
 
-/** Logging Levels */
-typedef enum _alpm_loglevel_t {
-   ALPM_LOG_ERROR= 1,
-   ALPM_LOG_WARNING  = (1 << 1),
-   ALPM_LOG_DEBUG= (1 << 2),
-   ALPM_LOG_FUNCTION = (1 << 3)
-} alpm_loglevel_t;
-
-typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
-
-/** A printf-like function for logging.
- * @param handle the context handle
- * @param prefix caller-specific prefix for the log
- * @param fmt output format
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int alpm_logaction(alpm_handle_t *handle, const char *prefix,
-   const char *fmt, ...) __attribute__((format(printf, 3, 4)));
-
-/** @} */
-
 /**
  * Type of events.
  */
@@ -790,7 +697,7 @@ typedef enum _alpm_event_type_t {
/** A .pacnew file was created; See alpm_event_pacnew_created_t for 
arguments. */
ALPM_EVENT_PACNEW_CREATED,
/** A .pacsave file was created; See alpm_event_pacsave_created_t for
-* arguments */
+* arguments. */
ALPM_EVENT_PACSAVE_CREATED,
/** Processing hooks will be started. */
ALPM_EVENT_HOOK_START,
@@ -798,100 +705,123 @@ typedef enum _alpm_event_type_t {
ALPM_EVENT_HOOK_DONE,
/** A hook is starting */
ALPM_EVENT_HOOK_RUN_START,
-   /** A hook has finished running */
+   /** A hook has finished running. */
ALPM_EVENT_HOOK_RUN_DONE
 } alpm_event_type_t;
 
+/** An event that may reprisent any event. */
 typedef struct _alpm_event_any_t {
-   /** Type of event. */
+   /** Type of event */
alpm_event_type_t type;
 } alpm_event_any_t;
 
+/** An enum over the kind of package operations. */
 typedef enum _alpm_package_operation_t {
/** Package (to be) installed. (No oldpkg) */
ALPM_PACKAGE_INSTALL = 1,
/** Package (to be) upgraded */
ALPM_PACKAGE_UPGRADE,
-   /** Package (to be) re-installed. */
+   /** Package (to be) re-installed */
ALPM_PACKAGE_REINSTALL,
-   /** Package (to be) downgraded. */
+   /** Package (to be) downgraded */
ALPM_PACKAGE_DOWNGRADE,
-   /** Package (to be) removed. (No newpkg) */
+   /** Package (to be) removed (No newpkg) */
ALPM_PACKAGE_REMOVE
 } alpm_package_operation_t;
 
+/** A package operation event occurred. */
 typedef struct _alpm_event_package_operation_t {
-   /** Type of event. */
+   /** Type of event */
alpm_event_type_t type;
-   /** Type of operation. */
+   /** Type of operation */
alpm_package_operation_t operation;
-   /** Old package. */
+   /** Old package */
alpm_pkg_t *oldpkg;
-   /** New 

[pacman-dev] [PATCH 08/23] doc: document databases

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 468 -
 1 file changed, 249 insertions(+), 219 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a8d48432..c71c275f 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -94,6 +94,38 @@ typedef struct __alpm_pkg_t alpm_pkg_t;
 /** Transaction structure used internally by libalpm */
 typedef struct __alpm_trans_t alpm_trans_t;
 
+/*
+ * Structures
+ */
+
+/** Package group */
+typedef struct _alpm_group_t {
+   /** group name */
+   char *name;
+   /** list of alpm_pkg_t packages */
+   alpm_list_t *packages;
+} alpm_group_t;
+
+/** File in a package */
+typedef struct _alpm_file_t {
+   char *name;
+   off_t size;
+   mode_t mode;
+} alpm_file_t;
+
+/** Package filelist container */
+typedef struct _alpm_filelist_t {
+   size_t count;
+   alpm_file_t *files;
+} alpm_filelist_t;
+
+/** Local package or package file backup entry */
+typedef struct _alpm_backup_t {
+   char *name;
+   char *hash;
+} alpm_backup_t;
+
+
 
 /** @addtogroup alpm_api ALPM
  * @brief The libalpm Public API
@@ -1123,6 +1155,223 @@ typedef int (*alpm_cb_fetch)(const char *url, const 
char *localpath,
 /** @} */
 
 
+/** @addtogroup alpm_databases Database
+ * @brief Functions to query and manipulate the database of libalpm.
+ * @{
+ */
+
+/** Get the database of locally installed packages.
+ * The returned pointer points to an internal structure
+ * of libalpm which should only be manipulated through
+ * libalpm functions.
+ * @return a reference to the local database
+ */
+alpm_db_t *alpm_get_localdb(alpm_handle_t *handle);
+
+/** Get the list of sync databases.
+ * Returns a list of alpm_db_t structures, one for each registered
+ * sync database.
+ *
+ * @param handle the context handle
+ * @return a reference to an internal list of alpm_db_t structures
+ */
+alpm_list_t *alpm_get_syncdbs(alpm_handle_t *handle);
+
+/** Register a sync database of packages.
+ * Databases can not be registered when there is an active transaction.
+ *
+ * @param handle the context handle
+ * @param treename the name of the sync repository
+ * @param level what level of signature checking to perform on the
+ * database; note that this must be a '.sig' file type verification
+ * @return an alpm_db_t* on success (the value), NULL on error
+ */
+alpm_db_t *alpm_register_syncdb(alpm_handle_t *handle, const char *treename,
+   int level);
+
+/** Unregister all package databases.
+ * Databases can not be unregistered while there is an active transaction.
+ *
+ * @param handle the context handle
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int alpm_unregister_all_syncdbs(alpm_handle_t *handle);
+
+/** Unregister a package database.
+ * Databases can not be unregistered when there is an active transaction.
+ *
+ * @param db pointer to the package database to unregister
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int alpm_db_unregister(alpm_db_t *db);
+
+/** Get the name of a package database.
+ * @param db pointer to the package database
+ * @return the name of the package database, NULL on error
+ */
+const char *alpm_db_get_name(const alpm_db_t *db);
+
+/** Get the signature verification level for a database.
+ * Will return the default verification level if this database is set up
+ * with ALPM_SIG_USE_DEFAULT.
+ * @param db pointer to the package database
+ * @return the signature verification level
+ */
+int alpm_db_get_siglevel(alpm_db_t *db);
+
+/** Check the validity of a database.
+ * This is most useful for sync databases and verifying signature status.
+ * If invalid, the handle error code will be set accordingly.
+ * @param db pointer to the package database
+ * @return 0 if valid, -1 if invalid (pm_errno is set accordingly)
+ */
+int alpm_db_get_valid(alpm_db_t *db);
+
+/** @name Server accessors
+ * @{
+ */
+
+/** Get the list of servers assigned to this db.
+ * @param db pointer to the database to get the servers from
+ * @return a char* list of servers
+ */
+alpm_list_t *alpm_db_get_servers(const alpm_db_t *db);
+
+/** Sets the list of servers for the database to use.
+ * @param db the database to set the servers
+ * @param servers a char* list of servers. Note: the database will
+ * take ownership of the list and it should no longer be
+ * freed by the caller
+ */
+int alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers);
+
+/** Add a download server to a database.
+ * @param db database pointer
+ * @param url url of the server
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int alpm_db_add_server(alpm_db_t *db, const char *url);
+
+/** Remove a download server from a database.
+ * @param db database pointer
+ * @param url url of the server
+ * @return 0 on success, 1 on server not present,
+ * -1 on error (pm_errno is set accordingly)
+ */
+int alpm_db_remove_server(alpm_db_t *db, const char *url);
+

[pacman-dev] [PATCH 12/23] doc: document transactions

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 35 +++
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 30bfb06d..76ae5722 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -2068,18 +2068,26 @@ int alpm_pkg_mtree_close(const alpm_pkg_t *pkg, struct 
archive *archive);
 /* End of alpm_packages */
 /** @} */
 
-
-/*
- * Sync
- */
-
 /** Check for new version of pkg in sync repos
  * (only the first occurrence is considered in sync)
  */
 alpm_pkg_t *alpm_sync_get_new_version(alpm_pkg_t *pkg, alpm_list_t *dbs_sync);
 
-/** @addtogroup alpm_api_trans Transaction Functions
- * Functions to manipulate libalpm transactions
+/** @addtogroup alpm_trans Transaction
+ * @brief Functions to manipulate libalpm transactions
+ *
+ * Transactions are the way to add/remove packages to/from the system.
+ * Only one transaction can exist at a time.
+ *
+ * The basic workflow of a transaction is to:
+ *
+ * - Initialize with \link alpm_trans_init \endlink
+ * - Choose which packages to add with \link alpm_add_pkg \endlink and \link 
alpm_remove_pkg \endlink
+ * - Prepare the transaction with \link alpm_trans_prepare \endlink
+ * - Commit the transaction with \link alpm_trans_commit \endlink
+ * - Release the transaction with \link alpm_trans_release \endlink
+ *
+ * A transaction can be released at any time. A transaction does not have to 
be committed.
  * @{
  */
 
@@ -2172,10 +2180,11 @@ int alpm_trans_interrupt(alpm_handle_t *handle);
  * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
 int alpm_trans_release(alpm_handle_t *handle);
-/** @} */
 
-/** @name Common Transactions */
-/** @{ */
+/** @name Add/Remove packages
+ * These functions remove/add packages to the transactions
+ * @{
+ * */
 
 /** Search for packages to upgrade and add them to the transaction.
  * @param handle the context handle
@@ -2186,22 +2195,24 @@ int alpm_sync_sysupgrade(alpm_handle_t *handle, int 
enable_downgrade);
 
 /** Add a package to the transaction.
  * If the package was loaded by alpm_pkg_load(), it will be freed upon
- * alpm_trans_release() invocation.
+ * \link alpm_trans_release \endlink invocation.
  * @param handle the context handle
  * @param pkg the package to add
  * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
 int alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg);
 
-/** Add a package removal action to the transaction.
+/** Add a package removal to the transaction.
  * @param handle the context handle
  * @param pkg the package to uninstall
  * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
 int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg);
 
+/* End of add/remove packages */
 /** @} */
 
+/* End of alpm_trans */
 /** @} */
 
 /*
-- 
2.29.2


[pacman-dev] [PATCH 15/23] doc: document options

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 592 ++---
 1 file changed, 564 insertions(+), 28 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 494a8319..05dec6c7 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1453,186 +1453,722 @@ int alpm_logaction(alpm_handle_t *handle, const char 
*prefix,
 /** @} */
 
 
-/** @addtogroup alpm_api_options Options
+/** @addtogroup alpm_options Options
  * Libalpm option getters and setters
  * @{
  */
 
-/** Returns the callback used for logging. */
+/** @name Accessors for callbacks
+ * @{
+ */
+
+/** Returns the callback used for logging.
+ * @param handle the context handle
+ * @return the currently set log callback
+ */
 alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle);
-/** Sets the callback used for logging. */
+
+/** Sets the callback used for logging. 
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb);
 
-/** Returns the callback used to report download progress. */
+/** Returns the callback used to report download progress. 
+ * @param handle the context handle
+ * @return the currently set download callback
+ */
 alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle);
-/** Sets the callback used to report download progress. */
+
+/** Sets the callback used to report download progress.
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb);
 
-/** Returns the downloading callback. */
+/** Returns the downloading callback.
+ * @param handle the context handle
+ * @return the currently set fetch callback
+ */
 alpm_cb_fetch alpm_option_get_fetchcb(alpm_handle_t *handle);
-/** Sets the downloading callback. */
+
+/** Sets the downloading callback.
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_fetchcb(alpm_handle_t *handle, alpm_cb_fetch cb);
 
-/** Returns the callback used to report total download size. */
+/** Returns the callback used to report total download size. 
+ * @param handle the context handle
+ * @return the currently set total download callback
+ */
 alpm_cb_totaldl alpm_option_get_totaldlcb(alpm_handle_t *handle);
-/** Sets the callback used to report total download size. */
+
+/** Sets the callback used to report total download size.
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_totaldlcb(alpm_handle_t *handle, alpm_cb_totaldl cb);
 
-/** Returns the callback used for events. */
+
+/** Returns the callback used for events.
+ * @param handle the context handle
+ * @return the currently set event callback
+ */
 alpm_cb_event alpm_option_get_eventcb(alpm_handle_t *handle);
-/** Sets the callback used for events. */
+
+/** Sets the callback used for events.
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_eventcb(alpm_handle_t *handle, alpm_cb_event cb);
 
-/** Returns the callback used for questions. */
+/** Returns the callback used for questions.
+ * @param handle the context handle
+ * @return the currently set question callback
+ */
 alpm_cb_question alpm_option_get_questioncb(alpm_handle_t *handle);
-/** Sets the callback used for questions. */
+
+/** Sets the callback used for questions.
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_questioncb(alpm_handle_t *handle, alpm_cb_question cb);
 
-/** Returns the callback used for operation progress. */
+
+/**Returns the callback used for operation progress.
+ * @param handle the context handle
+ * @return the currently set progress callback
+ */
 alpm_cb_progress alpm_option_get_progresscb(alpm_handle_t *handle);
-/** Sets the callback used for operation progress. */
+
+/** Sets the callback used for operation progress.
+ * @param handle the context handle
+ * @param cb the cb to use
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
 int alpm_option_set_progresscb(alpm_handle_t *handle, alpm_cb_progress cb);
+/* End of callback accessors */
+/** @} */
+
+
+/** @name Accessors to the root directory
+ *
+ * The root directory is the prefix to which libalpm installs packages to.
+ * Hooks and scriptlets will also be run in a chroot to ensure they behave 
correctly
+ * in alternative roots.
+ * @{
+ */
 
-/** Returns the root of the destination filesystem. Read-only. */
+/** Returns the root path. Read-only.
+ * @param handle the context handle
+ */
 const char 

[pacman-dev] [PATCH 06/23] doc: document depends

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 295 +
 1 file changed, 164 insertions(+), 131 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 43a47d54..ea99a8b3 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -441,49 +441,26 @@ int alpm_extract_keyid(alpm_handle_t *handle, const char 
*identifier,
 /** @} */
 
 
-/*
- * Enumerations
- * These ones are used in multiple contexts, so are forward-declared.
+/** @addtogroup alpm_depends Dependency
+ * @brief Functions dealing with libalpm's dependency and conflict
+ * information.
+ * @{
  */
 
-/** Package install reasons. */
-typedef enum _alpm_pkgreason_t {
-   /** Explicitly requested by the user. */
-   ALPM_PKG_REASON_EXPLICIT = 0,
-   /** Installed as a dependency for another package. */
-   ALPM_PKG_REASON_DEPEND = 1
-} alpm_pkgreason_t;
-
-/** Location a package object was loaded from. */
-typedef enum _alpm_pkgfrom_t {
-   ALPM_PKG_FROM_FILE = 1,
-   ALPM_PKG_FROM_LOCALDB,
-   ALPM_PKG_FROM_SYNCDB
-} alpm_pkgfrom_t;
-
-/** Method used to validate a package. */
-typedef enum _alpm_pkgvalidation_t {
-   ALPM_PKG_VALIDATION_UNKNOWN = 0,
-   ALPM_PKG_VALIDATION_NONE = (1 << 0),
-   ALPM_PKG_VALIDATION_MD5SUM = (1 << 1),
-   ALPM_PKG_VALIDATION_SHA256SUM = (1 << 2),
-   ALPM_PKG_VALIDATION_SIGNATURE = (1 << 3)
-} alpm_pkgvalidation_t;
-
 /** Types of version constraints in dependency specs. */
 typedef enum _alpm_depmod_t {
-   /** No version constraint */
-   ALPM_DEP_MOD_ANY = 1,
-   /** Test version equality (package=x.y.z) */
-   ALPM_DEP_MOD_EQ,
-   /** Test for at least a version (package>=x.y.z) */
-   ALPM_DEP_MOD_GE,
-   /** Test for at most a version (package<=x.y.z) */
-   ALPM_DEP_MOD_LE,
-   /** Test for greater than some version (package>x.y.z) */
-   ALPM_DEP_MOD_GT,
-   /** Test for less than some version (package=x.y.z) */
+ALPM_DEP_MOD_GE,
+/** Test for at most a version (package<=x.y.z) */
+ALPM_DEP_MOD_LE,
+/** Test for greater than some version (package>x.y.z) */
+ALPM_DEP_MOD_GT,
+/** Test for less than some version (package=2.12"
+ */
+char *alpm_dep_compute_string(const alpm_depend_t *dep);
+
+/** Return a newly allocated dependency information parsed from a string
+ *\link alpm_dep_free should be used to free the dependency \endlink
+ * @param depstring a formatted string, e.g. "glibc=2.12"
+ * @return a dependency info structure
+ */
+alpm_depend_t *alpm_dep_from_string(const char *depstring);
+
+/** Free a dependency info structure
+ * @param dep struct to free
+ */
+void alpm_dep_free(alpm_depend_t *dep);
+
+/** Free a fileconflict and its members.
+ * @param conflict the fileconflict to free
+ */
+void alpm_fileconflict_free(alpm_fileconflict_t *conflict);
+
+/** Free a depmissing and its members
+ * @param miss the depmissing to fre 
+ * */
+void alpm_depmissing_free(alpm_depmissing_t *miss);
+
+/**
+ * Free a conflict and its members.
+ * @param conflict the conflict to free
+ */
+void alpm_conflict_free(alpm_conflict_t *conflict);
+
+
+/* End of alpm_depends */
+/** @} */
+
+/*
+ * Enumerations
+ * These ones are used in multiple contexts, so are forward-declared.
+ */
+
+/** Package install reasons. */
+typedef enum _alpm_pkgreason_t {
+   /** Explicitly requested by the user. */
+   ALPM_PKG_REASON_EXPLICIT = 0,
+   /** Installed as a dependency for another package. */
+   ALPM_PKG_REASON_DEPEND = 1
+} alpm_pkgreason_t;
+
+/** Location a package object was loaded from. */
+typedef enum _alpm_pkgfrom_t {
+   ALPM_PKG_FROM_FILE = 1,
+   ALPM_PKG_FROM_LOCALDB,
+   ALPM_PKG_FROM_SYNCDB
+} alpm_pkgfrom_t;
+
+/** Method used to validate a package. */
+typedef enum _alpm_pkgvalidation_t {
+   ALPM_PKG_VALIDATION_UNKNOWN = 0,
+   ALPM_PKG_VALIDATION_NONE = (1 << 0),
+   ALPM_PKG_VALIDATION_MD5SUM = (1 << 1),
+   ALPM_PKG_VALIDATION_SHA256SUM = (1 << 2),
+   ALPM_PKG_VALIDATION_SIGNATURE = (1 << 3)
+} alpm_pkgvalidation_t;
+
+/*
+ * Structures
+ */
+
 /** Package group */
 typedef struct _alpm_group_t {
/** group name */
@@ -1900,76 +2016,6 @@ int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t 
*pkg);
 
 /** @} */
 
-/** @addtogroup alpm_api_depends Dependency Functions
- * Functions dealing with libalpm representation of dependency
- * information.
- * @{
- */
-
-/** Checks dependencies and returns missing ones in a list.
- * Dependencies can include versions with depmod operators.
- * @param handle the context handle
- * @param pkglist the list of local packages
- * @param remove an alpm_list_t* of packages to be removed
- * @param upgrade an alpm_list_t* of packages to be upgraded 
(remove-then-upgrade)
- * @param reversedeps handles the backward dependencies
- * @return an alpm_list_t* of alpm_depmissing_t pointers.
- */
-alpm_list_t *alpm_checkdeps(alpm_handle_t *handle, 

[pacman-dev] [PATCH 09/23] doc: document logging

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index c71c275f..ea690abc 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1412,13 +1412,27 @@ typedef enum _alpm_pkgvalidation_t {
 
 /** Logging Levels */
 typedef enum _alpm_loglevel_t {
-   ALPM_LOG_ERROR= 1,
-   ALPM_LOG_WARNING  = (1 << 1),
-   ALPM_LOG_DEBUG= (1 << 2),
-   ALPM_LOG_FUNCTION = (1 << 3)
+   /** Error */
+   ALPM_LOG_ERROR= 1,
+   /** Warning */
+   ALPM_LOG_WARNING  = (1 << 1),
+   /** Debug */
+   ALPM_LOG_DEBUG= (1 << 2),
+   /** Function */
+   ALPM_LOG_FUNCTION = (1 << 3)
 } alpm_loglevel_t;
 
-typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list);
+
+/** The callback type for logging.
+ *
+ * libalpm will call this function whenever something is to be logged.
+ * many libalpm will produce log output. Additionally any calls to \link 
alpm_logaction
+ * \endlink will also call this callback.
+ * @param level the currently set loglevel
+ * @param fmt the printf like format string
+ * @param args printf like arguments
+ */
+typedef void (*alpm_cb_log)(alpm_loglevel_t level, const char *fmt, va_list 
args);
 
 /** A printf-like function for logging.
  * @param handle the context handle
@@ -1429,6 +1443,7 @@ typedef void (*alpm_cb_log)(alpm_loglevel_t, const char 
*, va_list);
 int alpm_logaction(alpm_handle_t *handle, const char *prefix,
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
 
+/* End of alpm_log */
 /** @} */
 
 /** Fetch a list of remote packages.
-- 
2.29.2


[pacman-dev] [PATCH 14/23] doc: document alpm_list

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm_list.c | 251 -
 lib/libalpm/alpm_list.h | 299 +++-
 2 files changed, 295 insertions(+), 255 deletions(-)

diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index fe0c2906..2ecc8e0b 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -32,23 +32,8 @@
 #define SYMEXPORT __attribute__((visibility("default")))
 #define SYMHIDDEN __attribute__((visibility("internal")))
 
-/**
- * @addtogroup alpm_list List Functions
- * @brief Functions to manipulate alpm_list_t lists.
- *
- * These functions are designed to create, destroy, and modify lists of
- * type alpm_list_t. This is an internal list type used by libalpm that is
- * publicly exposed for use by frontends if desired.
- *
- * @{ */
-
 /* Allocation */
 
-/**
- * @brief Free a list, but not the contained data.
- *
- * @param list the list to free
- */
 void SYMEXPORT alpm_list_free(alpm_list_t *list)
 {
alpm_list_t *it = list;
@@ -60,12 +45,6 @@ void SYMEXPORT alpm_list_free(alpm_list_t *list)
}
 }
 
-/**
- * @brief Free the internal data of a list structure.
- *
- * @param list the list to free
- * @param fn   a free function for the internal data
- */
 void SYMEXPORT alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn)
 {
alpm_list_t *it = list;
@@ -83,28 +62,12 @@ void SYMEXPORT alpm_list_free_inner(alpm_list_t *list, 
alpm_list_fn_free fn)
 
 /* Mutators */
 
-/**
- * @brief Add a new item to the end of the list.
- *
- * @param list the list to add to
- * @param data the new item to be added to the list
- *
- * @return the resultant list
- */
 alpm_list_t SYMEXPORT *alpm_list_add(alpm_list_t *list, void *data)
 {
alpm_list_append(, data);
return list;
 }
 
-/**
- * @brief Add a new item to the end of the list.
- *
- * @param list the list to add to
- * @param data the new item to be added to the list
- *
- * @return the newly added item
- */
 alpm_list_t SYMEXPORT *alpm_list_append(alpm_list_t **list, void *data)
 {
alpm_list_t *ptr;
@@ -131,14 +94,6 @@ alpm_list_t SYMEXPORT *alpm_list_append(alpm_list_t **list, 
void *data)
return ptr;
 }
 
-/**
- * @brief Duplicate and append a string to a list.
- *
- * @param list the list to append to
- * @param data the string to duplicate and append
- *
- * @return the newly added item
- */
 alpm_list_t SYMEXPORT *alpm_list_append_strdup(alpm_list_t **list, const char 
*data)
 {
alpm_list_t *ret;
@@ -151,15 +106,6 @@ alpm_list_t SYMEXPORT *alpm_list_append_strdup(alpm_list_t 
**list, const char *d
}
 }
 
-/**
- * @brief Add items to a list in sorted order.
- *
- * @param list the list to add to
- * @param data the new item to be added to the list
- * @param fn   the comparison function to use to determine order
- *
- * @return the resultant list
- */
 alpm_list_t SYMEXPORT *alpm_list_add_sorted(alpm_list_t *list, void *data, 
alpm_list_fn_cmp fn)
 {
if(!fn || !list) {
@@ -202,17 +148,6 @@ alpm_list_t SYMEXPORT *alpm_list_add_sorted(alpm_list_t 
*list, void *data, alpm_
}
 }
 
-/**
- * @brief Join two lists.
- * The two lists must be independent. Do not free the original lists after
- * calling this function, as this is not a copy operation. The list pointers
- * passed in should be considered invalid after calling this function.
- *
- * @param first  the first list
- * @param second the second list
- *
- * @return the resultant joined list
- */
 alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, alpm_list_t *second)
 {
alpm_list_t *tmp;
@@ -235,15 +170,6 @@ alpm_list_t SYMEXPORT *alpm_list_join(alpm_list_t *first, 
alpm_list_t *second)
return first;
 }
 
-/**
- * @brief Merge the two sorted sublists into one sorted list.
- *
- * @param left  the first list
- * @param right the second list
- * @param fncomparison function for determining merge order
- *
- * @return the resultant list
- */
 alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right,
alpm_list_fn_cmp fn)
 {
@@ -305,15 +231,6 @@ alpm_list_t SYMEXPORT *alpm_list_mmerge(alpm_list_t *left, 
alpm_list_t *right,
return newlist;
 }
 
-/**
- * @brief Sort a list of size `n` using mergesort algorithm.
- *
- * @param list the list to sort
- * @param nthe size of the list
- * @param fn   the comparison function for determining order
- *
- * @return the resultant list
- */
 alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, size_t n,
alpm_list_fn_cmp fn)
 {
@@ -339,15 +256,6 @@ alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, 
size_t n,
return list;
 }
 
-/**
- * @brief Remove an item from the list.
- * item is not freed; this is the responsibility of the caller.
- *
- * @param haystack the list to remove the item from
- * @param item the item to remove from the list
- *
- * @return the resultant list
- */
 alpm_list_t SYMEXPORT 

[pacman-dev] [PATCH 19/23] doc: update doxyfile

2020-12-07 Thread morganamilo
---
 doc/Doxyfile.in | 81 +++--
 1 file changed, 59 insertions(+), 22 deletions(-)

diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
index e2101a28..776318da 100644
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -1,4 +1,4 @@
-# Doxyfile 1.8.2
+# Doxyfile 1.8.20
 
 #---
 # Project related configuration options
@@ -10,7 +10,9 @@ PROJECT_BRIEF  = "Arch Linux Package Manager Library"
 PROJECT_LOGO   =
 OUTPUT_DIRECTORY   = @OUTPUT_DIRECTORY@
 CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES= NO
 OUTPUT_LANGUAGE= English
+OUTPUT_TEXT_DIRECTION  = None
 BRIEF_MEMBER_DESC  = YES
 REPEAT_BRIEF   = YES
 ABBREVIATE_BRIEF   = "The $name class" \
@@ -31,36 +33,41 @@ STRIP_FROM_PATH=
 STRIP_FROM_INC_PATH=
 SHORT_NAMES= NO
 JAVADOC_AUTOBRIEF  = YES
+JAVADOC_BANNER = NO
 QT_AUTOBRIEF   = NO
 MULTILINE_CPP_IS_BRIEF = NO
+PYTHON_DOCSTRING   = YES
 INHERIT_DOCS   = YES
 SEPARATE_MEMBER_PAGES  = NO
 TAB_SIZE   = 4
 ALIASES=
-TCL_SUBST  =
 OPTIMIZE_OUTPUT_FOR_C  = YES
 OPTIMIZE_OUTPUT_JAVA   = NO
 OPTIMIZE_FOR_FORTRAN   = NO
 OPTIMIZE_OUTPUT_VHDL   = NO
+OPTIMIZE_OUTPUT_SLICE  = NO
 EXTENSION_MAPPING  =
 MARKDOWN_SUPPORT   = YES
+TOC_INCLUDE_HEADINGS   = 5
 AUTOLINK_SUPPORT   = YES
 BUILTIN_STL_SUPPORT= NO
 CPP_CLI_SUPPORT= NO
 SIP_SUPPORT= NO
 IDL_PROPERTY_SUPPORT   = YES
 DISTRIBUTE_GROUP_DOC   = NO
+GROUP_NESTED_COMPOUNDS = NO
 SUBGROUPING= YES
 INLINE_GROUPED_CLASSES = NO
-INLINE_SIMPLE_STRUCTS  = NO
+INLINE_SIMPLE_STRUCTS  = YES
 TYPEDEF_HIDES_STRUCT   = YES
-SYMBOL_CACHE_SIZE  = 0
 LOOKUP_CACHE_SIZE  = 0
+NUM_PROC_THREADS   = 1
 #---
 # Build related configuration options
 #---
 EXTRACT_ALL= NO
 EXTRACT_PRIVATE= NO
+EXTRACT_PRIV_VIRTUAL   = NO
 EXTRACT_PACKAGE= NO
 EXTRACT_STATIC = NO
 EXTRACT_LOCAL_CLASSES  = YES
@@ -73,7 +80,9 @@ HIDE_IN_BODY_DOCS  = YES
 INTERNAL_DOCS  = NO
 CASE_SENSE_NAMES   = YES
 HIDE_SCOPE_NAMES   = NO
+HIDE_COMPOUND_REFERENCE= NO
 SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC  = NO
 FORCE_LOCAL_INCLUDES   = NO
 INLINE_INFO= YES
 SORT_MEMBER_DOCS   = YES
@@ -95,26 +104,29 @@ FILE_VERSION_FILTER=
 LAYOUT_FILE=
 CITE_BIB_FILES =
 #---
-# configuration options related to warning and progress messages
+# Configuration options related to warning and progress messages
 #---
 QUIET  = NO
 WARNINGS   = YES
 WARN_IF_UNDOCUMENTED   = YES
 WARN_IF_DOC_ERROR  = YES
 WARN_NO_PARAMDOC   = NO
+WARN_AS_ERROR  = NO
 WARN_FORMAT= "$file:$line: $text"
 WARN_LOGFILE   =
 #---
-# configuration options related to the input files
+# Configuration options related to the input files
 #---
-INPUT  = ../lib/libalpm/alpm.h ../lib/libalpm/alpm_list.h
+INPUT  = ../lib/libalpm/alpm.h \
+ ../lib/libalpm/alpm_list.h
 INPUT_ENCODING = UTF-8
 FILE_PATTERNS  =
 RECURSIVE  = NO
 EXCLUDE=
 EXCLUDE_SYMLINKS   = NO
 EXCLUDE_PATTERNS   =
-EXCLUDE_SYMBOLS= _alpm_* __alpm_*
+EXCLUDE_SYMBOLS= _alpm_* \
+ __alpm_*
 EXAMPLE_PATH   =
 EXAMPLE_PATTERNS   = *
 EXAMPLE_RECURSIVE  = NO
@@ -123,8 +135,9 @@ INPUT_FILTER   =
 FILTER_PATTERNS=
 FILTER_SOURCE_FILES= NO
 FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
 #---
-# configuration options related to source browsing
+# Configuration options related to source browsing
 #---
 SOURCE_BROWSER = NO
 INLINE_SOURCES = NO
@@ -132,16 +145,17 @@ STRIP_CODE_COMMENTS= NO
 REFERENCED_BY_RELATION = YES
 REFERENCES_RELATION= YES
 REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS= YES
 USE_HTAGS  = NO
 VERBATIM_HEADERS   = YES
 #---
-# configuration options related to the alphabetical class index
+# Configuration options related to the alphabetical class index
 #---
 ALPHABETICAL_INDEX = NO
 

[pacman-dev] [PATCH 05/23] doc: document signatures

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 282 +++--
 1 file changed, 167 insertions(+), 115 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 178c8f6a..43a47d54 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -265,7 +265,7 @@ alpm_handle_t *alpm_initialize(const char *root, const char 
*dbpath,
  * This should be the last alpm call you make.
  * After this returns, handle should be considered invalid and cannot be reused
  * in any way.
- * @param myhandle the context handle
+ * @param handle the context handle
  * @return 0 on success, -1 on error
  */
 int alpm_release(alpm_handle_t *handle);
@@ -275,6 +275,172 @@ int alpm_release(alpm_handle_t *handle);
 
 typedef int64_t alpm_time_t;
 
+/** @addtogroup alpm_sig Signature checking
+ * @brief Functions to check signatures
+ * @{
+ */
+
+/** PGP signature verification options */
+typedef enum _alpm_siglevel_t {
+   /** Packages require a signature */
+   ALPM_SIG_PACKAGE = (1 << 0),
+   /** Packages do not require a signature,
+* but check packages that do have signatures */
+   ALPM_SIG_PACKAGE_OPTIONAL = (1 << 1),
+   /* Allow packages with signatures that are marginal trust */
+   ALPM_SIG_PACKAGE_MARGINAL_OK = (1 << 2),
+   /** Allow packages with signatues that are unknown trust */
+   ALPM_SIG_PACKAGE_UNKNOWN_OK = (1 << 3),
+
+   /** Databases require a signature */
+   ALPM_SIG_DATABASE = (1 << 10),
+   /** Databases do not require a signature,
+* but check databases that do have signatures */
+   ALPM_SIG_DATABASE_OPTIONAL = (1 << 11),
+   /** Allow databases with signatures that are marginal trust */
+   ALPM_SIG_DATABASE_MARGINAL_OK = (1 << 12),
+   /** Allow databases with signatues that are unknown trust */
+   ALPM_SIG_DATABASE_UNKNOWN_OK = (1 << 13),
+
+   /** The Default siglevel */
+   ALPM_SIG_USE_DEFAULT = (1 << 30)
+} alpm_siglevel_t;
+
+/** PGP signature verification status return codes */
+typedef enum _alpm_sigstatus_t {
+   /** Signature is valid */
+   ALPM_SIGSTATUS_VALID,
+   /** The key has expired */
+   ALPM_SIGSTATUS_KEY_EXPIRED,
+   /** The signature has expired */
+   ALPM_SIGSTATUS_SIG_EXPIRED,
+   /** The key is not in the keyring */
+   ALPM_SIGSTATUS_KEY_UNKNOWN,
+   /** The key has been disabled */
+   ALPM_SIGSTATUS_KEY_DISABLED,
+   /** The signature is invalid */
+   ALPM_SIGSTATUS_INVALID
+} alpm_sigstatus_t;
+
+
+/** The trust level of a PGP key */
+typedef enum _alpm_sigvalidity_t {
+   /** The signature is fully trusted */
+   ALPM_SIGVALIDITY_FULL,
+   /** The signature is marginally trusted */
+   ALPM_SIGVALIDITY_MARGINAL,
+   /** The signature is never trusted */
+   ALPM_SIGVALIDITY_NEVER,
+   /** The signature has unknown trust */
+   ALPM_SIGVALIDITY_UNKNOWN
+} alpm_sigvalidity_t;
+
+/** A PGP key */
+typedef struct _alpm_pgpkey_t {
+   /** The actual key data */
+   void *data;
+   /** The key's fingerprint */
+   char *fingerprint;
+   /** UID of the key */
+   char *uid;
+   /** Name of the key's owner */
+   char *name;
+   /** Email of the key's owner */
+   char *email;
+   /** When the key was created */
+   alpm_time_t created;
+   /** When the key expires */
+   alpm_time_t expires;
+   /** The length of the key */
+   unsigned int length;
+   /** has the key been revoked */
+   unsigned int revoked;
+   /** A character representing the  encryption algorithm used by the 
public key
+*
+* ? = unknown
+* R = RSA
+* D = DSA
+* E = EDDSA
+*/
+   char pubkey_algo;
+} alpm_pgpkey_t;
+
+/**
+ * Signature result. Contains the key, status, and validity of a given
+ * signature.
+ */
+typedef struct _alpm_sigresult_t {
+   /** The key of the signature */
+   alpm_pgpkey_t key;
+   /** The status of the signature */
+   alpm_sigstatus_t status;
+   /** The validity of the signature */
+   alpm_sigvalidity_t validity;
+} alpm_sigresult_t;
+
+/**
+ * Signature list. Contains the number of signatures found and a pointer to an
+ * array of results. The array is of size count.
+ */
+typedef struct _alpm_siglist_t {
+   /** The amount of results in the array */
+   size_t count;
+   /** An array of sigresults */
+   alpm_sigresult_t *results;
+} alpm_siglist_t;
+
+/**
+ * Check the PGP signature for the given package file.
+ * @param pkg the package to check
+ * @param siglist a pointer to storage for signature results
+ * @return a int value : 0 (valid), 1 (invalid), -1 (an error occurred)
+ */
+int alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg, alpm_siglist_t *siglist);
+
+/**
+ * Check the PGP signature for the given database.
+ * @param db the database to check
+ * @param siglist a pointer to storage for signature results

[pacman-dev] [PATCH 18/23] doc: configure doxygen

2020-12-07 Thread morganamilo
- only document public alpm items (alpm_*)
- hide typedef'd structs (_alpm_pkg_t shows as alpm_pkg_t)
- enable inline struct definitions (this stops having a man page for
  every single struct)
---
 doc/Doxyfile.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in
index 78481dd5..e2101a28 100644
--- a/doc/Doxyfile.in
+++ b/doc/Doxyfile.in
@@ -53,7 +53,7 @@ DISTRIBUTE_GROUP_DOC   = NO
 SUBGROUPING= YES
 INLINE_GROUPED_CLASSES = NO
 INLINE_SIMPLE_STRUCTS  = NO
-TYPEDEF_HIDES_STRUCT   = NO
+TYPEDEF_HIDES_STRUCT   = YES
 SYMBOL_CACHE_SIZE  = 0
 LOOKUP_CACHE_SIZE  = 0
 #---
@@ -107,14 +107,14 @@ WARN_LOGFILE   =
 #---
 # configuration options related to the input files
 #---
-INPUT  = ../lib/libalpm/
+INPUT  = ../lib/libalpm/alpm.h ../lib/libalpm/alpm_list.h
 INPUT_ENCODING = UTF-8
 FILE_PATTERNS  =
 RECURSIVE  = NO
 EXCLUDE=
 EXCLUDE_SYMLINKS   = NO
 EXCLUDE_PATTERNS   =
-EXCLUDE_SYMBOLS=
+EXCLUDE_SYMBOLS= _alpm_* __alpm_*
 EXAMPLE_PATH   =
 EXAMPLE_PATTERNS   = *
 EXAMPLE_RECURSIVE  = NO
-- 
2.29.2


[pacman-dev] [PATCH 17/23] doc: move top level items into groups

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 4673f639..e9cc7c85 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -62,6 +62,7 @@ extern "C" {
 /** The libalpm context handle.
  *
  * This struct represents an instance of libalpm.
+ * @ingroup alpm_handle
  */
 typedef struct __alpm_handle_t alpm_handle_t;
 
@@ -81,6 +82,7 @@ typedef struct __alpm_handle_t alpm_handle_t;
  * the user. They will be freed when the database is unregistered.
  *
  * Databases are automatically unregistered when the \link alpm_handle_t 
\endlink is released.
+ * @ingroup alpm_databases
  */
 typedef struct __alpm_db_t alpm_db_t;
 
@@ -93,12 +95,20 @@ typedef struct __alpm_db_t alpm_db_t;
  *
  * Packages can then be queried for metadata or added to a \link alpm_trans_t 
transaction \endlink
  * to be added or removed from the system.
+ * @ingroup alpm_packages
  */
 typedef struct __alpm_pkg_t alpm_pkg_t;
 
-/** Transaction structure used internally by libalpm */
+/** Transaction structure used internally by libalpm 
+ * @ingroup alpm_trans
+ * */
 typedef struct __alpm_trans_t alpm_trans_t;
 
+
+/** The time type used by libalpm. Represents a unix time stamp
+ * @ingroup alpm_misc */
+typedef int64_t alpm_time_t;
+
 /** @addtogroup alpm_files Files
  * @brief Functions for package files
  * @{
@@ -343,7 +353,6 @@ int alpm_release(alpm_handle_t *handle);
 /* End of alpm_handle */
 /** @} */
 
-typedef int64_t alpm_time_t;
 
 /** @addtogroup alpm_sig Signature checking
  * @brief Functions to check signatures
-- 
2.29.2


[pacman-dev] [PATCH 21/23] doc: add extra documentation to the man page

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h  | 10 --
 lib/libalpm/alpm_list.h | 10 ++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a0de9b13..b2772f19 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -50,8 +50,14 @@ extern "C" {
 
 #include 
 
-/** @addtogroup alpm alpm
- * @brief The libalpm Public API
+/** @addtogroup alpm The libalpm Public API
+ *
+ * @section see_also See Also
+ * \b alpm_list(3),
+ * \b alpm-hooks(5),
+ * \b makepkg(8),
+ * \b pacman(8),
+ * \b pacman.conf(5)
  * @{
  */
 
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index 1eac3043..01fa092c 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -24,6 +24,16 @@
  * @author Pacman Development Team
  * @date 7 Dec 2020
  * @brief A doubly linked list for use with libalpm
+ *
+ * @section see_also See Also
+ * \b alpm(3),
+ * \b alpm-hooks(5),
+ * \b makepkg(8),
+ * \b pacman(8),
+ * \b pacman.conf(5)
+ * @{
+ */
+
  */
 
 #ifndef ALPM_LIST_H
-- 
2.29.2


[pacman-dev] [PATCH 11/23] doc: document files and groups

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 102 +
 1 file changed, 56 insertions(+), 46 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 5ee99711..30bfb06d 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -94,44 +94,82 @@ typedef struct __alpm_pkg_t alpm_pkg_t;
 /** Transaction structure used internally by libalpm */
 typedef struct __alpm_trans_t alpm_trans_t;
 
-/*
- * Structures
+/** @addtogroup alpm_api ALPM
+ * @brief The libalpm Public API
+ * @{
  */
 
-/** Package group */
-typedef struct _alpm_group_t {
-   /** group name */
-   char *name;
-   /** list of alpm_pkg_t packages */
-   alpm_list_t *packages;
-} alpm_group_t;
+/** @addtogroup alpm_files Files
+ * @brief Functions for package files
+ * @{
+ */
 
 /** File in a package */
 typedef struct _alpm_file_t {
-   char *name;
-   off_t size;
-   mode_t mode;
+   /** Name of the file */
+   char *name;
+   /** Size of the file */
+   off_t size;
+   /** The file's permissions */
+   mode_t mode;
 } alpm_file_t;
 
 /** Package filelist container */
 typedef struct _alpm_filelist_t {
-   size_t count;
-   alpm_file_t *files;
+   /** Amount of files in the array */
+   size_t count;
+   /** An array of files */
+   alpm_file_t *files;
 } alpm_filelist_t;
 
 /** Local package or package file backup entry */
 typedef struct _alpm_backup_t {
-   char *name;
-   char *hash;
+   /** Name of the file (without .pacsave extension) */
+   char *name;
+   /** Hash of the filename (used internally) */
+   char *hash;
 } alpm_backup_t;
 
+/** Determines whether a package filelist contains a given path.
+ * The provided path should be relative to the install root with no leading
+ * slashes, e.g. "etc/localtime". When searching for directories, the path must
+ * have a trailing slash.
+ * @param filelist a pointer to a package filelist
+ * @param path the path to search for in the package
+ * @return a pointer to the matching file or NULL if not found
+ */
+alpm_file_t *alpm_filelist_contains(alpm_filelist_t *filelist, const char 
*path);
+
+/* End of alpm_files */
+/** @} */
 
 
-/** @addtogroup alpm_api ALPM
- * @brief The libalpm Public API
+/** @addtogroup alpm_groups Groups
+ * @brief Functions for package groups
  * @{
  */
 
+/** Package group */
+typedef struct _alpm_group_t {
+   /** group name */
+   char *name;
+   /** list of alpm_pkg_t packages */
+   alpm_list_t *packages;
+} alpm_group_t;
+
+/** Find group members across a list of databases.
+ * If a member exists in several databases, only the first database is used.
+ * IgnorePkg is also handled.
+ * @param dbs the list of alpm_db_t *
+ * @param name the name of the group
+ * @return the list of alpm_pkg_t * (caller is responsible for alpm_list_free)
+ */
+alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name);
+
+/* End of alpm_groups */
+/** @} */
+
+
 /** @addtogroup alpm_errors Error Codes
  * Error codes returned by libalpm.
  * @{
@@ -2031,34 +2069,6 @@ int alpm_pkg_mtree_close(const alpm_pkg_t *pkg, struct 
archive *archive);
 /** @} */
 
 
-/*
- * Filelists
- */
-
-/** Determines whether a package filelist contains a given path.
- * The provided path should be relative to the install root with no leading
- * slashes, e.g. "etc/localtime". When searching for directories, the path must
- * have a trailing slash.
- * @param filelist a pointer to a package filelist
- * @param path the path to search for in the package
- * @return a pointer to the matching file or NULL if not found
- */
-alpm_file_t *alpm_filelist_contains(alpm_filelist_t *filelist, const char 
*path);
-
-
-/*
- * Groups
- */
-
-/** Find group members across a list of databases.
- * If a member exists in several databases, only the first database is used.
- * IgnorePkg is also handled.
- * @param dbs the list of alpm_db_t *
- * @param name the name of the group
- * @return the list of alpm_pkg_t * (caller is responsible for alpm_list_free)
- */
-alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name);
-
 /*
  * Sync
  */
-- 
2.29.2


[pacman-dev] [PATCH 20/23] doc: rename alpm_api group to alpm

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index e9cc7c85..a0de9b13 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -50,7 +50,7 @@ extern "C" {
 
 #include 
 
-/** @addtogroup alpm_api ALPM
+/** @addtogroup alpm alpm
  * @brief The libalpm Public API
  * @{
  */
-- 
2.29.2


[pacman-dev] [PATCH 10/23] doc: document packages

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 164 ++---
 1 file changed, 96 insertions(+), 68 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ea690abc..5ee99711 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1368,43 +1368,11 @@ int alpm_db_get_usage(alpm_db_t *db, int *usage);
 /* End of usage accessors */
 /** @} */
 
+
 /* End of alpm_databases */
 /** @} */
 
 
-/*
- * Enumerations
- * These ones are used in multiple contexts, so are forward-declared.
- */
-
-/** Package install reasons. */
-typedef enum _alpm_pkgreason_t {
-   /** Explicitly requested by the user. */
-   ALPM_PKG_REASON_EXPLICIT = 0,
-   /** Installed as a dependency for another package. */
-   ALPM_PKG_REASON_DEPEND = 1
-} alpm_pkgreason_t;
-
-/** Location a package object was loaded from. */
-typedef enum _alpm_pkgfrom_t {
-   ALPM_PKG_FROM_FILE = 1,
-   ALPM_PKG_FROM_LOCALDB,
-   ALPM_PKG_FROM_SYNCDB
-} alpm_pkgfrom_t;
-
-/** Method used to validate a package. */
-typedef enum _alpm_pkgvalidation_t {
-   ALPM_PKG_VALIDATION_UNKNOWN = 0,
-   ALPM_PKG_VALIDATION_NONE = (1 << 0),
-   ALPM_PKG_VALIDATION_MD5SUM = (1 << 1),
-   ALPM_PKG_VALIDATION_SHA256SUM = (1 << 2),
-   ALPM_PKG_VALIDATION_SIGNATURE = (1 << 3)
-} alpm_pkgvalidation_t;
-
-/*
- * Logging facilities
- */
-
 /** \addtogroup alpm_log Logging Functions
  * @brief Functions to log using libalpm
  * @{
@@ -1446,17 +1414,6 @@ int alpm_logaction(alpm_handle_t *handle, const char 
*prefix,
 /* End of alpm_log */
 /** @} */
 
-/** Fetch a list of remote packages.
- * @param handle the context handle
- * @param urls list of package URLs to download
- * @param fetched list of filepaths to the fetched packages, each item
- *corresponds to one in `urls` list. This is an output parameter,
- *the caller should provide a pointer to an empty list
- *(*fetched === NULL) and the callee fills the list with data.
- * @return 0 on success or -1 on failure
- */
-int alpm_fetch_pkgurl(alpm_handle_t *handle, const alpm_list_t *urls,
- alpm_list_t **fetched);
 
 /** @addtogroup alpm_api_options Options
  * Libalpm option getters and setters
@@ -1638,11 +1595,44 @@ int alpm_option_set_parallel_downloads(alpm_handle_t 
*handle, unsigned int num_s
 
 /** @} */
 
-/** @addtogroup alpm_api_packages Package Functions
+/** @addtogroup alpm_packages Package Functions
  * Functions to manipulate libalpm packages
  * @{
  */
 
+/** Package install reasons. */
+typedef enum _alpm_pkgreason_t {
+   /** Explicitly requested by the user. */
+   ALPM_PKG_REASON_EXPLICIT = 0,
+   /** Installed as a dependency for another package. */
+   ALPM_PKG_REASON_DEPEND = 1
+} alpm_pkgreason_t;
+
+/** Location a package object was loaded from. */
+typedef enum _alpm_pkgfrom_t {
+   /** Loaded from a file via \link alpm_pkg_load \endlink */
+   ALPM_PKG_FROM_FILE = 1,
+   /** From the local database */
+   ALPM_PKG_FROM_LOCALDB,
+   /** From a sync database */
+   ALPM_PKG_FROM_SYNCDB
+} alpm_pkgfrom_t;
+
+
+/** Method used to validate a package. */
+typedef enum _alpm_pkgvalidation_t {
+   /** The package's validation type is unknown */
+   ALPM_PKG_VALIDATION_UNKNOWN = 0,
+   /** The package does not have any validation */
+   ALPM_PKG_VALIDATION_NONE = (1 << 0),
+   /** The package is validated with md5 */
+   ALPM_PKG_VALIDATION_MD5SUM = (1 << 1),
+   /** The package is validated with sha256 */
+   ALPM_PKG_VALIDATION_SHA256SUM = (1 << 2),
+   /** The package is validated with a PGP signature */
+   ALPM_PKG_VALIDATION_SIGNATURE = (1 << 3)
+} alpm_pkgvalidation_t;
+
 /** Create a package from a file.
  * If full is false, the archive is read only until all necessary
  * metadata is found. If it is true, the entire archive is read, which
@@ -1660,6 +1650,18 @@ int alpm_option_set_parallel_downloads(alpm_handle_t 
*handle, unsigned int num_s
 int alpm_pkg_load(alpm_handle_t *handle, const char *filename, int full,
int level, alpm_pkg_t **pkg);
 
+/** Fetch a list of remote packages.
+ * @param handle the context handle
+ * @param urls list of package URLs to download
+ * @param fetched list of filepaths to the fetched packages, each item
+ *corresponds to one in `urls` list. This is an output parameter,
+ *the caller should provide a pointer to an empty list
+ *(*fetched === NULL) and the callee fills the list with data.
+ * @return 0 on success or -1 on failure
+ */
+int alpm_fetch_pkgurl(alpm_handle_t *handle, const alpm_list_t *urls,
+ alpm_list_t **fetched);
+
 /** Find a package in a list by name.
  * @param haystack a list of alpm_pkg_t
  * @param needle the package name
@@ -1668,6 +1670,8 @@ int alpm_pkg_load(alpm_handle_t *handle, const char 
*filename, int full,
 alpm_pkg_t *alpm_pkg_find(alpm_list_t *haystack, const char *needle);
 
 /** Free a package.
+ * Only packages 

[pacman-dev] [PATCH 16/23] doc: move alpm_api group to top of file

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 05dec6c7..4673f639 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -50,6 +50,11 @@ extern "C" {
 
 #include 
 
+/** @addtogroup alpm_api ALPM
+ * @brief The libalpm Public API
+ * @{
+ */
+
 /*
  * Opaque Structures
  */
@@ -94,11 +99,6 @@ typedef struct __alpm_pkg_t alpm_pkg_t;
 /** Transaction structure used internally by libalpm */
 typedef struct __alpm_trans_t alpm_trans_t;
 
-/** @addtogroup alpm_api ALPM
- * @brief The libalpm Public API
- * @{
- */
-
 /** @addtogroup alpm_files Files
  * @brief Functions for package files
  * @{
-- 
2.29.2


[pacman-dev] [PATCH 22/23] doc: change group names to libalpm_*

2020-12-07 Thread morganamilo
Also change the group's title to point to the group's man page.

This makes generated man pages be named libalpm_* which is more
consistent with what library man pages are usually called.
---
 doc/meson.build |  1 -
 lib/libalpm/alpm.h  | 80 +
 lib/libalpm/alpm_list.h | 22 ++--
 3 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/doc/meson.build b/doc/meson.build
index e24172fd..570dc765 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -9,7 +9,6 @@ manpages = [
   { 'name': 'PKGBUILD.5', 'extra_depends' : [ 'PKGBUILD-example.txt' ] },
   { 'name': 'makepkg.conf.5' },
   { 'name': 'pacman.conf.5' },
-  { 'name': 'libalpm.3' },
   { 'name': 'BUILDINFO.5' },
   { 'name': 'pacman-conf.8' },
 ]
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index b2772f19..dd28b191 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -21,13 +21,6 @@
  *  along with this program.  If not, see .
  */
 
-/**
- * @file alpm.h
- * @author Pacman Development Team
- * @date 7 Dec 2020
- * @brief Arch Linux Package Manager Library
- */
-
 /** @mainpage alpm
  *
  * libalpm is a package management library, primaraly used by pacman.
@@ -50,14 +43,41 @@ extern "C" {
 
 #include 
 
-/** @addtogroup alpm The libalpm Public API
+/** @addtogroup libalpm The libalpm Public API
+ *
+ *
+ * libalpm is a package management library, primaraly used by pacman.
+ *
+ * For ease of access, the libalpm manual has been split up into several 
sections.
  *
- * @section see_also See Also
- * \b alpm_list(3),
+ * @section bugs Bugs
+ * Bugs? You must be kidding; there are no bugs in this software. But if we 
happen to be wrong,
+ * submit a bug report with as much detail as possible at the Arch Linux Bug 
Tracker in the
+ * Pacman section.
+ *
+ * @section see_also See also
+ * \b libalpm-list(3),
  * \b alpm-hooks(5),
  * \b makepkg(8),
- * \b pacman(8),
- * \b pacman.conf(5)
+ *
+ * @section maintainers Maintainers
+ * Current maintainers:
+ *
+ * - Allan McRae 
+ * - Andrew Gregory 
+ * - Dave Reisner 
+ * - Eli Schwartz 
+ *
+ * Past major contributors:
+ *
+ * - Judd Vinet 
+ * - Aurelien Foret 
+ * - Aaron Griffin 
+ * - Dan McGee 
+ * - Xavier Chantry 
+ * - Nagy Gabor 
+ *
+ * For additional contributors, use git shortlog -s on the pacman.git 
repository.
  * @{
  */
 
@@ -68,7 +88,7 @@ extern "C" {
 /** The libalpm context handle.
  *
  * This struct represents an instance of libalpm.
- * @ingroup alpm_handle
+ * @ingroup libalpm-handle
  */
 typedef struct __alpm_handle_t alpm_handle_t;
 
@@ -88,7 +108,7 @@ typedef struct __alpm_handle_t alpm_handle_t;
  * the user. They will be freed when the database is unregistered.
  *
  * Databases are automatically unregistered when the \link alpm_handle_t 
\endlink is released.
- * @ingroup alpm_databases
+ * @ingroup libalpm-databases
  */
 typedef struct __alpm_db_t alpm_db_t;
 
@@ -101,21 +121,21 @@ typedef struct __alpm_db_t alpm_db_t;
  *
  * Packages can then be queried for metadata or added to a \link alpm_trans_t 
transaction \endlink
  * to be added or removed from the system.
- * @ingroup alpm_packages
+ * @ingroup libalpm-packages
  */
 typedef struct __alpm_pkg_t alpm_pkg_t;
 
 /** Transaction structure used internally by libalpm 
- * @ingroup alpm_trans
+ * @ingroup libalpm-trans
  * */
 typedef struct __alpm_trans_t alpm_trans_t;
 
 
 /** The time type used by libalpm. Represents a unix time stamp
- * @ingroup alpm_misc */
+ * @ingroup libalpm-misc */
 typedef int64_t alpm_time_t;
 
-/** @addtogroup alpm_files Files
+/** @addtogroup libalpm-files libalpm-files(3)
  * @brief Functions for package files
  * @{
  */
@@ -160,7 +180,7 @@ alpm_file_t *alpm_filelist_contains(alpm_filelist_t 
*filelist, const char *path)
 /** @} */
 
 
-/** @addtogroup alpm_groups Groups
+/** @addtogroup libalpm-groups libalpm-groups(3)
  * @brief Functions for package groups
  * @{
  */
@@ -186,7 +206,7 @@ alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const 
char *name);
 /** @} */
 
 
-/** @addtogroup alpm_errors Error Codes
+/** @addtogroup libalpm-errors libalpm-errors(3)
  * Error codes returned by libalpm.
  * @{
  */
@@ -330,7 +350,7 @@ const char *alpm_strerror(alpm_errno_t err);
 /** @} */
 
 
-/** \addtogroup alpm_handle Handle
+/** \addtogroup libalpm-handle libalpm-handle(3)
  * @brief Functions to initialize and release libalpm
  * @{
  */
@@ -360,7 +380,7 @@ int alpm_release(alpm_handle_t *handle);
 /** @} */
 
 
-/** @addtogroup alpm_sig Signature checking
+/** @addtogroup libalpm-sig libalpm-sig(3)
  * @brief Functions to check signatures
  * @{
  */
@@ -526,7 +546,7 @@ int alpm_extract_keyid(alpm_handle_t *handle, const char 
*identifier,
 /** @} */
 
 
-/** @addtogroup alpm_depends Dependency
+/** @addtogroup libalpm-depends libalpm-depends(3)
  * @brief Functions dealing with libalpm's dependency and conflict
  * information.
  * @{
@@ -703,7 +723,7 @@ void 

[pacman-dev] [PATCH 13/23] doc: document misc

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 35 ---
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 76ae5722..494a8319 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -2068,11 +2068,6 @@ int alpm_pkg_mtree_close(const alpm_pkg_t *pkg, struct 
archive *archive);
 /* End of alpm_packages */
 /** @} */
 
-/** Check for new version of pkg in sync repos
- * (only the first occurrence is considered in sync)
- */
-alpm_pkg_t *alpm_sync_get_new_version(alpm_pkg_t *pkg, alpm_list_t *dbs_sync);
-
 /** @addtogroup alpm_trans Transaction
  * @brief Functions to manipulate libalpm transactions
  *
@@ -2212,20 +2207,25 @@ int alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t 
*pkg);
 /* End of add/remove packages */
 /** @} */
 
+
 /* End of alpm_trans */
 /** @} */
 
-/*
- * Helpers
- */
-
-/* checksums */
 
 /** \addtogroup alpm_misc Miscellaneous Functions
  * @brief Various libalpm functions
  * @{
  */
 
+/** Check for new version of pkg in syncdbs.
+ *
+ * If the same package appears multiple dbs only the first will be checked
+ *
+ * This only checks the syncdb for a newer version. It does not access the 
network at all.
+ * See \link alpm_db_update \endlink to update a database.
+ */
+alpm_pkg_t *alpm_sync_get_new_version(alpm_pkg_t *pkg, alpm_list_t *dbs_sync);
+
 /** Get the md5 sum of file.
  * @param filename name of the file
  * @return the checksum on success, NULL on error
@@ -2238,8 +2238,6 @@ char *alpm_compute_md5sum(const char *filename);
  */
 char *alpm_compute_sha256sum(const char *filename);
 
-/** @} */
-
 /** Remove the database lock file
  * @param handle the context handle
  * @return 0 on success, -1 on error
@@ -2248,10 +2246,14 @@ char *alpm_compute_sha256sum(const char *filename);
  */
 int alpm_unlock(alpm_handle_t *handle);
 
+/** Enum of possible compile time features */
 enum alpm_caps {
-   ALPM_CAPABILITY_NLS = (1 << 0),
-   ALPM_CAPABILITY_DOWNLOADER = (1 << 1),
-   ALPM_CAPABILITY_SIGNATURES = (1 << 2)
+/** localization */
+ALPM_CAPABILITY_NLS = (1 << 0),
+/** Ability to download */
+ALPM_CAPABILITY_DOWNLOADER = (1 << 1),
+/** Signature checking */
+ALPM_CAPABILITY_SIGNATURES = (1 << 2)
 };
 
 /** Get the version of library.
@@ -2264,6 +2266,9 @@ const char *alpm_version(void);
  * */
 int alpm_capabilities(void);
 
+/* End of alpm_misc */
+/** @} */
+
 /* End of alpm_api */
 /** @} */
 
-- 
2.29.2


[pacman-dev] [PATCH 23/23] doc: remove old libalpm man file

2020-12-07 Thread morganamilo
---
 doc/libalpm.3.asciidoc | 37 -
 1 file changed, 37 deletions(-)
 delete mode 100644 doc/libalpm.3.asciidoc

diff --git a/doc/libalpm.3.asciidoc b/doc/libalpm.3.asciidoc
deleted file mode 100644
index 79ea5409..
--- a/doc/libalpm.3.asciidoc
+++ /dev/null
@@ -1,37 +0,0 @@
-libalpm(3)
-==
-
-Name
-
-libalpm - Arch Linux Package Management (ALPM) library
-
-
-Synopsis
-
-For ease of access, the libalpm manual has been split up into several sections.
-
-*TODO:* Yes, this man page needs a lot of work. Once we get around to doing
-good Doxygen documentation, it will improve. We promise.
-
-*alpm_databases*:: Database Functions
-*alpm_interface*:: Interface Functions
-*alpm_list*::  List Functions
-*alpm_log*::   Logging Functions
-*alpm_misc*::  Miscellaneous Functions
-*alpm_packages*::  Package Functions
-*alpm_sync*::  Sync Functions
-*alpm_trans*:: Transaction Functions
-
-
-Configuration
--
-See linkman:pacman.conf[5] for more details on configuring libalpm using the
-'pacman.conf' file.
-
-
-See Also
-
-linkman:alpm-hooks[5], linkman:makepkg[8], linkman:pacman[8],
-linkman:pacman.conf[5]
-
-include::footer.asciidoc[]
-- 
2.29.2


[pacman-dev] [PATCH 04/23] doc: document handle

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 58 --
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 1c2422ca..178c8f6a 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -243,6 +243,36 @@ const char *alpm_strerror(alpm_errno_t err);
 /* End of alpm_errors */
 /** @} */
 
+
+/** \addtogroup alpm_handle Handle
+ * @brief Functions to initialize and release libalpm
+ * @{
+ */
+
+/** Initializes the library.
+ * Creates handle, connects to database and creates lockfile.
+ * This must be called before any other functions are called.
+ * @param root the root path for all filesystem operations
+ * @param dbpath the absolute path to the libalpm database
+ * @param err an optional variable to hold any error return codes
+ * @return a context handle on success, NULL on error, err will be set if 
provided
+ */
+alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
+   alpm_errno_t *err);
+
+/** Release the library.
+ * Disconnects from the database, removes handle and lockfile
+ * This should be the last alpm call you make.
+ * After this returns, handle should be considered invalid and cannot be reused
+ * in any way.
+ * @param myhandle the context handle
+ * @return 0 on success, -1 on error
+ */
+int alpm_release(alpm_handle_t *handle);
+
+/* End of alpm_handle */
+/** @} */
+
 typedef int64_t alpm_time_t;
 
 /*
@@ -1915,34 +1945,6 @@ char *alpm_compute_sha256sum(const char *filename);
 
 /** @} */
 
-/** \addtogroup alpm_interface Interface Functions
- * @brief Functions to initialize and release libalpm
- * @{
- */
-
-/** Initializes the library.
- * Creates handle, connects to database and creates lockfile.
- * This must be called before any other functions are called.
- * @param root the root path for all filesystem operations
- * @param dbpath the absolute path to the libalpm database
- * @param err an optional variable to hold any error return codes
- * @return a context handle on success, NULL on error, err will be set if 
provided
- */
-alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
-   alpm_errno_t *err);
-
-/** Release the library.
- * Disconnects from the database, removes handle and lockfile
- * This should be the last alpm call you make.
- * After this returns, handle should be considered invalid and cannot be reused
- * in any way.
- * @param myhandle the context handle
- * @return 0 on success, -1 on error
- */
-int alpm_release(alpm_handle_t *handle);
-
-/** @} */
-
 /** Remove the database lock file
  * @param handle the context handle
  * @return 0 on success, -1 on error
-- 
2.29.2


[pacman-dev] [PATCH 03/23] doc: document error

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 122 -
 1 file changed, 109 insertions(+), 13 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 48ba7fdc..1c2422ca 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -51,102 +51,198 @@ extern "C" {
 #include 
 
 /*
- * Arch Linux Package Management library
+ * Opaque Structures
  */
 
-/*
- * Opaque Structures
+/** The libalpm context handle.
+ *
+ * This struct represents an instance of libalpm.
  */
 typedef struct __alpm_handle_t alpm_handle_t;
+
+/** A database.
+ *
+ * A database is a container that stores metadata about packages.
+ *
+ * A database can be located on the local filesystem or on a remote server.
+ *
+ * To use a database, it must first be registered via \link 
alpm_register_syncdb \endlink.
+ * If the database is already preasant in dbpath then it will be usable. 
Otherwise,
+ * the database needs to be downloaded using \link alpm_db_update \endlink. 
Even if the
+ * source of the database is the local filesystem.
+ *
+ * After this, the database can be used to query packages and groups. Any 
packages or groups
+ * from the database will continue to be owned by the database and do not need 
to be freed by
+ * the user. They will be freed when the database is unregistered.
+ *
+ * Databases are automatically unregistered when the \link alpm_handle_t 
\endlink is released.
+ */
 typedef struct __alpm_db_t alpm_db_t;
+
+
+/** A package
+ *
+ * A package can be loaded from disk via \link alpm_pkg_load \endlink or 
retrieved from a database.
+ * Packages from databases are automatically freed when the database is 
unregistered. Packages loaded
+ * from a file must be freed manually.
+ *
+ * Packages can then be queried for metadata or added to a \link alpm_trans_t 
transaction \endlink
+ * to be added or removed from the system.
+ */
 typedef struct __alpm_pkg_t alpm_pkg_t;
+
+/** Transaction structure used internally by libalpm */
 typedef struct __alpm_trans_t alpm_trans_t;
 
-/** @addtogroup alpm_api_errors Error Codes
+
+/** @addtogroup alpm_api ALPM
+ * @brief The libalpm Public API
+ * @{
+ */
+
+/** @addtogroup alpm_errors Error Codes
+ * Error codes returned by libalpm.
  * @{
  */
+
+/** libalpm's error type */
 typedef enum _alpm_errno_t {
+   /** No error */
ALPM_ERR_OK = 0,
+   /** Failed to allocate memory */
ALPM_ERR_MEMORY,
+   /** A system error occurred */
ALPM_ERR_SYSTEM,
+   /** Permmision denied */
ALPM_ERR_BADPERMS,
+   /** Should be a file */
ALPM_ERR_NOT_A_FILE,
+   /** Should be a directory */
ALPM_ERR_NOT_A_DIR,
+   /** Function was called with invalid arguments */
ALPM_ERR_WRONG_ARGS,
+   /** Insufficient disk space */
ALPM_ERR_DISK_SPACE,
/* Interface */
+   /** Handle should be null */
ALPM_ERR_HANDLE_NULL,
+   /** Handle should not be null */
ALPM_ERR_HANDLE_NOT_NULL,
+   /** Failed to acquire lock */
ALPM_ERR_HANDLE_LOCK,
/* Databases */
+   /** Failed to open database */
ALPM_ERR_DB_OPEN,
+   /** Failed to create database */
ALPM_ERR_DB_CREATE,
+   /** Database should not be null */
ALPM_ERR_DB_NULL,
+   /** Database should be null */
ALPM_ERR_DB_NOT_NULL,
+   /** The database could not be found */
ALPM_ERR_DB_NOT_FOUND,
+   /** Database is invalid */
ALPM_ERR_DB_INVALID,
+   /** Database has an invalid signature */
ALPM_ERR_DB_INVALID_SIG,
+   /** The localdb is in a newer/older format than libalpm expects */
ALPM_ERR_DB_VERSION,
+   /** Failed to write to the database */
ALPM_ERR_DB_WRITE,
+   /** Failed to remove entry from database */
ALPM_ERR_DB_REMOVE,
/* Servers */
+   /** Server URL is in an invalid format */
ALPM_ERR_SERVER_BAD_URL,
+   /** The database has no configured servers */
ALPM_ERR_SERVER_NONE,
/* Transactions */
+   /** A transaction is already initialized */
ALPM_ERR_TRANS_NOT_NULL,
+   /** A transaction has not been initialized */
ALPM_ERR_TRANS_NULL,
+   /** Duplicate target in transaction */
ALPM_ERR_TRANS_DUP_TARGET,
+   /** A transaction has not been initialized */
ALPM_ERR_TRANS_NOT_INITIALIZED,
+   /** Transaction has not been prepared */
ALPM_ERR_TRANS_NOT_PREPARED,
+   /** Transaction was aborted */
ALPM_ERR_TRANS_ABORT,
+   /** Failed to interrupt transaction */
ALPM_ERR_TRANS_TYPE,
+   /** Tried to commit transaction without locking the database */
ALPM_ERR_TRANS_NOT_LOCKED,
+   /** A hook failed to run */
ALPM_ERR_TRANS_HOOK_FAILED,
/* Packages */
+   /** Package not found */
ALPM_ERR_PKG_NOT_FOUND,
+   /** Package is in ignorepkg */
ALPM_ERR_PKG_IGNORED,
+   /** Package is invalid */
  

[pacman-dev] [PATCH 02/23] doc: add doc header to alpm.h

2020-12-07 Thread morganamilo
---
 lib/libalpm/alpm.h | 13 +
 1 file changed, 13 insertions(+)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 50c4bb6b..48ba7fdc 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -20,6 +20,19 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
+
+/**
+ * @file alpm.h
+ * @author Pacman Development Team
+ * @date 7 Dec 2020
+ * @brief Arch Linux Package Manager Library
+ */
+
+/** @mainpage alpm
+ *
+ * libalpm is a package management library, primaraly used by pacman.
+ */
+
 #ifndef ALPM_H
 #define ALPM_H
 
-- 
2.29.2


[pacman-dev] [PATCH 00/23] Docs Docs Docs 2: electric boogaloo

2020-12-07 Thread morganamilo
Here's a redo of my original docs patch and more.

This time it's split in to many commits so it's hopefully easier to
review/rebase.

Every function, struct and param is now documented.

Simply `man libalpm` to get the main page. Then `man libalpm-databases`
to see the database section and so on for each section.

Also while doing all this, I thought it would make sense to change some
function names:

I also think alpm_unlock() should be named alpm_db_unlock() and
alpm_sync_get_new_version() should be named alpm_pkg_get_new_version()

Then the functions could be moved into the db and packages groups
repectivley.

To be clear I have not actually changed any function names in this patch
set.

morganamilo (23):
  doc: remove stray doxygen comment
  doc: add doc header to alpm.h
  doc: document error
  doc: document handle
  doc: document signatures
  doc: document depends
  doc: document callbacks
  doc: document databases
  doc: document logging
  doc: document packages
  doc: document files and groups
  doc: document transactions
  doc: document misc
  doc: document alpm_list
  doc: document options
  doc: move alpm_api group to top of file
  doc: move top level items into groups
  doc: configure doxygen
  doc: update doxyfile
  doc: rename alpm_api group to alpm
  doc: add extra documentation to the man page
  doc: change group names to libalpm_*
  doc: remove old libalpm man file

 doc/Doxyfile.in |   83 +-
 doc/libalpm.3.asciidoc  |   37 -
 doc/meson.build |1 -
 lib/libalpm/alpm.h  | 2429 +++
 lib/libalpm/alpm_list.c |  251 
 lib/libalpm/alpm_list.h |  293 -
 lib/libalpm/trans.c |2 -
 7 files changed, 2048 insertions(+), 1048 deletions(-)
 delete mode 100644 doc/libalpm.3.asciidoc

-- 
2.29.2


[pacman-dev] [PATCH 01/23] doc: remove stray doxygen comment

2020-12-07 Thread morganamilo
---
 lib/libalpm/trans.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index c7317c15..303d2fca 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -266,8 +266,6 @@ int SYMEXPORT alpm_trans_release(alpm_handle_t *handle)
return 0;
 }
 
-/** @} */
-
 void _alpm_trans_free(alpm_trans_t *trans)
 {
if(trans == NULL) {
-- 
2.29.2


[pacman-dev] [PATCH] Add --confirm

2020-12-07 Thread morganamilo
this is useful for cancelling the automatically passed --noconfirm
by makechrootpkg

diff --git a/doc/makepkg.8.asciidoc b/doc/makepkg.8.asciidoc
index 3b5e61b3..b3ecbe12 100644
--- a/doc/makepkg.8.asciidoc
+++ b/doc/makepkg.8.asciidoc
@@ -184,6 +184,9 @@ Options
(Passed to pacman) Prevent pacman from waiting for user input before
proceeding with operations.
 
+*\--confirm*::
+   Cancels the effects of a previous --noconfirm.
+
 *\--needed*::
(Passed to pacman) Tell pacman not to reinstall a target if it is 
already
up-to-date. (used with '-i' / '\--install').
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index b39433f3..1c8e8a0e 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -997,6 +997,7 @@ usage() {
printf -- "$(gettext "  --asdeps Install packages as 
non-explicitly installed")\n"
printf -- "$(gettext "  --needed Do not reinstall the targets 
that are already up to date")\n"
printf -- "$(gettext "  --noconfirm  Do not ask for confirmation 
when resolving dependencies")\n"
+   printf -- "$(gettext "  --confirmCancels the effects of a 
previous --noconfirm")\n"
printf -- "$(gettext "  --noprogressbar  Do not show a progress bar 
when downloading files")\n"
echo
printf -- "$(gettext "If %s is not specified, %s will look for 
'%s'")\n" "-p" "makepkg" "$BUILDSCRIPT"
@@ -1036,7 +1037,7 @@ OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 
'config:' 'force' 'geninteg'
   'skippgpcheck' 'source' 'syncdeps' 'verifysource' 'version')
 
 # Pacman Options
-OPT_LONG+=('asdeps' 'noconfirm' 'needed' 'noprogressbar')
+OPT_LONG+=('asdeps' 'confirm' 'noconfirm' 'needed' 'noprogressbar')
 
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
exit $E_INVALID_OPTION
@@ -1050,6 +1051,7 @@ while true; do
--asdeps) ASDEPS=1;;
--needed) NEEDED=1;;
--noconfirm)  PACMAN_OPTS+=("--noconfirm") ;;
+   --confirm)PACMAN_OPTS+=("--confirm") ;;
--noprogressbar)  PACMAN_OPTS+=("--noprogressbar") ;;
 
# Makepkg Options
-- 
2.29.2


[pacman-dev] [PATCH] libalpm: set ret in download files

2020-11-30 Thread morganamilo
download_files never set ret on failiure, so even when downloading
fails, the transaction goes on to commit and error out.

:: Retrieving packages...
 python-packaging-20.4-4-any.pkg.tar.zst failed to download
error: failed retrieving file 'python-packaging-20.4-4-any.pkg.tar.zst' from 
mirror.oldsql.cc : The requested URL returned error: 404
warning: failed to retrieve some files
(1/1) checking keys in keyring
(1/1) checking package integrity
error: failed to commit transaction (wrong or NULL argument passed)
Errors occurred, no packages were upgraded.

Also make the ret checking more consistent.

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 601f1d69..5d8652a5 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -769,7 +769,7 @@ static int download_files(alpm_handle_t *handle)
}
 
ret = find_dl_candidates(handle, );
-   if(ret) {
+   if(ret != 0) {
goto finish;
}
 
@@ -818,7 +818,9 @@ static int download_files(alpm_handle_t *handle)
 
payloads = alpm_list_add(payloads, payload);
}
-   if(_alpm_download(handle, payloads, cachedir) == -1) {
+
+   ret = _alpm_download(handle, payloads, cachedir);
+   if(ret != 0) {
event.type = ALPM_EVENT_PKG_RETRIEVE_FAILED;
EVENT(handle, );
_alpm_log(handle, ALPM_LOG_WARNING, _("failed to 
retrieve some files\n"));
-- 
2.29.2


[pacman-dev] [PATCH 3/5] libalpm: clarify alpm_download_event_completed_t status

2020-11-24 Thread morganamilo
The comment makes it seem that the result itself is an error code. But
all it does is simply return -1 to indicate an error occured;

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 614a530c..6a7323e0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -728,9 +728,9 @@ typedef struct {
/* total bytes in file */
off_t total;
/* download result code:
-*   0 - download completed successfully
-*   1 - the file is up-to-date
-*   negative - error code
+*0 - download completed successfully
+*1 - the file is up-to-date
+*   -1 - error
 */
int result;
 } alpm_download_event_completed_t;
-- 
2.29.2


[pacman-dev] [PATCH 5/5] libalpm: add alpm_option_get_parallel_downloads

2020-11-24 Thread morganamilo


diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 6a7323e0..50c4bb6b 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -934,6 +934,8 @@ int alpm_option_set_remote_file_siglevel(alpm_handle_t 
*handle, int level);
 
 int alpm_option_set_disable_dl_timeout(alpm_handle_t *handle, unsigned short 
disable_dl_timeout);
 
+int alpm_option_get_parallel_downloads(alpm_handle_t *handle);
+
 /** Sets number of parallel streams to download database and package files.
  * If the function is not called then the default value of '1' stream
  * (i.e. sequential download) is used.
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 16d4beaa..3994f314 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -300,6 +300,16 @@ const char SYMEXPORT *alpm_option_get_dbext(alpm_handle_t 
*handle)
return handle->dbext;
 }
 
+int SYMEXPORT alpm_option_get_parallel_downloads(alpm_handle_t *handle)
+{
+   CHECK_HANDLE(handle, return -1);
+#ifdef HAVE_LIBCURL
+   return handle->parallel_downloads;
+#else
+   return 1;
+#endif
+}
+
 int SYMEXPORT alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb)
 {
CHECK_HANDLE(handle, return -1);
-- 
2.29.2


[pacman-dev] [PATCH 2/5] libalpm: don't call dlcb when not set

2020-11-24 Thread morganamilo
Fixes FS#68728:

diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 673e769f..d43e6d45 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -586,7 +586,7 @@ cleanup:
unlink(payload->tempfile_name);
}
 
-   if(!payload->signature) {
+   if(handle->dlcb && !payload->signature) {
alpm_download_event_completed_t cb_data = {0};
cb_data.total = bytes_dl;
cb_data.result = ret;
@@ -719,7 +719,7 @@ static int curl_download_internal(alpm_handle_t *handle,
struct dload_payload *payload = payloads->data;
 
if(curl_add_payload(handle, curlm, payload, localpath) 
== 0) {
-   if(!payload->signature) {
+   if(handle->dlcb && !payload->signature) {
alpm_download_event_init_t cb_data = 
{.optional = payload->errors_ok};
handle->dlcb(payload->remote_name, 
ALPM_DOWNLOAD_INIT, _data);
}
-- 
2.29.2


[pacman-dev] [PATCH 4/5] libalpm: set errno when setting parallel downloads with an invalid number

2020-11-24 Thread morganamilo


diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 1310601a..16d4beaa 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -857,9 +857,7 @@ int SYMEXPORT 
alpm_option_set_parallel_downloads(alpm_handle_t *handle,
 {
CHECK_HANDLE(handle, return -1);
 #ifdef HAVE_LIBCURL
-   if(num_streams < 1) {
-   return -1;
-   }
+   ASSERT(num_streams >= 1, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
handle->parallel_downloads = num_streams;
 #else
(void)num_streams; /* silence unused variable warnings */
-- 
2.29.2


[pacman-dev] [PATCH 1/5] libalpm: set parallel_downloads to 1 when creating the handle

2020-11-24 Thread morganamilo
Fixes FS#68729

diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 34c5b4b2..5d36136d 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -61,6 +61,8 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, 
const char *dbpath,
/* set default database extension */
STRDUP(myhandle->dbext, ".db", goto nomem);
 
+   myhandle->parallel_downloads = 1;
+
lockfilelen = strlen(myhandle->dbpath) + strlen(lf) + 1;
MALLOC(myhandle->lockfile, lockfilelen, goto nomem);
snprintf(myhandle->lockfile, lockfilelen, "%s%s", myhandle->dbpath, lf);
-- 
2.29.2


[pacman-dev] [PATCH v2] libmakepkg: lint all arrays for empty values

2020-10-27 Thread morganamilo
Empty values break pacman's db format, as an empty line indicates an end
of section.

---

I've seen this out in the wild:
https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=vim-coc-highlight-git=3063e1a6d3e72a35528

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index 1bc49722..22f5fbbb 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -31,7 +31,7 @@ lint_pkgbuild_functions+=('lint_variable')
 
 
 lint_variable() {
-   local i a pkg out bad ret=0
+   local i a pkg out bad array var ret=0
 
# global variables
for i in ${pkgbuild_schema_arrays[@]}; do
@@ -93,5 +93,62 @@ lint_variable() {
done
done
 
+   # ensure lists don't contain empty values
+   for i in ${pkgbuild_schema_arrays[@]}; do
+   if declare -p $i > /dev/null 2>&1; then
+   array_build "array" "$i"
+   for var in "${array[@]}"; do
+   if [[ -z "$var" ]]; then
+   error "$(gettext "%s is not allowed to 
be empty")" "$i"
+   ret=1
+   fi
+   done
+   fi
+   done
+
+   for a in ${arch[@]}; do
+   [[ $a == "any" ]] && continue
+
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
+   if declare -p "${i}_${a}" > /dev/null 2>&1; then
+   array_build "array" "${i}_${a}"
+   for var in "${array[@]}"; do
+   if [[ -z "$var" ]]; then
+   error "$(gettext "%s is not 
allowed to be empty")" "${i}_${a}"
+   ret=1
+   fi
+   done
+   fi
+   done
+   done
+
+   for pkg in ${pkgname[@]}; do
+   for i in ${pkgbuild_schema_arrays[@]}; do
+   if extract_function_variable "package_$pkg" $i 1 out; 
then
+   for val in "${out[@]}" ;do
+   if [[ -z "$val" ]]; then
+   error "$(gettext "%s is not 
allowed to be empty")" "$i"
+   ret=1
+   fi
+   done
+   fi
+   done
+
+   for a in ${arch[@]}; do
+   [[ $a == "any" ]] && continue
+
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
+   if extract_function_variable "package_$pkg" 
"${i}_${a}" 1 out; then
+   for val in "${out[@]}" ;do
+   if [[ -z "$val" ]]; then
+   error "$(gettext "%s is 
not allowed to be empty")" "${i}_${a}"
+   ret=1
+   fi
+   done
+   fi
+   done
+   done
+   done
+
return $ret
 }
-- 
2.29.1


[pacman-dev] [PATCH] libmakepkg: lint all arrays for empty values

2020-10-27 Thread morganamilo
---

I've seen this out in the wild:
https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=vim-coc-highlight-git=3063e1a6d3e72a35528

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index 1bc49722..22f5fbbb 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -31,7 +31,7 @@ lint_pkgbuild_functions+=('lint_variable')
 
 
 lint_variable() {
-   local i a pkg out bad ret=0
+   local i a pkg out bad array var ret=0
 
# global variables
for i in ${pkgbuild_schema_arrays[@]}; do
@@ -93,5 +93,62 @@ lint_variable() {
done
done
 
+   # ensure lists don't contain empty values
+   for i in ${pkgbuild_schema_arrays[@]}; do
+   if declare -p $i > /dev/null 2>&1; then
+   array_build "array" "$i"
+   for var in "${array[@]}"; do
+   if [[ -z "$var" ]]; then
+   error "$(gettext "%s is not allowed to 
be empty")" "$i"
+   ret=1
+   fi
+   done
+   fi
+   done
+
+   for a in ${arch[@]}; do
+   [[ $a == "any" ]] && continue
+
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
+   if declare -p "${i}_${a}" > /dev/null 2>&1; then
+   array_build "array" "${i}_${a}"
+   for var in "${array[@]}"; do
+   if [[ -z "$var" ]]; then
+   error "$(gettext "%s is not 
allowed to be empty")" "${i}_${a}"
+   ret=1
+   fi
+   done
+   fi
+   done
+   done
+
+   for pkg in ${pkgname[@]}; do
+   for i in ${pkgbuild_schema_arrays[@]}; do
+   if extract_function_variable "package_$pkg" $i 1 out; 
then
+   for val in "${out[@]}" ;do
+   if [[ -z "$val" ]]; then
+   error "$(gettext "%s is not 
allowed to be empty")" "$i"
+   ret=1
+   fi
+   done
+   fi
+   done
+
+   for a in ${arch[@]}; do
+   [[ $a == "any" ]] && continue
+
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
+   if extract_function_variable "package_$pkg" 
"${i}_${a}" 1 out; then
+   for val in "${out[@]}" ;do
+   if [[ -z "$val" ]]; then
+   error "$(gettext "%s is 
not allowed to be empty")" "${i}_${a}"
+   ret=1
+   fi
+   done
+   fi
+   done
+   done
+   done
+
return $ret
 }
-- 
2.29.1


[pacman-dev] [PATCH 2/2] Docs docs docs and more docs

2020-01-25 Thread morganamilo
Write docs for every public alpm member and expand on the existing
documentation for other members.

---

The entire .h file has basically been restructed. The best way to see
the end result is either to read the generated man pages or enabled html
and view the generated html.

Also note alpm_list is still not documented.
---
 lib/libalpm/alpm.h  | 1546 ++-
 lib/libalpm/alpm_list.h |   14 +-
 lib/libalpm/version.c   |2 +-
 3 files changed, 1200 insertions(+), 362 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 4a2d2fc1..51e9e5b4 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -20,6 +20,16 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
+
+/**
+ * @file alpm.h
+ * @author Pacman Development Team
+ * @date 26 Jan 2020
+ * @brief Arch Linux Package Manager Library
+ *
+ * bork
+ */
+
 #ifndef ALPM_H
 #define ALPM_H
 
@@ -38,267 +48,313 @@ extern "C" {
 #include 
 
 /*
- * Arch Linux Package Management library
+ * Opaque Structures
  */
 
-/*
- * Opaque Structures
+/** The libalpm context handle.
+ *
+ * This struct represents an instance of libalpm.
  */
 typedef struct __alpm_handle_t alpm_handle_t;
+
+/** A database.
+ *
+ * A database is a container that stores metadata about packages.
+ *
+ * A database can be located on the local filesystem or on a remote server.
+ *
+ * To use a database, it must first be registered via \link 
alpm_register_syncdb \endlink.
+ * If the database is already preasant in the dbpath then it will be usable. 
Otherwise,
+ * the database needs to be downloaded using \link alpm_db_update \endlink. 
Even if the
+ * source of the database is the local filesystem.
+ *
+ * After this, the database can be used to query packages and groups. Any 
packages or groups
+ * from the database will continue to be owned by the database and do not need 
to be freed by
+ * the user. They will be freed when the database is unregistered.
+ *
+ * Databases are automatically unregistered when the \link alpm_handle_t 
\endlink is released.
+ */
 typedef struct __alpm_db_t alpm_db_t;
+
+/** A package
+ *
+ * A package can be loaded from disk via \link alpm_pkg_load \endlink or 
retrieved from a database.
+ * Packages from databases are automatically freed when the database is 
unregistered. Packages loaded
+ * from a file must be freed manually.
+ *
+ * Packages can then be queried for metadata or added to a \link alpm_trans_t 
transaction \endlink
+ * to be added or removed from the system.
+ */
 typedef struct __alpm_pkg_t alpm_pkg_t;
+
+/** Transaction structure used internally by libalpm */
 typedef struct __alpm_trans_t alpm_trans_t;
 
-/** @addtogroup alpm_api_errors Error Codes
+/** @addtogroup alpm_api ALPM
+ * @brief The libalpm Public API
+ * @{
+ */
+
+/** @addtogroup alpm_errors Error Codes
+ * @brief The error codes used by libalpm
  * @{
  */
+
+/** libalpm's error type */
 typedef enum _alpm_errno_t {
+   /** No error */
ALPM_ERR_OK = 0,
+   /** Failed to allocate memory */
ALPM_ERR_MEMORY,
+   /** A system error occurred */
ALPM_ERR_SYSTEM,
+   /** Permmision denied */
ALPM_ERR_BADPERMS,
+   /** Should be a file */
ALPM_ERR_NOT_A_FILE,
+   /** Should be a directory */
ALPM_ERR_NOT_A_DIR,
+   /** Function was called with invalid arguments */
ALPM_ERR_WRONG_ARGS,
+   /** Insufficient disk space */
ALPM_ERR_DISK_SPACE,
/* Interface */
+   /** Handle should be null */
ALPM_ERR_HANDLE_NULL,
+   /** Handle should not be null */
ALPM_ERR_HANDLE_NOT_NULL,
+   /** Failed to acquire lock */
ALPM_ERR_HANDLE_LOCK,
/* Databases */
+   /** Failed to open database */
ALPM_ERR_DB_OPEN,
+   /** Failed to create database */
ALPM_ERR_DB_CREATE,
+   /** Database should not be null */
ALPM_ERR_DB_NULL,
+   /** Database should be null */
ALPM_ERR_DB_NOT_NULL,
+   /** The database could not be found */
ALPM_ERR_DB_NOT_FOUND,
+   /** Database is invalid */
ALPM_ERR_DB_INVALID,
+   /** Database has an invalid signature */
ALPM_ERR_DB_INVALID_SIG,
+   /** The localdb is in a newer/older format than libalpm expects */
ALPM_ERR_DB_VERSION,
+   /** Fauked to write to the database */
ALPM_ERR_DB_WRITE,
+   /** Fauked to remove entry from database */
ALPM_ERR_DB_REMOVE,
/* Servers */
+   /** Server URL is in an invalid format */
ALPM_ERR_SERVER_BAD_URL,
+   /** The database has no configured servers */
ALPM_ERR_SERVER_NONE,
/* Transactions */
+   /** A transaction is already initialized */
ALPM_ERR_TRANS_NOT_NULL,
+   /** A transaction has not been initialized */
ALPM_ERR_TRANS_NULL,
+   /** Duplicate 

[pacman-dev] [PATCH] libalpm: fix alpm_option_set_assumeinstalled

2020-01-22 Thread morganamilo
It looks like this function has never actually worked. The current list
is never set to NULL after being freed. So the new deps were just
appended to the already freed list, leading to a segfault.

diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index e3193f40..23464045 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -690,6 +690,7 @@ int SYMEXPORT alpm_option_set_assumeinstalled(alpm_handle_t 
*handle, alpm_list_t
if(handle->assumeinstalled) {
alpm_list_free_inner(handle->assumeinstalled, 
(alpm_list_fn_free)alpm_dep_free);
alpm_list_free(handle->assumeinstalled);
+   handle->assumeinstalled = NULL;
}
while(deps) {
if(alpm_option_add_assumeinstalled(handle, deps->data) != 0) {
-- 
2.25.0


[pacman-dev] [PATCH] libalpm: free trans before databases

2020-01-19 Thread morganamilo
When releasing the handle, alpm tries to do some self clean up by
freeing the databases and transaction.

However, databases refuse to unregister is there is an in progress
transaction. Causing them to leak if the handle is released while
a transaction is active.

diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 1a378db9..02b8fc9b 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -30,6 +30,7 @@
 #include "alpm_list.h"
 #include "handle.h"
 #include "log.h"
+#include "trans.h"
 #include "util.h"
 
 /** \addtogroup alpm_interface Interface Functions
@@ -114,6 +115,8 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
 
CHECK_HANDLE(myhandle, return -1);
 
+   _alpm_trans_free(myhandle->trans);
+
/* close local database */
db = myhandle->db_local;
if(db) {
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index e3193f40..1e42f4a8 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -34,7 +34,6 @@
 #include "alpm_list.h"
 #include "util.h"
 #include "log.h"
-#include "trans.h"
 #include "alpm.h"
 #include "deps.h"
 
@@ -74,7 +73,6 @@ void _alpm_handle_free(alpm_handle_t *handle)
 #endif
 
/* free memory */
-   _alpm_trans_free(handle->trans);
FREE(handle->root);
FREE(handle->dbpath);
FREE(handle->dbext);
-- 
2.25.0


[pacman-dev] [PATCH v2] pacman+libalpm: print version names for conflicting packages

2019-11-27 Thread morganamilo
When ever pacman prints a conflict, it now prints pkgname-version,
instead of just pkgname.

alpm_conflict_t now carries pointers to alpm_pkg_t instead of just the
names of each package.

Fixes FS#12536 (point 2)

---

v2: dupe each alpm_pkg_t

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 956284bd..b0aa0671 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -247,10 +247,8 @@ typedef struct _alpm_depmissing_t {
 
 /** Conflict */
 typedef struct _alpm_conflict_t {
-   unsigned long package1_hash;
-   unsigned long package2_hash;
-   char *package1;
-   char *package2;
+   alpm_pkg_t *package1;
+   alpm_pkg_t *package2;
alpm_depend_t *reason;
 } alpm_conflict_t;
 
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 80827ed6..08ae86cb 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -49,11 +49,8 @@ static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, 
alpm_pkg_t *pkg2,
alpm_conflict_t *conflict;
 
CALLOC(conflict, 1, sizeof(alpm_conflict_t), return NULL);
-
-   conflict->package1_hash = pkg1->name_hash;
-   conflict->package2_hash = pkg2->name_hash;
-   STRDUP(conflict->package1, pkg1->name, goto error);
-   STRDUP(conflict->package2, pkg2->name, goto error);
+   ASSERT(_alpm_pkg_dup(pkg1, >package1) == 0, goto error);
+   ASSERT(_alpm_pkg_dup(pkg2, >package2) == 0, goto error);
conflict->reason = reason;
 
return conflict;
@@ -69,8 +66,8 @@ error:
 void SYMEXPORT alpm_conflict_free(alpm_conflict_t *conflict)
 {
ASSERT(conflict != NULL, return);
-   FREE(conflict->package2);
-   FREE(conflict->package1);
+   _alpm_pkg_free(conflict->package1);
+   _alpm_pkg_free(conflict->package2);
FREE(conflict);
 }
 
@@ -79,20 +76,7 @@ void SYMEXPORT alpm_conflict_free(alpm_conflict_t *conflict)
  */
 alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict)
 {
-   alpm_conflict_t *newconflict;
-   CALLOC(newconflict, 1, sizeof(alpm_conflict_t), return NULL);
-
-   newconflict->package1_hash = conflict->package1_hash;
-   newconflict->package2_hash = conflict->package2_hash;
-   STRDUP(newconflict->package1, conflict->package1, goto error);
-   STRDUP(newconflict->package2, conflict->package2, goto error);
-   newconflict->reason = conflict->reason;
-
-   return newconflict;
-
-error:
-   alpm_conflict_free(newconflict);
-   return NULL;
+   return conflict_new(conflict->package1, conflict->package2, 
conflict->reason);
 }
 
 /**
@@ -108,10 +92,10 @@ static int conflict_isin(alpm_conflict_t *needle, 
alpm_list_t *haystack)
alpm_list_t *i;
for(i = haystack; i; i = i->next) {
alpm_conflict_t *conflict = i->data;
-   if(needle->package1_hash == conflict->package1_hash
-   && needle->package2_hash == 
conflict->package2_hash
-   && strcmp(needle->package1, conflict->package1) 
== 0
-   && strcmp(needle->package2, conflict->package2) 
== 0) {
+   if(needle->package1->name_hash == conflict->package2->name_hash
+   && needle->package2->name_hash == 
conflict->package2->name_hash
+   && strcmp(needle->package1->name, 
conflict->package1->name) == 0
+   && strcmp(needle->package2->name, 
conflict->package2->name) == 0) {
return 1;
}
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 97a351fe..d26a1323 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -510,21 +510,23 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t 
**data)
 
for(i = deps; i; i = i->next) {
alpm_conflict_t *conflict = i->data;
+   const char *name1 = conflict->package1->name;
+   const char *name2 = conflict->package2->name;
alpm_pkg_t *rsync, *sync, *sync1, *sync2;
 
/* have we already removed one of the conflicting 
targets? */
-   sync1 = alpm_pkg_find(trans->add, conflict->package1);
-   sync2 = alpm_pkg_find(trans->add, conflict->package2);
+   sync1 = alpm_pkg_find(trans->add, name1);
+   sync2 = alpm_pkg_find(trans->add, name2);
if(!sync1 || !sync2) {
continue;
}
 
_alpm_log(handle, ALPM_LOG_DEBUG, "conflicting packages 
in the sync list: '%s' <-> '%s'\n",
-   conflict->package1, conflict->package2);
+   name1, name2);
 
/* if sync1 provides sync2, we remove sync2 from the 
targets, and vice versa */
-   

[pacman-dev] [PATCH v2] pacman: print error when -Fx is given invalid regex

2019-11-27 Thread morganamilo
When processing the targets for -Fx, compile all the regex ahead of
time, printing an error for each that failed to compile. Then, if they all
compiled successfully, continue with printing files.

Signed-off-by: morganamilo 

---

v2:
Add comment about why we don't free targ
Fix whitespace error

I have vim set to display trialing whitespace so normally I catch it.
Not sure why I didn't this time.

Also I agree that running all the regex against each target before
moving on to the next is a good improvement. This patch is already kinda
long though, so I'll do it another time.

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 3b6dc23b..6fcc6e9b 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -94,17 +94,27 @@ static void print_match(alpm_list_t *match, alpm_db_t 
*repo, alpm_pkg_t *pkg, in
}
 }
 
+struct filetarget {
+   char *targ;
+   int exact_file;
+   regex_t reg;
+};
+
+static void filetarget_free(struct filetarget *ftarg) {
+   regfree(>reg);
+   /* we don't own ftarg->targ so don't free it */
+   free(ftarg);
+}
+
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
-   alpm_list_t *t;
+   alpm_list_t *t, *filetargs = NULL;
 
for(t = targets; t; t = alpm_list_next(t)) {
char *targ = t->data;
-   alpm_list_t *s;
-   int found = 0;
-   regex_t reg;
size_t len = strlen(targ);
int exact_file = strchr(targ, '/') != NULL;
+   regex_t reg;
 
if(exact_file) {
while(len > 1 && targ[0] == '/') {
@@ -115,11 +125,33 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
 
if(regex) {
if(regcomp(, targ, REG_EXTENDED | REG_NOSUB | 
REG_ICASE | REG_NEWLINE) != 0) {
-   /* TODO: error message */
-   goto notfound;
+   pm_printf(ALPM_LOG_ERROR,
+   _("invalid regular expression 
'%s'\n"), targ);
+   ret = 1;
+   continue;
}
}
 
+   struct filetarget *ftarg = malloc(sizeof(struct filetarget));
+   ftarg->targ = targ;
+   ftarg->exact_file = exact_file;
+   ftarg->reg = reg;
+
+   filetargs = alpm_list_add(filetargs, ftarg);
+   }
+
+   if(ret != 0) {
+   goto cleanup;
+   }
+
+   for(t = filetargs; t; t = alpm_list_next(t)) {
+   struct filetarget *ftarg = t->data;
+   char *targ = ftarg->targ;
+   regex_t *reg = >reg;
+   int exact_file = ftarg->exact_file;
+   alpm_list_t *s;
+   int found = 0;
+
for(s = syncs; s; s = alpm_list_next(s)) {
alpm_list_t *p;
alpm_db_t *repo = s->data;
@@ -135,7 +167,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
if (regex) {
for(size_t f = 0; f < 
files->count; f++) {
char *c = 
files->files[f].name;
-   if(regexec(, c, 0, 
0, 0) == 0) {
+   if(regexec(reg, c, 0, 
0, 0) == 0) {
match = 
alpm_list_add(match, files->files[f].name);
found = 1;
}
@@ -151,7 +183,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
char *c = 
strrchr(files->files[f].name, '/');
if(c && *(c + 1)) {
if(regex) {
-   m = 
regexec(, (c + 1), 0, 0, 0);
+   m = 
regexec(reg, (c + 1), 0, 0, 0);
} else {
m = strcmp(c + 
1, targ);
}
@@ -170,16 +202,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
}
}
 
-   if(regex) {
-   regfree();
- 

[pacman-dev] [PATCH v2] alpm: fix documentation for alpm_mtree_next

2019-11-19 Thread morganamilo
End of archive is 1, not 0, also it is possible for errors to occur.

Signed-off-by: morganamilo 

---

V2: fix stray changes. Working dir was not clean

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index d3630385..9c474443 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1328,7 +1328,7 @@ struct archive *alpm_pkg_mtree_open(alpm_pkg_t *pkg);
  * @param pkg the package that the mtree file is being read from
  * @param archive the archive structure reading from the mtree file
  * @param entry an archive_entry to store the entry header information
- * @return 0 if end of archive is reached, non-zero otherwise.
+ * @return 1 if end of archive is reached, 0 on success, otherwise error
  */
 int alpm_pkg_mtree_next(const alpm_pkg_t *pkg, struct archive *archive,
struct archive_entry **entry);
-- 
2.24.0


[pacman-dev] [PATCH] alpm: fix documentation for alpm_mtree_next

2019-11-19 Thread morganamilo
End of archive is 1, not 0, also it is possible for errors to occur.

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index d3630385..9c474443 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1328,7 +1328,7 @@ struct archive *alpm_pkg_mtree_open(alpm_pkg_t *pkg);
  * @param pkg the package that the mtree file is being read from
  * @param archive the archive structure reading from the mtree file
  * @param entry an archive_entry to store the entry header information
- * @return 0 if end of archive is reached, non-zero otherwise.
+ * @return 1 if end of archive is reached, 0 on success, otherwise error
  */
 int alpm_pkg_mtree_next(const alpm_pkg_t *pkg, struct archive *archive,
struct archive_entry **entry);
diff --git a/src/pacman/query.c b/src/pacman/query.c
index bdcfc3c1..4e3ec5a0 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -194,7 +194,7 @@ static int query_fileowner(alpm_list_t *targets)
 
if(strncmp(rpath, root, rootlen) != 0) {
/* file is outside root, we know nothing can own it */
-   pm_printf(ALPM_LOG_ERROR, _("No package owns %s\n"), 
filename);
+   pm_printf(ALPM_LOG_ERROR, _("No package owns %s\n"), 
rpath);
goto targcleanup;
}
 
-- 
2.24.0


[pacman-dev] [PATCH] pacman+libalpm: print version names for conflicting packages

2019-11-13 Thread morganamilo
When ever pacman prints a conflict, it now prints pkgname-version,
instead of just pkgname.

alpm_conflict_t now carries pointers to alpm_pkg_t instead of just the
names of each package.

Fixes FS#12536 (point 2)

---

One slight difference here is that the alpm_conflict_t used to hold a
dupe of the pkgnames, while now it holds a pointer to the real
alpm_pkg_t.

We could make it so that it holds a dupe of the package but that will be
slower. Of course conflicts are pretty rare and usually involve manual
intervention anyway so what does speed matter?

Conflicts are also usually handled before the transaction finishes, so
is there ever a reason for the front end to keep the conflict around
after?

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index d3630385..d9d3e4e0 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -247,10 +247,8 @@ typedef struct _alpm_depmissing_t {
 
 /** Conflict */
 typedef struct _alpm_conflict_t {
-   unsigned long package1_hash;
-   unsigned long package2_hash;
-   char *package1;
-   char *package2;
+   alpm_pkg_t *package1;
+   alpm_pkg_t *package2;
alpm_depend_t *reason;
 } alpm_conflict_t;
 
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 80827ed6..d35fe106 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -50,17 +50,11 @@ static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, 
alpm_pkg_t *pkg2,
 
CALLOC(conflict, 1, sizeof(alpm_conflict_t), return NULL);
 
-   conflict->package1_hash = pkg1->name_hash;
-   conflict->package2_hash = pkg2->name_hash;
-   STRDUP(conflict->package1, pkg1->name, goto error);
-   STRDUP(conflict->package2, pkg2->name, goto error);
+   conflict->package1 = pkg1;
+   conflict->package2 = pkg2;
conflict->reason = reason;
 
return conflict;
-
-error:
-   alpm_conflict_free(conflict);
-   return NULL;
 }
 
 /**
@@ -69,8 +63,6 @@ error:
 void SYMEXPORT alpm_conflict_free(alpm_conflict_t *conflict)
 {
ASSERT(conflict != NULL, return);
-   FREE(conflict->package2);
-   FREE(conflict->package1);
FREE(conflict);
 }
 
@@ -82,17 +74,11 @@ alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t 
*conflict)
alpm_conflict_t *newconflict;
CALLOC(newconflict, 1, sizeof(alpm_conflict_t), return NULL);
 
-   newconflict->package1_hash = conflict->package1_hash;
-   newconflict->package2_hash = conflict->package2_hash;
-   STRDUP(newconflict->package1, conflict->package1, goto error);
-   STRDUP(newconflict->package2, conflict->package2, goto error);
+   newconflict->package1 = conflict->package1;
+   newconflict->package2 = conflict->package2;
newconflict->reason = conflict->reason;
 
return newconflict;
-
-error:
-   alpm_conflict_free(newconflict);
-   return NULL;
 }
 
 /**
@@ -108,10 +94,10 @@ static int conflict_isin(alpm_conflict_t *needle, 
alpm_list_t *haystack)
alpm_list_t *i;
for(i = haystack; i; i = i->next) {
alpm_conflict_t *conflict = i->data;
-   if(needle->package1_hash == conflict->package1_hash
-   && needle->package2_hash == 
conflict->package2_hash
-   && strcmp(needle->package1, conflict->package1) 
== 0
-   && strcmp(needle->package2, conflict->package2) 
== 0) {
+   if(needle->package1->name_hash == conflict->package2->name_hash
+   && needle->package2->name_hash == 
conflict->package2->name_hash
+   && strcmp(needle->package1->name, 
conflict->package1->name) == 0
+   && strcmp(needle->package2->name, 
conflict->package2->name) == 0) {
return 1;
}
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 59108eb9..ae491280 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -510,21 +510,23 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t 
**data)
 
for(i = deps; i; i = i->next) {
alpm_conflict_t *conflict = i->data;
+   const char *name1 = conflict->package1->name;
+   const char *name2 = conflict->package2->name;
alpm_pkg_t *rsync, *sync, *sync1, *sync2;
 
/* have we already removed one of the conflicting 
targets? */
-   sync1 = alpm_pkg_find(trans->add, conflict->package1);
-   sync2 = alpm_pkg_find(trans->add, conflict->package2);
+   sync1 = alpm_pkg_find(trans->add, name1);

[pacman-dev] [PATCH] pacman: print error when -Fx is given invalid regex

2019-11-11 Thread morganamilo
When processing the targets for -Fx, compile all the regex ahead of
time, printing an error for each that failed to compile. Then, if they all
compiled successfully, continue with printing files.

Signed-off-by: morganamilo 

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 3b6dc23b..91d891a6 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -94,17 +94,26 @@ static void print_match(alpm_list_t *match, alpm_db_t 
*repo, alpm_pkg_t *pkg, in
}
 }
 
+struct filetarget {
+   char *targ;
+   int exact_file;
+   regex_t reg;
+};
+
+static void filetarget_free(struct filetarget *ftarg) {
+   regfree(>reg);
+   free(ftarg);
+}
+
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
-   alpm_list_t *t;
+   alpm_list_t *t, *filetargs = NULL;
 
for(t = targets; t; t = alpm_list_next(t)) {
char *targ = t->data;
-   alpm_list_t *s;
-   int found = 0;
-   regex_t reg;
size_t len = strlen(targ);
int exact_file = strchr(targ, '/') != NULL;
+   regex_t reg;
 
if(exact_file) {
while(len > 1 && targ[0] == '/') {
@@ -115,11 +124,33 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
 
if(regex) {
if(regcomp(, targ, REG_EXTENDED | REG_NOSUB | 
REG_ICASE | REG_NEWLINE) != 0) {
-   /* TODO: error message */
-   goto notfound;
+   pm_printf(ALPM_LOG_ERROR, 
+   _("invalid regular expression 
'%s'\n"), targ);
+   ret = 1;
+   continue;
}
}
 
+   struct filetarget *ftarg = malloc(sizeof(struct filetarget));
+   ftarg->targ = targ;
+   ftarg->exact_file = exact_file;
+   ftarg->reg = reg;
+
+   filetargs = alpm_list_add(filetargs, ftarg);
+   }
+
+   if(ret != 0) {
+   goto cleanup;
+   }
+
+   for(t = filetargs; t; t = alpm_list_next(t)) {
+   struct filetarget *ftarg = t->data;
+   char *targ = ftarg->targ;
+   regex_t *reg = >reg;
+   int exact_file = ftarg->exact_file;
+   alpm_list_t *s;
+   int found = 0;
+
for(s = syncs; s; s = alpm_list_next(s)) {
alpm_list_t *p;
alpm_db_t *repo = s->data;
@@ -135,7 +166,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
if (regex) {
for(size_t f = 0; f < 
files->count; f++) {
char *c = 
files->files[f].name;
-   if(regexec(, c, 0, 
0, 0) == 0) {
+   if(regexec(reg, c, 0, 
0, 0) == 0) {
match = 
alpm_list_add(match, files->files[f].name);
found = 1;
}
@@ -151,7 +182,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
char *c = 
strrchr(files->files[f].name, '/');
if(c && *(c + 1)) {
if(regex) {
-   m = 
regexec(, (c + 1), 0, 0, 0);
+   m = 
regexec(reg, (c + 1), 0, 0, 0);
} else {
m = strcmp(c + 
1, targ);
}
@@ -170,16 +201,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
}
}
 
-   if(regex) {
-   regfree();
-   }
-
-notfound:
if(!found) {
ret = 1;
}
}
 
+cleanup:
+   alpm_list_free_inner(filetargs, (alpm_list_fn_free) filetarget_free);
+   alpm_list_free(filetargs);
+
return ret;
 }
 
-- 
2.23.0


[pacman-dev] [PATCH] pacman: print error message for -F with invalid regex

2019-11-05 Thread morganamilo


diff --git a/src/pacman/files.c b/src/pacman/files.c
index 19191dd8..05b6f223 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -115,7 +115,8 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
 
if(regex) {
if(regcomp(, targ, REG_EXTENDED | REG_NOSUB | 
REG_ICASE | REG_NEWLINE) != 0) {
-   /* TODO: error message */
+   pm_printf(ALPM_LOG_ERROR,
+   _("search failed: invalid 
regular expression '%s'\n"), targ);
goto notfound;
}
}
-- 
2.23.0


[pacman-dev] [PATCH] pacman+libalpm: handle search errors

2019-11-05 Thread morganamilo
Previously, pacman treated no matches and an error during search the
same.

To fix this, alpm_db_search now returns its status as an int and
instead takes the to be returned list as a param. Allowing front ends to
easily differentiate between errors and no matches.

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 4486da44..d3630385 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -997,9 +997,11 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
 /** Searches a database with regular expressions.
  * @param db pointer to the package database to search in
  * @param needles a list of regular expressions to search for
- * @return the list of packages matching all regular expressions on success, 
NULL on error
+ * @param ret the list of packages matching all regular expressions
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
  */
-alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
+int alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret);
 
 typedef enum _alpm_db_usage_t {
ALPM_DB_USAGE_SYNC = 1,
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index a443e552..cf4c865f 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -298,12 +298,14 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t 
*db)
 }
 
 /** Searches a database. */
-alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t 
*needles)
+int SYMEXPORT alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret)
 {
-   ASSERT(db != NULL, return NULL);
+   ASSERT(db != NULL && ret != NULL && *ret == NULL,
+   RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
db->handle->pm_errno = ALPM_ERR_OK;
 
-   return _alpm_db_search(db, needles);
+   return _alpm_db_search(db, needles, ret);
 }
 
 /** Sets the usage bitmask for a repo */
@@ -396,13 +398,13 @@ int _alpm_db_cmp(const void *d1, const void *d2)
return strcmp(db1->treename, db2->treename);
 }
 
-alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles)
+int _alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret)
 {
const alpm_list_t *i, *j, *k;
-   alpm_list_t *ret = NULL;
 
if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
-   return NULL;
+   return 0;
}
 
/* copy the pkgcache- we will free the list var after each needle */
@@ -415,12 +417,12 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const 
alpm_list_t *needles)
if(i->data == NULL) {
continue;
}
-   ret = NULL;
+   *ret = NULL;
targ = i->data;
_alpm_log(db->handle, ALPM_LOG_DEBUG, "searching for target 
'%s'\n", targ);
 
if(regcomp(, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | 
REG_NEWLINE) != 0) {
-   RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, NULL);
+   RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, -1);
}
 
for(j = list; j; j = j->next) {
@@ -463,18 +465,18 @@ alpm_list_t *_alpm_db_search(alpm_db_t *db, const 
alpm_list_t *needles)
_alpm_log(db->handle, ALPM_LOG_DEBUG,
"search target '%s' matched 
'%s' on package '%s'\n",
targ, matched, name);
-   ret = alpm_list_add(ret, pkg);
+   *ret = alpm_list_add(*ret, pkg);
}
}
 
/* Free the existing search list, and use the returned list for 
the
 * next needle. This allows for AND-based package searching. */
alpm_list_free(list);
-   list = ret;
+   list = *ret;
regfree();
}
 
-   return ret;
+   return 0;
 }
 
 /* Returns a new package cache from db.
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index f17444e6..e7ad98f5 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -87,7 +87,8 @@ alpm_db_t *_alpm_db_new(const char *treename, int is_local);
 void _alpm_db_free(alpm_db_t *db);
 const char *_alpm_db_path(alpm_db_t *db);
 int _alpm_db_cmp(const void *d1, const void *d2);
-alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
+int _alpm_db_search(alpm_db_t *db, const alpm_list_t *needles,
+   alpm_list_t **ret);
 alpm_db_t *_alpm_db_register_local(alpm_handle_t *handle);
 alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
int level);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 35cfcd94..ec6e78fc 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -

[pacman-dev] [PATCH] pacman: make exact_file an int

2019-11-05 Thread morganamilo
We only ever use it as a bool, no need to pass a char* around.

Signed-off-by: morganamilo 

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 19191dd8..3b6dc23b 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -58,7 +58,7 @@ static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, 
char *filename)
alpm_pkg_get_version(pkg), colstr->nocolor);
 }
 
-static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
char *exact_file)
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
int exact_file)
 {
alpm_db_t *db_local = alpm_get_localdb(config->handle);
const colstr_t *colstr = >colstr;
@@ -71,7 +71,7 @@ static void print_match(alpm_list_t *match, alpm_db_t *repo, 
alpm_pkg_t *pkg, ch
}
} else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
-   } else if(exact_file != NULL) {
+   } else if(exact_file) {
alpm_list_t *ml;
for(ml = match; ml; ml = alpm_list_next(ml)) {
char *filename = ml->data;
@@ -104,9 +104,9 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
int found = 0;
regex_t reg;
size_t len = strlen(targ);
-   char *exact_file = strchr(targ, '/');
+   int exact_file = strchr(targ, '/') != NULL;
 
-   if(exact_file != NULL) {
+   if(exact_file) {
while(len > 1 && targ[0] == '/') {
targ++;
len--;
@@ -131,7 +131,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
alpm_list_t *match = NULL;
 
-   if(exact_file != NULL) {
+   if(exact_file) {
if (regex) {
for(size_t f = 0; f < 
files->count; f++) {
char *c = 
files->files[f].name;
-- 
2.23.0


[pacman-dev] [PATCH] pacman: clarify error when alpm fails to init

2019-11-05 Thread morganamilo
Currently pacman is hard coded to print the dbpath, then the error alpm
returned. Even though the error could really be caused by anything.

So instead just print the arugemnts given to alpm and not assume the
resulting error message is releated to either path.

Fixes FS#59595

Signed-off-by: morganamilo 

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 468a3e02..42946189 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -766,8 +766,8 @@ static int setup_libalpm(void)
/* initialize library */
handle = alpm_initialize(config->rootdir, config->dbpath, );
if(!handle) {
-   pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm 
library\n(%s: %s)\n"),
-   alpm_strerror(err), config->dbpath);
+   pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library 
(root: %s, dbpath: %s):\n%s\n"),
+   config->rootdir, config->dbpath, alpm_strerror(err));
if(err == ALPM_ERR_DB_VERSION) {
fprintf(stderr, _("try running pacman-db-upgrade\n"));
}
-- 
2.23.0


[pacman-dev] [PATCH] makepkg: don't warn when PACKAGER is unset

2019-10-22 Thread morganamilo
makepkg now complains when PACKAGER is not in the format
"name ".

Hide this warning when PACKAGER is unset but still warn if it is set to
something out of format.

diff --git a/scripts/libmakepkg/lint_config/variable.sh.in 
b/scripts/libmakepkg/lint_config/variable.sh.in
index aa9f6c07..61ef4c09 100644
--- a/scripts/libmakepkg/lint_config/variable.sh.in
+++ b/scripts/libmakepkg/lint_config/variable.sh.in
@@ -62,7 +62,7 @@ lint_config_variables() {
 
# pacman should be able to extract an email address from PACKAGER for 
WKD key lookup
local match='^([^<>]+ )?<[^<>]*>$'
-   if ! [[ $PACKAGER =~ $match ]]; then
+   if ! [[ $PACKAGER == "Unknown Packager" || $PACKAGER =~ $match ]]; then
warning "$(gettext "PACKAGER should have the format 'Example 
Name '")"
fi
 
-- 
2.23.0


[pacman-dev] [PATCH v2 1/2] libalpm: fix segfault when -Qip'ing a package

2019-10-15 Thread morganamilo
The dummy checksigs function never sets count to 0, leaving it
unitialized. This caused the siglist cleanup to try and free the empty
list.

---
v2: remove UNUSED

diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 30d057a3..fc537dd3 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -800,8 +800,9 @@ int _alpm_key_import(alpm_handle_t UNUSED *handle, const 
char UNUSED *uid,
 }
 
 int _alpm_gpgme_checksig(alpm_handle_t UNUSED *handle, const char UNUSED *path,
-   const char UNUSED *base64_sig, alpm_siglist_t UNUSED *siglist)
+   const char UNUSED *base64_sig, alpm_siglist_t *siglist)
 {
+   siglist->count = 0;
return -1;
 }
 #endif /* HAVE_LIBGPGME */
-- 
2.23.0


[pacman-dev] [PATCH v2 2/2] libalpm: set errno in signing dummy functions

2019-10-15 Thread morganamilo
This allows pacman to print the correct error message when checking keys
and libalpm has been compiled without gpgme support.
---
v2: remove UNUSED

diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index fc537dd3..7fed862e 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -788,21 +788,24 @@ error:
 }
 
 #else /* HAVE_LIBGPGME */
-int _alpm_key_in_keychain(alpm_handle_t UNUSED *handle, const char UNUSED *fpr)
+int _alpm_key_in_keychain(alpm_handle_t *handle, const char UNUSED *fpr)
 {
+   handle->pm_errno = ALPM_ERR_MISSING_CAPABILITY_SIGNATURES;
return -1;
 }
 
-int _alpm_key_import(alpm_handle_t UNUSED *handle, const char UNUSED *uid,
+int _alpm_key_import(alpm_handle_t *handle, const char UNUSED *uid,
const char UNUSED *fpr)
 {
+   handle->pm_errno = ALPM_ERR_MISSING_CAPABILITY_SIGNATURES;
return -1;
 }
 
-int _alpm_gpgme_checksig(alpm_handle_t UNUSED *handle, const char UNUSED *path,
+int _alpm_gpgme_checksig(alpm_handle_t *handle, const char UNUSED *path,
const char UNUSED *base64_sig, alpm_siglist_t *siglist)
 {
siglist->count = 0;
+   handle->pm_errno = ALPM_ERR_MISSING_CAPABILITY_SIGNATURES;
return -1;
 }
 #endif /* HAVE_LIBGPGME */
-- 
2.23.0


[pacman-dev] [PATCH 2/2] libalpm: set errno in signing dummy functions

2019-10-15 Thread morganamilo
This allows pacman to print the correct error message when checking keys
and libalpm has been compiled without gpgme support.

diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 4cb31e7c..8522e049 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -790,12 +790,14 @@ error:
 #else /* HAVE_LIBGPGME */
 int _alpm_key_in_keychain(alpm_handle_t UNUSED *handle, const char UNUSED *fpr)
 {
+   handle->pm_errno = ALPM_ERR_MISSING_CAPABILITY_SIGNATURES;
return -1;
 }
 
 int _alpm_key_import(alpm_handle_t UNUSED *handle, const char UNUSED *uid,
const char UNUSED *fpr)
 {
+   handle->pm_errno = ALPM_ERR_MISSING_CAPABILITY_SIGNATURES;
return -1;
 }
 
@@ -803,6 +805,7 @@ int _alpm_gpgme_checksig(alpm_handle_t UNUSED *handle, 
const char UNUSED *path,
const char UNUSED *base64_sig, alpm_siglist_t UNUSED *siglist)
 {
siglist->count = 0;
+   handle->pm_errno = ALPM_ERR_MISSING_CAPABILITY_SIGNATURES;
return -1;
 }
 #endif /* HAVE_LIBGPGME */
-- 
2.23.0


[pacman-dev] [PATCH 1/2] libalpm: fix segfault when -Qip'ing a package

2019-10-15 Thread morganamilo
The dummy checksigs function never sets count to 0, leaving it
unitialized. This caused the siglist cleanup to try and free the empty
list.

diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 30d057a3..4cb31e7c 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -802,6 +802,7 @@ int _alpm_key_import(alpm_handle_t UNUSED *handle, const 
char UNUSED *uid,
 int _alpm_gpgme_checksig(alpm_handle_t UNUSED *handle, const char UNUSED *path,
const char UNUSED *base64_sig, alpm_siglist_t UNUSED *siglist)
 {
+   siglist->count = 0;
return -1;
 }
 #endif /* HAVE_LIBGPGME */
-- 
2.23.0


[pacman-dev] [PATCH] pacman: return 1 when -F has no results

2019-10-12 Thread morganamilo
---

This is basically my V2 for "pacman: better handle -F when file is not
found".

With the freeze coming up and me not having that much time to do pacman
stuff, this is the best I've got right now.

I have been thinking about the original patch and I don't really like it
much any more.

One issue is that -Qi and -Si give error messages when there's no match,
but -Qs and -Ss do not. So for consistency sake should -Fx not give an
error message?

Also -Qs and -Ss both fail to report when an error occurs during
search. So just like how -F currently does not report regex errors,
neither does -Q and -S.

Lastly there is the issue of how to handle regex errors in -F? Because
the search is done in the front end, the error does not come from alpm.
We could just do `alpm_strerror(ALPM_ERR_REGEX)` to reuse alpm's
error message. Or maybe move it into the backend along side
alpm_db_search?

I'll leave all this open to discussion and hope this small patch is
mostly agreeable so it can make it in this release.
---
 src/pacman/files.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 8e518486..af11666d 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -176,11 +176,11 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
 
 notfound:
if(!found) {
-   ret++;
+   ret = 1;
}
}
 
-   return 0;
+   return ret;
 }
 
 static void dump_file_list(alpm_pkg_t *pkg) {
-- 
2.23.0


[pacman-dev] [PATCH 4/4] pacman: speed up deptest

2019-09-08 Thread morganamilo
Try and find an exact match via pkgcache before iterating the entire
localdb.

Gives a noticeable speed up for exact matches e.g. `pacman -T zlib`

---

Do note this fails for versioned exact matches. "zlib>1" will not take
the faster route because alpm_db_get_pkgfromcache() does not work for
versioned deps.

I do have a solution for this in an alternative patch which adds
alpm_db_find_local_satisfier() "62 insertions(+), 7 deletions(-)"

But is that worth it just for a speed up on -T? Nowhere else really
makes extensive use of searching the localdb.
---
 src/pacman/deptest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c
index 597eee42..76bf223e 100644
--- a/src/pacman/deptest.c
+++ b/src/pacman/deptest.c
@@ -32,11 +32,13 @@ int pacman_deptest(alpm_list_t *targets)
alpm_list_t *i;
alpm_list_t *deps = NULL;
alpm_db_t *localdb = alpm_get_localdb(config->handle);
+   alpm_list_t *pkgcache = alpm_db_get_pkgcache(localdb);
 
for(i = targets; i; i = alpm_list_next(i)) {
char *target = i->data;
 
-   if(!alpm_find_satisfier(alpm_db_get_pkgcache(localdb), target)) 
{
+   if(!alpm_db_get_pkg(localdb, target) &&
+   !alpm_find_satisfier(pkgcache, target)) {
deps = alpm_list_add(deps, target);
}
}
-- 
2.23.0


[pacman-dev] [PATCH 1/4] libalpm: fix incorrect documentation

2019-09-08 Thread morganamilo
---
 lib/libalpm/deps.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 71185c68..ce7869c3 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -643,10 +643,9 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, 
int include_explicit)
  * @param dep is the dependency to search for
  * @param dbs are the databases to search
  * @param excluding are the packages to exclude from the search
- * @param prompt if true, will cause an unresolvable dependency to issue an
- *interactive prompt asking whether the package should be removed from
- *the transaction or the transaction aborted; if false, simply returns
- *an error code without prompting
+ * @param prompt if true, ask an alpm_question_install_ignorepkg_t to decide
+ *if ignored packages should be installed; if false, skip ignored
+ *packages.
  * @return the resolved package
  **/
 static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
@@ -766,8 +765,11 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, 
alpm_depend_t *dep,
 
 /** Find a package satisfying a specified dependency.
  * First look for a literal, going through each db one by one. Then look for
- * providers. The first satisfier found is returned.
+ * providers. The first satisfier that belongs to an installed package is
+ * returned. If no providers belong to an installed package then an
+ * alpm_question_select_provider_t is created to select the provider.
  * The dependency can include versions with depmod operators.
+ *
  * @param handle the context handle
  * @param dbs an alpm_list_t* of alpm_db_t where the satisfier will be searched
  * @param depstring package or provision name, versioned or not
-- 
2.23.0


[pacman-dev] [PATCH 3/4] libalpm: short circuit alpm_find_dbs_satisfier

2019-09-08 Thread morganamilo
when a satisfying package is already installed, we always pick it
instead of prompting the user. So we can return that package as soon as
we find it, instead of waiting until we've iterated through all the
databases.
---
 lib/libalpm/deps.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 322c4e7e..f69f24ad 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -719,20 +719,19 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, 
alpm_depend_t *dep,
}
_alpm_log(handle, ALPM_LOG_DEBUG, "provider 
found (%s provides %s)\n",
pkg->name, dep->name);
+
+   /* provide is already installed so return early 
instead of prompting later */
+   if(_alpm_db_get_pkgfromcache(handle->db_local, 
pkg->name)) {
+   alpm_list_free(providers);
+   return pkg;
+   }
+
providers = alpm_list_add(providers, pkg);
/* keep looking for other providers in the all 
dbs */
}
}
}
 
-   /* first check if one provider is already installed locally */
-   for(i = providers; i; i = i->next) {
-   alpm_pkg_t *pkg = i->data;
-   if(_alpm_db_get_pkgfromcache(handle->db_local, pkg->name)) {
-   alpm_list_free(providers);
-   return pkg;
-   }
-   }
count = alpm_list_count(providers);
if(count >= 1) {
alpm_question_select_provider_t question = {
-- 
2.23.0


[pacman-dev] [PATCH 2/4] libalpm: resolvedep(): don't compare names twice

2019-09-08 Thread morganamilo
If we failed to get the pkg from pkgcache then we know no satisfying
package exists by name. So only compare provides.
---
 lib/libalpm/deps.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index ce7869c3..322c4e7e 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -698,7 +698,8 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, 
alpm_depend_t *dep,
for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
alpm_pkg_t *pkg = j->data;
if((pkg->name_hash != dep->name_hash || 
strcmp(pkg->name, dep->name) != 0)
-   && _alpm_depcmp(pkg, dep) && 
!alpm_pkg_find(excluding, pkg->name)) {
+   && _alpm_depcmp_provides(dep, 
alpm_pkg_get_provides(pkg))
+   && !alpm_pkg_find(excluding, 
pkg->name)) {
if(alpm_pkg_should_ignore(handle, pkg)) {
alpm_question_install_ignorepkg_t 
question = {
.type = 
ALPM_QUESTION_INSTALL_IGNOREPKG,
-- 
2.23.0


[pacman-dev] [PATCH] libalpm: fix documentation for alpm_pkg_mtree_next

2019-06-13 Thread morganamilo
libarchive uses 1 for EOF, not 0. Instead of using the actual ints, use
libarchive's error codes.
---

By the way, not familiar with doxygen. Is my wording fine or is there
some built in "see also" functionality?

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ffb2ad96..ece894cf 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1326,7 +1326,8 @@ struct archive *alpm_pkg_mtree_open(alpm_pkg_t *pkg);
  * @param pkg the package that the mtree file is being read from
  * @param archive the archive structure reading from the mtree file
  * @param entry an archive_entry to store the entry header information
- * @return 0 if end of archive is reached, non-zero otherwise.
+ * @return ARCHIVE_OK on success, ARCHIVE_EOF if end of archive is reached,
+ * otherwise an error occured (see archive.h).
  */
 int alpm_pkg_mtree_next(const alpm_pkg_t *pkg, struct archive *archive,
struct archive_entry **entry);
-- 
2.21.0


[pacman-dev] [PATCH] pacman: correctly free lists

2019-06-13 Thread morganamilo


diff --git a/src/pacman/database.c b/src/pacman/database.c
index f3b890ce..7a792bad 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -105,7 +105,8 @@ static int check_db_missing_deps(alpm_list_t *pkglist)
free(depstring);
ret++;
}
-   FREELIST(data);
+   alpm_list_free_inner(data, (alpm_list_fn_free)alpm_depmissing_free);
+   alpm_list_free(data);
return ret;
 }
 
@@ -159,7 +160,8 @@ static int check_db_local_package_conflicts(alpm_list_t 
*pkglist)
conflict->package1, conflict->package2);
ret++;
}
-   FREELIST(data);
+   alpm_list_free_inner(data, (alpm_list_fn_free)alpm_conflict_free);
+   alpm_list_free(data);
return ret;
 }
 
-- 
2.21.0


[pacman-dev] [PATCH] Correctly report a download failiure for 404s

2019-06-11 Thread morganamilo
Currently when caling alpm_trans_commit, if fetching a package restults
in a 404 (or other non 400 response code), the function returns -1 but
errno is never set.

Thish patch sets errno to ALPM_ERR_RETRIEVE.

diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 05813c40..e5696bb0 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -454,6 +454,7 @@ static int curl_download_internal(struct dload_payload 
*payload,
if(payload->respcode >= 400) {
payload->unlink_on_fail = 1;
if(!payload->errors_ok) {
+   handle->pm_errno = ALPM_ERR_RETRIEVE;
/* non-translated message is same as 
libcurl */
snprintf(error_buffer, 
sizeof(error_buffer),
"The requested URL 
returned error: %ld", payload->respcode);
-- 
2.21.0


[pacman-dev] [PATCH] pacman: fix error during -Fy

2019-06-06 Thread morganamilo
Signed-off-by: morganamilo 

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 74d06815..8e518486 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -300,7 +300,7 @@ int pacman_files(alpm_list_t *targets)
return files_list(files_dbs, targets);
}
 
-   if(targets == NULL) {
+   if(targets == NULL && !config->op_s_sync) {
pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for 
help)\n"));
return 1;
}
-- 
2.21.0


[pacman-dev] [PATCH v4 2/2] pacman: rework the UI of -F

2019-05-29 Thread morganamilo
Reworks the UI of -F according to FS#47949

In short -F replaces both -Fs and -Fo.

Searching for an exact path (target contains "/"), causes the output to
switch to the old -Fo output. Otherwise the old -Fs output is used.

Also strip the leading "/" from targets like how -Qo does.
---

Docs changed and wip title removed.

 doc/pacman.8.asciidoc |  14 ++---
 src/pacman/files.c| 125 --
 src/pacman/pacman.c   |  19 +--
 3 files changed, 53 insertions(+), 105 deletions(-)

diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc
index fe95178d..68b62a90 100644
--- a/doc/pacman.8.asciidoc
+++ b/doc/pacman.8.asciidoc
@@ -488,14 +488,8 @@ File Options (apply to '-F')[[FO]]
 *-l, \--list*::
List the files owned by the queried package.
 
-*-s, \--search*::
-   Search package file names for matching strings.
-
 *-x, --regex*::
-   Treat arguments to '--search' as regular expressions.
-
-*-o, \--owns*::
-   Search for packages that own a particular file.
+   Interpret each query as a regular expression.
 
 *-q, \--quiet*::
Show less information for certain file operations. This is useful when
@@ -503,9 +497,9 @@ File Options (apply to '-F')[[FO]]
'--machinereadable' instead.
 
 *--machinereadable*::
-   Use a machine readable output format for '--list', '--search' and
-   '--owns'. The format is 'repository\0pkgname\0pkgver\0path\n' with '\0'
-   being the NULL character and '\n' a linefeed.
+   Print each match in a machine readable output format. The format is
+   'repository\0pkgname\0pkgver\0path\n' with '\0' being the NULL character
+   and '\n' a linefeed.
 
 Handling Config Files[[HCF]]
 
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 26f96a67..74d06815 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -58,53 +58,7 @@ static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, 
char *filename)
alpm_pkg_get_version(pkg), colstr->nocolor);
 }
 
-static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
-   int ret = 0;
-   alpm_list_t *t;
-
-   for(t = targets; t; t = alpm_list_next(t)) {
-   char *filename = t->data;
-   int found = 0;
-   alpm_list_t *s;
-   size_t len = strlen(filename);
-
-   while(len > 1 && filename[0] == '/') {
-   filename++;
-   len--;
-   }
-
-   for(s = syncs; s; s = alpm_list_next(s)) {
-   alpm_list_t *p;
-   alpm_db_t *repo = s->data;
-   alpm_list_t *packages = alpm_db_get_pkgcache(repo);
-
-   for(p = packages; p; p = alpm_list_next(p)) {
-   alpm_pkg_t *pkg = p->data;
-   alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
-
-   if(alpm_filelist_contains(files, filename)) {
-   if(config->op_f_machinereadable) {
-   
print_line_machinereadable(repo, pkg, filename);
-   } else if(!config->quiet) {
-   print_owned_by(repo, pkg, 
filename);
-   } else {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   }
-
-   found = 1;
-   }
-   }
-   }
-
-   if(!found) {
-   ret++;
-   }
-   }
-
-   return 0;
-}
-
-static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
char *exact_file)
 {
alpm_db_t *db_local = alpm_get_localdb(config->handle);
const colstr_t *colstr = >colstr;
@@ -117,6 +71,12 @@ static void print_match(alpm_list_t *match, alpm_db_t 
*repo, alpm_pkg_t *pkg)
}
} else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
+   } else if(exact_file != NULL) {
+   alpm_list_t *ml;
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   print_owned_by(repo, pkg, filename);
+   }
} else {
alpm_list_t *ml;
printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo),
@@ -143,6 +103,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_list_t *s;
int found = 0;
regex_t reg;
+   size_t len = strlen(targ);
+   char 

[pacman-dev] [PATCH v3 1/2] pacman: refactor file match printing to their own functions

2019-05-28 Thread morganamilo
---
 src/pacman/files.c | 71 ++
 1 file changed, 41 insertions(+), 30 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index fa4170bd..26f96a67 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -49,6 +49,15 @@ static void dump_pkg_machinereadable(alpm_db_t *db, 
alpm_pkg_t *pkg)
}
 }
 
+static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, char *filename)
+{
+   const colstr_t *colstr = >colstr;
+   printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename,
+   colstr->repo, alpm_db_get_name(db), colstr->title,
+   alpm_pkg_get_name(pkg), colstr->version,
+   alpm_pkg_get_version(pkg), colstr->nocolor);
+}
+
 static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
int ret = 0;
alpm_list_t *t;
@@ -77,11 +86,7 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t 
*targets) {
if(config->op_f_machinereadable) {

print_line_machinereadable(repo, pkg, filename);
} else if(!config->quiet) {
-   const colstr_t *colstr = 
>colstr;
-   printf(_("%s is owned by 
%s%s/%s%s %s%s%s\n"), filename,
-   colstr->repo, 
alpm_db_get_name(repo), colstr->title,
-   
alpm_pkg_get_name(pkg), colstr->version,
-   
alpm_pkg_get_version(pkg), colstr->nocolor);
+   print_owned_by(repo, pkg, 
filename);
} else {
printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
}
@@ -99,11 +104,39 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t 
*targets) {
return 0;
 }
 
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
+{
+   alpm_db_t *db_local = alpm_get_localdb(config->handle);
+   const colstr_t *colstr = >colstr;
+
+   if(config->op_f_machinereadable) {
+   alpm_list_t *ml;
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   print_line_machinereadable(repo, pkg, filename);
+   }
+   } else if(config->quiet) {
+   printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
+   } else {
+   alpm_list_t *ml;
+   printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo),
+   colstr->title, alpm_pkg_get_name(pkg),
+   colstr->version, alpm_pkg_get_version(pkg), 
colstr->nocolor);
+
+   print_groups(pkg);
+   print_installed(db_local, pkg);
+   printf("\n");
+
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   printf("%s\n", filename);
+   }
+   }
+}
+
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
-   alpm_db_t *db_local = alpm_get_localdb(config->handle);
alpm_list_t *t;
-   const colstr_t *colstr = >colstr;
 
for(t = targets; t; t = alpm_list_next(t)) {
char *targ = t->data;
@@ -148,29 +181,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
}
 
if(match != NULL) {
-   if(config->op_f_machinereadable) {
-   alpm_list_t *ml;
-   for(ml = match; ml; ml = 
alpm_list_next(ml)) {
-   char *filename = 
ml->data;
-   
print_line_machinereadable(repo, pkg, filename);
-   }
-   } else if(config->quiet) {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   } else {
-   alpm_list_t *ml;
-   printf("%s%s/%s%s %s%s%s", 
colstr->repo, alpm_db_get_name(repo),
-   colstr->title, 
alpm_pkg_get_name(pkg),
-   colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
-
-   print_groups(pkg);
- 

[pacman-dev] [PATCH v3 2/2] wip: pacman: rework the UI of -F

2019-05-28 Thread morganamilo
Reworks the UI of -F according to FS#47949

In short -F replaces both -Fs and -Fo.

Searching for an exact path (target contains "/"), causes the output to
switch to the old -Fo output. Otherwise the old -Fs output is used.

Also strip the leading "/" from targets like how -Qo does.

TODO: docs
---
 src/pacman/files.c  | 125 +---
 src/pacman/pacman.c |  17 +-
 2 files changed, 49 insertions(+), 93 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 26f96a67..74d06815 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -58,53 +58,7 @@ static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, 
char *filename)
alpm_pkg_get_version(pkg), colstr->nocolor);
 }
 
-static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
-   int ret = 0;
-   alpm_list_t *t;
-
-   for(t = targets; t; t = alpm_list_next(t)) {
-   char *filename = t->data;
-   int found = 0;
-   alpm_list_t *s;
-   size_t len = strlen(filename);
-
-   while(len > 1 && filename[0] == '/') {
-   filename++;
-   len--;
-   }
-
-   for(s = syncs; s; s = alpm_list_next(s)) {
-   alpm_list_t *p;
-   alpm_db_t *repo = s->data;
-   alpm_list_t *packages = alpm_db_get_pkgcache(repo);
-
-   for(p = packages; p; p = alpm_list_next(p)) {
-   alpm_pkg_t *pkg = p->data;
-   alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
-
-   if(alpm_filelist_contains(files, filename)) {
-   if(config->op_f_machinereadable) {
-   
print_line_machinereadable(repo, pkg, filename);
-   } else if(!config->quiet) {
-   print_owned_by(repo, pkg, 
filename);
-   } else {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   }
-
-   found = 1;
-   }
-   }
-   }
-
-   if(!found) {
-   ret++;
-   }
-   }
-
-   return 0;
-}
-
-static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg, 
char *exact_file)
 {
alpm_db_t *db_local = alpm_get_localdb(config->handle);
const colstr_t *colstr = >colstr;
@@ -117,6 +71,12 @@ static void print_match(alpm_list_t *match, alpm_db_t 
*repo, alpm_pkg_t *pkg)
}
} else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
+   } else if(exact_file != NULL) {
+   alpm_list_t *ml;
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   print_owned_by(repo, pkg, filename);
+   }
} else {
alpm_list_t *ml;
printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo),
@@ -143,6 +103,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_list_t *s;
int found = 0;
regex_t reg;
+   size_t len = strlen(targ);
+   char *exact_file = strchr(targ, '/');
+
+   if(exact_file != NULL) {
+   while(len > 1 && targ[0] == '/') {
+   targ++;
+   len--;
+   }
+   }
 
if(regex) {
if(regcomp(, targ, REG_EXTENDED | REG_NOSUB | 
REG_ICASE | REG_NEWLINE) != 0) {
@@ -158,30 +127,44 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
int m;
 
for(p = packages; p; p = alpm_list_next(p)) {
-   size_t f = 0;
-   char* c;
alpm_pkg_t *pkg = p->data;
alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
alpm_list_t *match = NULL;
 
-   while(f < files->count) {
-   c = strrchr(files->files[f].name, '/');
-   if(c && *(c + 1)) {
-   if(regex) {
-   m = regexec(, (c + 
1), 0, 0, 0);
-   } else {
-   

[pacman-dev] [PATCH v2] wip: pacman: rework the UI of -F

2019-04-20 Thread morganamilo
Reworks the UI of -F according to FS#47949

In short -F replaces both -Fs and -Fo.
--regex/-x has been replaced with --search/-s.
--oneline/-o can be used to change the output format to match the old -Fo

Signed-off-by: morganamilo 
---

v1:
This patch is WIP. Functional changes made,
documentation still needs to be changed.

Additionally I think https://bugs.archlinux.org/task/47949#comment143477
Is a good idea and I will probably be included in v2

v2:
added --oneline/-o

diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index f45ed436..523b54a5 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -90,8 +90,8 @@ typedef struct __config_t {
unsigned short op_s_search;
unsigned short op_s_upgrade;
 
-   unsigned short op_f_regex;
unsigned short op_f_machinereadable;
+   unsigned short op_f_oneline;
 
unsigned short group;
unsigned short noask;
@@ -200,6 +200,7 @@ enum {
OP_SEARCH,
OP_REGEX,
OP_MACHINEREADABLE,
+   OP_ONELINE,
OP_UNREQUIRED,
OP_UPGRADES,
OP_SYSUPGRADE,
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 3ebd9b9b..905e16ed 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -49,54 +49,13 @@ static void dump_pkg_machinereadable(alpm_db_t *db, 
alpm_pkg_t *pkg)
}
 }
 
-static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
-   int ret = 0;
-   alpm_list_t *t;
-
-   for(t = targets; t; t = alpm_list_next(t)) {
-   char *filename = t->data;
-   int found = 0;
-   alpm_list_t *s;
-   size_t len = strlen(filename);
-
-   while(len > 1 && filename[0] == '/') {
-   filename++;
-   len--;
-   }
-
-   for(s = syncs; s; s = alpm_list_next(s)) {
-   alpm_list_t *p;
-   alpm_db_t *repo = s->data;
-   alpm_list_t *packages = alpm_db_get_pkgcache(repo);
-
-   for(p = packages; p; p = alpm_list_next(p)) {
-   alpm_pkg_t *pkg = p->data;
-   alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
-
-   if(alpm_filelist_contains(files, filename)) {
-   if(config->op_f_machinereadable) {
-   
print_line_machinereadable(repo, pkg, filename);
-   } else if(!config->quiet) {
-   const colstr_t *colstr = 
>colstr;
-   printf(_("%s is owned by 
%s%s/%s%s %s%s%s\n"), filename,
-   colstr->repo, 
alpm_db_get_name(repo), colstr->title,
-   
alpm_pkg_get_name(pkg), colstr->version,
-   
alpm_pkg_get_version(pkg), colstr->nocolor);
-   } else {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   }
-
-   found = 1;
-   }
-   }
-   }
-
-   if(!found) {
-   ret++;
-   }
-   }
-
-   return 0;
+static void print_owned_by(alpm_db_t *db, alpm_pkg_t *pkg, char *filename)
+{
+   const colstr_t *colstr = >colstr;
+   printf(_("%s is owned by %s%s/%s%s %s%s%s\n"), filename,
+   colstr->repo, alpm_db_get_name(db), colstr->title,
+   alpm_pkg_get_name(pkg), colstr->version,
+   alpm_pkg_get_version(pkg), colstr->nocolor);
 }
 
 static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
@@ -110,6 +69,12 @@ static void print_match(alpm_list_t *match, alpm_db_t 
*repo, alpm_pkg_t *pkg)
char *filename = ml->data;
print_line_machinereadable(repo, pkg, filename);
}
+   } else if(config->op_f_oneline) {
+   alpm_list_t *ml;
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   print_owned_by(repo, pkg, filename);
+   }
} else if(config->quiet) {
printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
} else {
@@ -138,6 +103,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_list_t *s;
int found = 0;
regex_t reg;
+   size_t len =

[pacman-dev] [PATCH] pacman: fix segfault when Usage is specified without a value

2019-03-06 Thread morganamilo
And extract all the common code to a macro.

Signed-off-by: morganamilo 
---
 src/pacman/conf.c | 38 --
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 29f69052..cca3657e 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -844,28 +844,28 @@ static int _parse_repo(const char *key, char *value, 
const char *file,
int ret = 0;
config_repo_t *repo = section->repo;
 
+#define CHECK_VALUE(val) do { \
+   if(!val) { \
+   pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive 
'%s' needs a value\n"), \
+   file, line, key); \
+   return 1; \
+   } \
+} while(0)
+
if(strcmp(key, "Server") == 0) {
-   if(!value) {
-   pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: 
directive '%s' needs a value\n"),
-   file, line, key);
-   ret = 1;
-   } else {
-   repo->servers = alpm_list_add(repo->servers, 
strdup(value));
-   }
+   CHECK_VALUE(value);
+   repo->servers = alpm_list_add(repo->servers, strdup(value));
} else if(strcmp(key, "SigLevel") == 0) {
-   if(!value) {
-   pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: 
directive '%s' needs a value\n"),
-   file, line, key);
-   } else {
-   alpm_list_t *values = NULL;
-   setrepeatingoption(value, "SigLevel", );
-   if(values) {
-   ret = process_siglevel(values, >siglevel,
-   >siglevel_mask, file, 
line);
-   FREELIST(values);
-   }
+   CHECK_VALUE(value);
+   alpm_list_t *values = NULL;
+   setrepeatingoption(value, "SigLevel", );
+   if(values) {
+   ret = process_siglevel(values, >siglevel,
+   >siglevel_mask, file, line);
+   FREELIST(values);
}
} else if(strcmp(key, "Usage") == 0) {
+   CHECK_VALUE(value);
alpm_list_t *values = NULL;
setrepeatingoption(value, "Usage", );
if(values) {
@@ -881,6 +881,8 @@ static int _parse_repo(const char *key, char *value, const 
char *file,
file, line, key, repo->name);
}
 
+#undef CHECK_VALUE
+
return ret;
 }
 
-- 
2.21.0


[pacman-dev] [PATCH] fix various typos

2019-02-02 Thread morganamilo
Signed-off-by: morganamilo 
---
 NEWS  | 12 ++--
 configure.ac  |  2 +-
 doc/PKGBUILD.5.asciidoc   |  4 ++--
 lib/libalpm/package.h |  2 +-
 lib/libalpm/signing.c |  2 +-
 meson_options.txt |  2 +-
 scripts/libmakepkg/executable/strip.sh.in |  2 +-
 scripts/libmakepkg/util/pkgbuild.sh.in|  2 +-
 src/pacman/util.c |  2 +-
 9 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index a182d65e..6ae93a9d 100644
--- a/NEWS
+++ b/NEWS
@@ -167,7 +167,7 @@ VERSION DESCRIPTION
   - fix triggering of Install hooks (FS#47996)
   - fix handling of stdin scripts called by pacman
   - hook activity is logged
-  - documentataion updates for alpm-hooks (FS#48080)
+  - documentation updates for alpm-hooks (FS#48080)
   - makepkg:
 - increase robustness of variable array checks
 - makepkg -g does not perform current architecture checks
@@ -259,9 +259,9 @@ VERSION DESCRIPTION
 - Fix removal of static libraries when the shared library
   uses the absolute path in symbolic links (FS#43395)
 - Improve Bazaar cloning (FS#43448)
-- Fix issues with architecture dependant checksum
+- Fix issues with architecture dependent checksum
   verification (FS#43192)
-- Fix .SRCINFO file with architecture dependant fields
+- Fix .SRCINFO file with architecture dependent fields
   (FS#43247)
 - Fix compatibility with older bash versions
 - Allow git checkouts to be downloaded into directory ending
@@ -351,7 +351,7 @@ VERSION DESCRIPTION
 - checkupdates: rename CHECKUPDATE_DB to CHECKUPDATES_DB
 - pacdiff: add a "Quit" option, and many other improvements
 - pacsysclean is removed
-4.1.2 - validate %FILEPATH% when parsing repos to prevent arbitary
+4.1.2 - validate %FILEPATH% when parsing repos to prevent arbitrary
 file overwrites from malicious databases
   - makepkg:
 - restrict package name from starting with a dot
@@ -816,7 +816,7 @@ VERSION DESCRIPTION
   - repo-add: use openssl instead of md5sum
   - simplify doc building process for ease of development
   - ensure correct handling of syscall interruptions
-  - readd missing newline on -Qi/-Si output (FS#11331)
+  - read missing newline on -Qi/-Si output (FS#11331)
   - fix TotalDownload regression (FS#11339)
   - makepkg:
 - replace getopt with an internal function
@@ -1262,7 +1262,7 @@ VERSION DESCRIPTION
 external download utility like wget
   - added a license field to package meta-data
   - add url support to -A and -U operations (download packages)
-  - -Ss now searches thru provides fields
+  - -Ss now searches through provides fields
   - added --dbonly option to -R
 2.7.6 - added --print-uris option
   - fixed an http download bug (FS#667)
diff --git a/configure.ac b/configure.ac
index 6f336022..415ed3cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,7 +72,7 @@ if test "x$CFLAGS" = "x"; then
   CFLAGS=""
 fi
 
-# Set subsitution values for version stuff in Makefiles and anywhere else,
+# Set substitution values for version stuff in Makefiles and anywhere else,
 # and put LIB_VERSION in config.h
 AC_SUBST(LIB_VERSION)
 AC_SUBST(LIB_VERSION_INFO)
diff --git a/doc/PKGBUILD.5.asciidoc b/doc/PKGBUILD.5.asciidoc
index f12effde..32668adc 100644
--- a/doc/PKGBUILD.5.asciidoc
+++ b/doc/PKGBUILD.5.asciidoc
@@ -60,8 +60,8 @@ systems (see below).
allows package maintainers to make updates to the package's configure
flags, for example. This is typically set to '1' for each new upstream
software release and incremented for intermediate PKGBUILD updates. The
-   variable is a postive integer, with an optional subrelease level
-   specified by adding another postive integer separated by a period
+   variable is a positive integer, with an optional subrelease level
+   specified by adding another positive integer separated by a period
(i.e. in the form x.y).
 
 *epoch*::
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index b11d5dda..fbcde266 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -38,7 +38,7 @@
 /** Package operations struct. This struct contains function pointers to
  * all methods used to access data in a package to allow for things such
  * as l

[pacman-dev] [PATCH 1/2] pacman: refactor file match printing to its own function

2019-02-02 Thread morganamilo
Signed-off-by: morganamilo 
---
 src/pacman/files.c | 56 +-
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index fa4170bd..3ebd9b9b 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -99,11 +99,39 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t 
*targets) {
return 0;
 }
 
+static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
+{
+   alpm_db_t *db_local = alpm_get_localdb(config->handle);
+   const colstr_t *colstr = >colstr;
+
+   if(config->op_f_machinereadable) {
+   alpm_list_t *ml;
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   print_line_machinereadable(repo, pkg, filename);
+   }
+   } else if(config->quiet) {
+   printf("%s/%s\n", alpm_db_get_name(repo), 
alpm_pkg_get_name(pkg));
+   } else {
+   alpm_list_t *ml;
+   printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(repo),
+   colstr->title, alpm_pkg_get_name(pkg),
+   colstr->version, alpm_pkg_get_version(pkg), 
colstr->nocolor);
+
+   print_groups(pkg);
+   print_installed(db_local, pkg);
+   printf("\n");
+
+   for(ml = match; ml; ml = alpm_list_next(ml)) {
+   char *filename = ml->data;
+   printf("%s\n", filename);
+   }
+   }
+}
+
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
-   alpm_db_t *db_local = alpm_get_localdb(config->handle);
alpm_list_t *t;
-   const colstr_t *colstr = >colstr;
 
for(t = targets; t; t = alpm_list_next(t)) {
char *targ = t->data;
@@ -148,29 +176,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
}
 
if(match != NULL) {
-   if(config->op_f_machinereadable) {
-   alpm_list_t *ml;
-   for(ml = match; ml; ml = 
alpm_list_next(ml)) {
-   char *filename = 
ml->data;
-   
print_line_machinereadable(repo, pkg, filename);
-   }
-   } else if(config->quiet) {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   } else {
-   alpm_list_t *ml;
-   printf("%s%s/%s%s %s%s%s", 
colstr->repo, alpm_db_get_name(repo),
-   colstr->title, 
alpm_pkg_get_name(pkg),
-   colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
-
-   print_groups(pkg);
-   print_installed(db_local, pkg);
-   printf("\n");
-
-   for(ml = match; ml; ml = 
alpm_list_next(ml)) {
-   c = ml->data;
-   printf("%s\n", c);
-   }
-   }
+   print_match(match, repo, pkg);
alpm_list_free(match);
}
}
-- 
2.20.1


[pacman-dev] [PATCH 2/2] wip: pacman: rework the UI of -F

2019-02-02 Thread morganamilo
Reworks the UI of -F according to FS#47949

In short -F replaces both -Fs and -Fo.
--regex/-x has been replaced with --search/-s.

Signed-off-by: morganamilo 
---

This patch is WIP. Functional changes made,
documentation still needs to be changed.

Additionally I think https://bugs.archlinux.org/task/47949#comment143477
Is a good idea and I will probably be included in v2

 src/pacman/conf.h   |   1 -
 src/pacman/files.c  | 119 +++-
 src/pacman/pacman.c |  19 ++-
 3 files changed, 42 insertions(+), 97 deletions(-)

diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index ababf2e0..04bba2dd 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -91,7 +91,6 @@ typedef struct __config_t {
unsigned short op_s_search;
unsigned short op_s_upgrade;
 
-   unsigned short op_f_regex;
unsigned short op_f_machinereadable;
 
unsigned short group;
diff --git a/src/pacman/files.c b/src/pacman/files.c
index 3ebd9b9b..5ec47c54 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -49,56 +49,6 @@ static void dump_pkg_machinereadable(alpm_db_t *db, 
alpm_pkg_t *pkg)
}
 }
 
-static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) {
-   int ret = 0;
-   alpm_list_t *t;
-
-   for(t = targets; t; t = alpm_list_next(t)) {
-   char *filename = t->data;
-   int found = 0;
-   alpm_list_t *s;
-   size_t len = strlen(filename);
-
-   while(len > 1 && filename[0] == '/') {
-   filename++;
-   len--;
-   }
-
-   for(s = syncs; s; s = alpm_list_next(s)) {
-   alpm_list_t *p;
-   alpm_db_t *repo = s->data;
-   alpm_list_t *packages = alpm_db_get_pkgcache(repo);
-
-   for(p = packages; p; p = alpm_list_next(p)) {
-   alpm_pkg_t *pkg = p->data;
-   alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
-
-   if(alpm_filelist_contains(files, filename)) {
-   if(config->op_f_machinereadable) {
-   
print_line_machinereadable(repo, pkg, filename);
-   } else if(!config->quiet) {
-   const colstr_t *colstr = 
>colstr;
-   printf(_("%s is owned by 
%s%s/%s%s %s%s%s\n"), filename,
-   colstr->repo, 
alpm_db_get_name(repo), colstr->title,
-   
alpm_pkg_get_name(pkg), colstr->version,
-   
alpm_pkg_get_version(pkg), colstr->nocolor);
-   } else {
-   printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
-   }
-
-   found = 1;
-   }
-   }
-   }
-
-   if(!found) {
-   ret++;
-   }
-   }
-
-   return 0;
-}
-
 static void print_match(alpm_list_t *match, alpm_db_t *repo, alpm_pkg_t *pkg)
 {
alpm_db_t *db_local = alpm_get_localdb(config->handle);
@@ -138,6 +88,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
alpm_list_t *s;
int found = 0;
regex_t reg;
+   size_t len = strlen(targ);
+   char *exact_file = strchr(targ, '/');
+
+   if(exact_file != NULL) {
+   while(len > 1 && targ[0] == '/') {
+   targ++;
+   len--;
+   }
+   }
 
if(regex) {
if(regcomp(, targ, REG_EXTENDED | REG_NOSUB | 
REG_ICASE | REG_NEWLINE) != 0) {
@@ -153,26 +112,40 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
int m;
 
for(p = packages; p; p = alpm_list_next(p)) {
-   size_t f = 0;
-   char* c;
alpm_pkg_t *pkg = p->data;
alpm_filelist_t *files = 
alpm_pkg_get_files(pkg);
alpm_list_t *match = NULL;
 
-   while(f < files->count) {
-   c = strrchr(files->files[f].name, '/');
-   if(c && *(c + 1)) {
- 

[pacman-dev] [PATCH v6 1/2] libmakepkg: lint disallowed variables in package()

2019-01-30 Thread morganamilo
makepkg will now error if disallowed variables are set inside of
the package function.

Disallowed variables are variables that do exist, like 'makedepends'
and 'pkgver' but can not be set inside of a package function.

Signed-off-by: morganamilo 
---

v5:
Move this lint to its own file.

v6:
"libmakepkg: add exists_function_variable helper" was squashed
into this commit.

Fixups and rebase against master

 scripts/Makefile.am   |  1 +
 scripts/libmakepkg/lint_pkgbuild/meson.build  |  1 +
 .../package_function_variable.sh.in   | 62 +++
 scripts/libmakepkg/util/pkgbuild.sh.in|  9 +++
 4 files changed, 73 insertions(+)
 create mode 100644 
scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 0e5619bd..f84fda1d 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -92,6 +92,7 @@ LIBMAKEPKG_IN = \
libmakepkg/lint_pkgbuild/optdepends.sh \
libmakepkg/lint_pkgbuild/options.sh \
libmakepkg/lint_pkgbuild/package_function.sh \
+   libmakepkg/lint_pkgbuild/package_function_variable.sh \
libmakepkg/lint_pkgbuild/pkgbase.sh \
libmakepkg/lint_pkgbuild/pkglist.sh \
libmakepkg/lint_pkgbuild/pkgname.sh \
diff --git a/scripts/libmakepkg/lint_pkgbuild/meson.build 
b/scripts/libmakepkg/lint_pkgbuild/meson.build
index 4ca414e4..f699a8e2 100644
--- a/scripts/libmakepkg/lint_pkgbuild/meson.build
+++ b/scripts/libmakepkg/lint_pkgbuild/meson.build
@@ -14,6 +14,7 @@ sources = [
   'optdepends.sh.in',
   'options.sh.in',
   'package_function.sh.in',
+  'package_function_variable.sh.in',
   'pkgbase.sh.in',
   'pkglist.sh.in',
   'pkgname.sh.in',
diff --git a/scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in
new file mode 100644
index ..172e0a08
--- /dev/null
+++ b/scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+#   package_function_variable.sh - Check variables inside the package function.
+#
+#   Copyright (c) 2014-2018 Pacman Development Team 
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[[ -n "$LIBMAKEPKG_LINT_PKGBUILD_PACKAGE_FUNCTION_VARIABLE_SH" ]] && return
+LIBMAKEPKG_LINT_PKGBUILD_PACKAGE_FUNCTION_VARIABLE_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+source "$LIBRARY/util/schema.sh"
+source "$LIBRARY/util/util.sh"
+
+
+lint_pkgbuild_functions+=('lint_package_function_variable')
+
+
+lint_package_function_variable() {
+   local i a pkg ret=0
+
+   # package function variables
+   for pkg in ${pkgname[@]}; do
+   for a in ${arch[@]}; do
+   [[ $a == "any" ]] && continue
+
+   for i in ${pkgbuild_schema_arrays[@]} 
${pkgbuild_schema_strings[@]}; do
+   in_array "$i" 
${pkgbuild_schema_package_overrides[@]} && continue
+   if exists_function_variable "package_$pkg" 
"${i}_${a}"; then
+   error "$(gettext "%s can not be set 
inside a package function")" "${i}_${a}"
+   ret=1
+   fi
+   done
+   done
+
+   for i in ${pkgbuild_schema_arrays[@]} 
${pkgbuild_schema_strings[@]}; do
+   in_array "$i" ${pkgbuild_schema_package_overrides[@]} 
&& continue
+   if exists_function_variable "package_$pkg" "$i"; then
+   error "$(gettext "%s can not be set inside a 
package function")" "$i"
+   ret=1
+   fi
+   done
+   done
+
+   return $ret
+}
diff --git a/scripts/libmakepkg/util/pkgbuild.sh.in 
b/scripts/libmakepkg/util/pkgbuild.sh.in
index 0dc239d1..298275a8 100644
--- a/scripts/libmakepkg/util/pkgbuild.sh.in
+++ b/scripts/libmakepkg/util/pkgbuild.sh.in
@@ -100,6 +100,1

[pacman-dev] [PATCH v6 2/2] libmakepkg: lint disallowed architecture specific variables

2019-01-30 Thread morganamilo
Variables such as 'pkgdesc_x86_64' are invalid, instead of ignoring them
raise an error.

This also disallows using 'any' as an architecture specific variable

Signed-off-by: morganamilo 
---

v5:
"libmakepkg: disallow using any as an architecture specific variable"
was squashed into this commit.

Move this lint to its own file.

v6:
Fixups and rebase against master

 scripts/Makefile.am   |  1 +
 .../lint_pkgbuild/arch_specific.sh.in | 82 +++
 scripts/libmakepkg/lint_pkgbuild/meson.build  |  1 +
 3 files changed, 84 insertions(+)
 create mode 100644 scripts/libmakepkg/lint_pkgbuild/arch_specific.sh.in

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index f84fda1d..7fffd93b 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -80,6 +80,7 @@ LIBMAKEPKG_IN = \
libmakepkg/lint_package/missing_backup.sh \
libmakepkg/lint_pkgbuild.sh \
libmakepkg/lint_pkgbuild/arch.sh \
+   libmakepkg/lint_pkgbuild/arch_specific.sh \
libmakepkg/lint_pkgbuild/backup.sh \
libmakepkg/lint_pkgbuild/changelog.sh \
libmakepkg/lint_pkgbuild/checkdepends.sh \
diff --git a/scripts/libmakepkg/lint_pkgbuild/arch_specific.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/arch_specific.sh.in
new file mode 100644
index ..25627dd9
--- /dev/null
+++ b/scripts/libmakepkg/lint_pkgbuild/arch_specific.sh.in
@@ -0,0 +1,82 @@
+#!/bin/bash
+#
+#   arch_specific.sh - Check that arch specific variables can be arch specific.
+#
+#   Copyright (c) 2014-2018 Pacman Development Team 
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[[ -n "$LIBMAKEPKG_LINT_PKGBUILD_ARCH_SPECIFIC_SH" ]] && return
+LIBMAKEPKG_LINT_PKGBUILD_ARCH_SPECIFIC_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+source "$LIBRARY/util/schema.sh"
+source "$LIBRARY/util/util.sh"
+
+
+lint_pkgbuild_functions+=('lint_arch_specific')
+
+
+lint_arch_specific() {
+   local i a pkg ret=0
+
+   # global variables
+   for a in ${arch[@]}; do
+   if [[ $a == "any" ]]; then
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
+   if declare -p "${i}_${a}" > /dev/null 2>&1; then
+   error "$(gettext "Can not provide 
architecture specific variables for the '%s' architecture: %s")" "any" 
"${i}_${a}"
+   ret=1
+   fi
+   done
+   fi
+
+   for i in ${pkgbuild_schema_arrays[@]} 
${pkgbuild_schema_strings[@]}; do
+   in_array "$i" ${pkgbuild_schema_arch_arrays[@]} && 
continue
+   v="${i}_${a}"
+   if declare -p "$v" > /dev/null 2>&1; then
+   error "$(gettext "%s can not be architecture 
specific: %s")" "$i" "${i}_${a}"
+   ret=1
+   fi
+   done
+   done
+
+   # package function variables
+   for pkg in ${pkgname[@]}; do
+   for a in ${arch[@]}; do
+   if [[ $a == "any" ]]; then
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
+   if exists_function_variable 
"package_$pkg" "${i}_${a}"; then
+   error "$(gettext "Can not 
provide architecture specific variables for the '%s' architecture: %s")" "any" 
"${i}_${a}"
+   ret=1
+   fi
+   done
+   fi
+
+   for i in ${pkgbuild_schema_arrays[@]} 
${pkgbuild_schema_strings[@]}; do
+   in_array "$i" ${pkgbuild_schema_arch_arrays[@]} 
&& continue
+   if exists_function_variable "package_$pkg" 
"$

[pacman-dev] [PATCH] libmakepkg: centralise random arrays of pkgbuild variables

2019-01-30 Thread morganamilo
Refactor many of the different arrays of pkgbuild variables
into scripts/libmakepkg/util/schema.sh.in.

Signed-off-by: morganamilo 
---

All the arch overrides happen to be arrays. The current code also uses
arrays in the variable name to document this.

so use pkgbuild_schema_arch_arrays over the previously discussed
pkgbuild_schema_arch_overrides.

 scripts/Makefile.am   |  1 +
 .../integrity/generate_checksum.sh.in |  1 +
 .../integrity/verify_checksum.sh.in   |  1 +
 .../libmakepkg/lint_pkgbuild/variable.sh.in   | 20 +++-
 scripts/libmakepkg/util/meson.build   |  1 +
 scripts/libmakepkg/util/pkgbuild.sh.in|  2 +
 scripts/libmakepkg/util/schema.sh.in  | 49 +++
 scripts/makepkg.sh.in | 11 +
 8 files changed, 64 insertions(+), 22 deletions(-)
 create mode 100644 scripts/libmakepkg/util/schema.sh.in

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 08fc34b2..0e5619bd 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -124,6 +124,7 @@ LIBMAKEPKG_IN = \
libmakepkg/util/option.sh \
libmakepkg/util/parseopts.sh \
libmakepkg/util/pkgbuild.sh \
+   libmakepkg/util/schema.sh \
libmakepkg/util/source.sh \
libmakepkg/util/util.sh
 
diff --git a/scripts/libmakepkg/integrity/generate_checksum.sh.in 
b/scripts/libmakepkg/integrity/generate_checksum.sh.in
index 57ef46ff..63cdc4d6 100644
--- a/scripts/libmakepkg/integrity/generate_checksum.sh.in
+++ b/scripts/libmakepkg/integrity/generate_checksum.sh.in
@@ -25,6 +25,7 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 
 source "$LIBRARY/util/message.sh"
 source "$LIBRARY/util/pkgbuild.sh"
+source "$LIBRARY/util/schema.sh"
 
 generate_one_checksum() {
local integ=$1 arch=$2 sources numsrc indentsz idx
diff --git a/scripts/libmakepkg/integrity/verify_checksum.sh.in 
b/scripts/libmakepkg/integrity/verify_checksum.sh.in
index 532e0693..ec61b16d 100644
--- a/scripts/libmakepkg/integrity/verify_checksum.sh.in
+++ b/scripts/libmakepkg/integrity/verify_checksum.sh.in
@@ -25,6 +25,7 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 
 source "$LIBRARY/util/message.sh"
 source "$LIBRARY/util/pkgbuild.sh"
+source "$LIBRARY/util/schema.sh"
 
 check_checksums() {
local integ a
diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index a975b024..512bed7b 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -25,22 +25,16 @@ LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
 
 source "$LIBRARY/util/message.sh"
 source "$LIBRARY/util/pkgbuild.sh"
+source "$LIBRARY/util/schema.sh"
 
 lint_pkgbuild_functions+=('lint_variable')
 
 
 lint_variable() {
-   # TODO: refactor - similar arrays are used elsewhere
-   local array=(arch backup groups license noextract options validpgpkeys)
-   local arch_array=(checkdepends conflicts depends makedepends md5sums
- optdepends provides replaces sha1sums sha224sums
- sha256sums sha384sums sha512sums source)
-   local string=(changelog epoch install pkgbase pkgdesc pkgrel pkgver url)
-
local i a pkg out bad ret=0
 
# global variables
-   for i in ${array[@]} ${arch_array[@]}; do
+   for i in ${pkgbuild_schema_arrays[@]}; do
if declare -p $i > /dev/null 2>&1; then
if ! is_array $i; then
error "$(gettext "%s should be an array")" "$i"
@@ -52,7 +46,7 @@ lint_variable() {
for a in ${arch[@]}; do
[[ $a == "any" ]] && continue
 
-   for i in ${arch_array[@]}; do
+   for i in ${pkgbuild_schema_arch_arrays[@]}; do
if declare -p "${i}_${a}" > /dev/null 2>&1; then
if ! is_array ${i}_${a}; then
error "$(gettext "%s should be an 
array")" "${i}_${a}"
@@ -62,7 +56,7 @@ lint_variable() {
done
done
 
-   for i in ${string[@]}; do
+   for i in ${pkgbuild_schema_strings[@]}; do
if declare -p "$i" > /dev/null 2>&1; then
if is_array $i; then
error "$(gettext "%s should not be an array")" 
"$i"
@@ -73,7 +67,7 @@ lint_variable() {
 
# package function variables
for pkg in ${pkgname[@]}; do
-   for i in ${array[@]} ${arch_array[@]}; do
+   for i in ${pkgbuild_schema_arrays[@]}; do
if extract_function_variable "package_$pkg" $i 0 out; 
then
 

[pacman-dev] [PATCH v5 3/4] libmakepkg: lint disallowed variables in package()

2019-01-21 Thread morganamilo
makepkg will now error if disallowed variables are set inside of
the package function.

Disallowed variables are variables that do exist, like 'makedepends'
and 'pkgver' but can not be set inside of a package function.

Signed-off-by: morganamilo 
---

v5:
Move this lint to its own file.

 scripts/Makefile.am   |  1 +
 scripts/libmakepkg/lint_pkgbuild/meson.build  |  1 +
 .../package_function_variable.sh.in   | 61 +++
 3 files changed, 63 insertions(+)
 create mode 100644 
scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in

diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 08fc34b2..6f9ada17 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -92,6 +92,7 @@ LIBMAKEPKG_IN = \
libmakepkg/lint_pkgbuild/optdepends.sh \
libmakepkg/lint_pkgbuild/options.sh \
libmakepkg/lint_pkgbuild/package_function.sh \
+   libmakepkg/lint_pkgbuild/package_function_variable.sh \
libmakepkg/lint_pkgbuild/pkgbase.sh \
libmakepkg/lint_pkgbuild/pkglist.sh \
libmakepkg/lint_pkgbuild/pkgname.sh \
diff --git a/scripts/libmakepkg/lint_pkgbuild/meson.build 
b/scripts/libmakepkg/lint_pkgbuild/meson.build
index 4ca414e4..f699a8e2 100644
--- a/scripts/libmakepkg/lint_pkgbuild/meson.build
+++ b/scripts/libmakepkg/lint_pkgbuild/meson.build
@@ -14,6 +14,7 @@ sources = [
   'optdepends.sh.in',
   'options.sh.in',
   'package_function.sh.in',
+  'package_function_variable.sh.in',
   'pkgbase.sh.in',
   'pkglist.sh.in',
   'pkgname.sh.in',
diff --git a/scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in
new file mode 100644
index ..4dff7848
--- /dev/null
+++ b/scripts/libmakepkg/lint_pkgbuild/package_function_variable.sh.in
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+#   package_function_variable.sh - Check variables inside the package function.
+#
+#   Copyright (c) 2014-2018 Pacman Development Team 
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+[[ -n "$LIBMAKEPKG_LINT_PKGBUILD_PACKAGE_FUNCTION_VARIABLE_SH" ]] && return
+LIBMAKEPKG_LINT_PKGBUILD_PACKAGE_FUNCTION_VARIABLE_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+lint_pkgbuild_functions+=('lint_package_function_variable')
+
+
+lint_package_function_variable() {
+   local no_package=(checkdepends epoch makedepends md5sums noextract
+   pkgbase pkgname pkgrel pkgver sha1sums sha224sums 
sha256sums
+   ha384sums sha512sums source validpgpkeys)
+   local i a pkg ret=0
+
+   # package function variables
+   for pkg in ${pkgname[@]}; do
+   for a in ${arch[@]}; do
+   [[ $a == "any" ]] && continue
+
+   for i in ${no_package[@]}; do
+   if exists_function_variable "package_$pkg" 
"${i}_${a}"; then
+   error "$(gettext "%s can not be set 
inside a package function")" "${i}_${a}"
+   ret=1
+   fi
+   done
+   done
+
+   for i in ${no_package[@]}; do
+   if exists_function_variable "package_$pkg" "$i"; then
+   error "$(gettext "%s can not be set inside a 
package function")" "$i"
+   ret=1
+   fi
+   done
+   done
+
+   return $ret
+}
-- 
2.20.1


[pacman-dev] [PATCH v5 2/4] libmakepkg: add exists_function_variable helper

2019-01-21 Thread morganamilo
This helpers functions allows checking for the existence of a package
variable without worrying if it is an array or not.

Signed-off-by: morganamilo 
---
 scripts/libmakepkg/util/pkgbuild.sh.in | 9 +
 1 file changed, 9 insertions(+)

diff --git a/scripts/libmakepkg/util/pkgbuild.sh.in 
b/scripts/libmakepkg/util/pkgbuild.sh.in
index b29229a3..f9fc440b 100644
--- a/scripts/libmakepkg/util/pkgbuild.sh.in
+++ b/scripts/libmakepkg/util/pkgbuild.sh.in
@@ -98,6 +98,15 @@ extract_function_variable() {
return $r
 }
 
+exists_function_variable() {
+   # $1: function name
+   # $2: variable name
+
+   local funcname=$1 attr=$2 out
+   extract_function_variable "$funcname" "$attr" 0 out || \
+   extract_function_variable "$funcname" "$attr" 1 out
+}
+
 get_pkgbuild_attribute() {
# $1: package name
# $2: attribute name
-- 
2.20.1


[pacman-dev] [PATCH v5 1/4] libmakepkg: move checkdepends to the correct array

2019-01-21 Thread morganamilo
Signed-off-by: morganamilo 
---
 scripts/libmakepkg/lint_pkgbuild/variable.sh.in | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index d19c95bc..a975b024 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -31,11 +31,10 @@ lint_pkgbuild_functions+=('lint_variable')
 
 lint_variable() {
# TODO: refactor - similar arrays are used elsewhere
-   local array=(arch backup checkdepends groups license noextract options
-validpgpkeys)
-   local arch_array=(conflicts depends makedepends md5sums optdepends 
provides
- replaces sha1sums sha224sums sha256sums sha384sums 
sha512sums
- source)
+   local array=(arch backup groups license noextract options validpgpkeys)
+   local arch_array=(checkdepends conflicts depends makedepends md5sums
+ optdepends provides replaces sha1sums sha224sums
+ sha256sums sha384sums sha512sums source)
local string=(changelog epoch install pkgbase pkgdesc pkgrel pkgver url)
 
local i a pkg out bad ret=0
-- 
2.20.1


[pacman-dev] [PATCH] libalpm: fix minor typo in _alpm_db_usage_

2019-01-18 Thread morganamilo
Signed-off-by: morganamilo 

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index bbce0971..337b30d2 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1046,7 +1046,7 @@ alpm_list_t *alpm_db_get_groupcache(alpm_db_t *db);
  */
 alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles);
 
-typedef enum _alpm_db_usage_ {
+typedef enum _alpm_db_usage_t {
ALPM_DB_USAGE_SYNC = 1,
ALPM_DB_USAGE_SEARCH = (1 << 1),
ALPM_DB_USAGE_INSTALL = (1 << 2),
-- 
2.20.1


[pacman-dev] [PATCH v4 4/4] libmakepkg: disallow using 'any' with other arches

2019-01-15 Thread morganamilo
Error if the arch array contains any and any other values. This also
fixes a bug where the check for `$arch == 'any'` which only evaluated
the first value in the array, meaning the rest of the values would not
be linted.

Signed-off-by: morganamilo 
---
 scripts/libmakepkg/lint_pkgbuild/arch.sh.in | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
index ef1aac46..3b1d0ce7 100644
--- a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
@@ -33,8 +33,13 @@ lint_pkgbuild_functions+=('lint_arch')
 lint_arch() {
local a name list ret=0
 
-   if [[ $arch == 'any' ]]; then
-   return 0
+   if in_array "any" "${arch[@]}"; then
+   if (( ${#arch[@]} == 1 )); then
+   return 0;
+   else
+   error "$(gettext "Can not use '%s' architecture with 
other architectures")" "any"
+   return 1;
+   fi
fi
 
for a in "${arch[@]}"; do
-- 
2.20.1


[pacman-dev] [PATCH v4 3/4] libmakepkg: disallow using any as an architecture specific variable

2019-01-15 Thread morganamilo
Signed-off-by: morganamilo 
---
 scripts/libmakepkg/lint_pkgbuild/variable.sh.in | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index b65c01f2..7420cdbc 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -56,7 +56,10 @@ lint_variable() {
done
 
for a in ${arch[@]}; do
-   [[ $a == "any" ]] && continue
+   if [[ $a == "any" ]]; then
+   error "$(gettext "Can not provide architecture specific 
variables for the '%s' architecture: %s_%s")" "any" "$i" "$a"
+   ret=1
+   fi
 
for i in ${arch_array[@]}; do
if declare -p "${i}_${a}" > /dev/null 2>&1; then
@@ -106,6 +109,11 @@ lint_variable() {
 
for i in ${array[@]}; do
if extract_function_variable "package_$pkg" 
"${i}_${a}" 1 out; then
+   if [[ $a == "any" ]]; then
+   error "$(gettext "Can not 
provide architecture specific variables for the '%s' architecture: %s_%s")" 
"any" "$i" "$a"
+   ret=1
+   fi
+
error "$(gettext "%s can not be 
architecture specific: $s_$s")" "$i"
ret=1
fi
-- 
2.20.1


[pacman-dev] [PATCH v4 1/4] libmakepkg: lint disallowed variables in package()

2019-01-15 Thread morganamilo
makepkg will now error if disallowed variables are set inside of
the package function.

Disallowed variables are variables that do exist, like 'makedepends'
and 'pkgver' but can not be set inside of a package function.

Signed-off-by: morganamilo 
---
 .../libmakepkg/lint_pkgbuild/variable.sh.in   | 34 +++
 1 file changed, 34 insertions(+)

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index 1ee3c834..ad3ffd8e 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -38,6 +38,11 @@ lint_variable() {
  source)
local string=(changelog epoch install pkgbase pkgdesc pkgrel pkgver url)
 
+   local no_package_string=(epoch pkgbase pkgname pkgrel pkgver)
+
+   local no_package_array=(checkdepends makedepends md5sums noextract
+   sha1sums sha224sums sha256sums sha384sums sha512sums
+   source validpgpkeys)
local i a pkg out bad ret=0
 
# global variables
@@ -84,6 +89,21 @@ lint_variable() {
for a in ${arch[@]}; do
[[ $a == "any" ]] && continue
 
+   for i in ${no_package_string[@]}; do
+   if extract_function_variable "package_$pkg" 
"${i}_${a}" 0 out; then
+   error "$(gettext "%s_%s can not be set 
inside a package function")" "$i" "$a"
+   ret=1
+   fi
+   done
+
+   for i in ${no_package_array[@]}; do
+   if extract_function_variable "package_$pkg" 
"${i}_${a}" 1 out; then
+   error "$(gettext "%s_%s can not be set 
inside a package function")" "$i" "$a"
+   ret=1
+   fi
+
+   done
+
for i in ${arch_array[@]}; do
if extract_function_variable "package_$pkg" 
"${i}_${a}" 0 out; then
error "$(gettext "%s_%s should be an 
array")" "$i" "$a"
@@ -92,6 +112,20 @@ lint_variable() {
done
done
 
+   for i in ${no_package_string[@]}; do
+   if extract_function_variable "package_$pkg" "$i" 0 out; 
then
+   error "$(gettext "%s can not be set inside a 
package function")" "$i"
+   ret=1
+   fi
+   done
+
+   for i in ${no_package_array[@]}; do
+   if extract_function_variable "package_$pkg" "$i" 1 out; 
then
+   error "$(gettext "%s can not be set inside a 
package function")" "$i"
+   ret=1
+   fi
+   done
+
for i in ${string[@]}; do
if extract_function_variable "package_$pkg" $i 1 out; 
then
error "$(gettext "%s should not be an array")" 
"$i"
-- 
2.20.1


[pacman-dev] [PATCH v3] pacman: don't error when a group exists but all packages are ignored

2018-10-20 Thread morganamilo
Currently when attempting to sync a group where all packages are
ignored, either by ignorepkg, ignoregroup or --needed, pacman
will error with "target not found".

Instead, if a group has no packages check if the group exists
before throwing an error.

Signed-off-by: morganamilo 
---

v2: Move to frontend + fix formatting.
v3: Strip alpm_ prefix

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ef8faedf..57677a42 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -535,6 +535,20 @@ static int process_pkg(alpm_pkg_t *pkg)
return 0;
 }
 
+static int group_exists(alpm_list_t *dbs, const char *name)
+{
+   alpm_list_t *i;
+   for(i = dbs; i; i = i->next) {
+   alpm_db_t *db = i->data;
+
+   if(alpm_db_get_group(db, name)) {
+   return 1;
+   }
+   }
+
+   return 0;
+}
+
 static int process_group(alpm_list_t *dbs, const char *group, int error)
 {
int ret = 0;
@@ -543,6 +557,10 @@ static int process_group(alpm_list_t *dbs, const char 
*group, int error)
int count = alpm_list_count(pkgs);
 
if(!count) {
+   if(group_exists(dbs, group)) {
+   return 0;
+   }
+
pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), group);
return 1;
}
-- 
2.19.1


[pacman-dev] [PATCH v2] pacman: don't error when a group exists but all packages are ignored

2018-10-19 Thread morganamilo
Currently when attempting to sync a group where all packages are
ignored, either by ignorepkg, ignoregroup or --needed, pacman
will error with "target not found".

Instead, if a group has no packages check if the group exists
before throwing an error.

Signed-off-by: morganamilo 
---

v2: Move to frontend + fix formatting.

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ef8faedf..57e92266 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -535,6 +535,20 @@ static int process_pkg(alpm_pkg_t *pkg)
return 0;
 }
 
+static int alpm_group_exists(alpm_list_t *dbs, const char *name)
+{
+   alpm_list_t *i;
+   for(i = dbs; i; i = i->next) {
+   alpm_db_t *db = i->data;
+
+   if(alpm_db_get_group(db, name)) {
+   return 1;
+   }
+   }
+
+   return 0;
+}
+
 static int process_group(alpm_list_t *dbs, const char *group, int error)
 {
int ret = 0;
@@ -543,6 +557,10 @@ static int process_group(alpm_list_t *dbs, const char 
*group, int error)
int count = alpm_list_count(pkgs);
 
if(!count) {
+   if(alpm_group_exists(dbs, group)) {
+   return 0;
+   }
+
pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), group);
return 1;
}
-- 
2.19.1


[pacman-dev] [PATCH] pacman: don't error when a group exists but all packages are ignored

2018-10-18 Thread morganamilo
Currently when attempting to sync a group where all packages are
ignored (either by ignorepkg, ignoregroup or --needed) pacman
will error with "target not found".

Instead, if a group has no packages, check if the group exists
and only throw an error if it does not.

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 2d3d198a..316853bb 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1446,6 +1446,8 @@ int alpm_extract_keyid(alpm_handle_t *handle, const char 
*identifier,
 
 alpm_list_t *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name);
 
+int alpm_group_exists(alpm_list_t *dbs, const char *name);
+
 /*
  * Sync
  */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 05f58fad..57058782 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -313,6 +313,26 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t 
*dbs,
return pkgs;
 }
 
+/** Check if a group exists across a list of databases.
+ * @param dbs the list of alpm_db_t *
+ * @param name the name of the group
+ * @return 1 if the group exists, 0 if it does not
+ */
+int SYMEXPORT alpm_group_exists(alpm_list_t *dbs,
+   const char *name)
+{
+   alpm_list_t *i;
+   for(i = dbs; i; i = i->next) {
+   alpm_db_t *db = i->data;
+
+   if (alpm_db_get_group(db, name)) {
+   return 1;
+   }
+   }
+
+   return 0;
+}
+
 /** Compute the size of the files that will be downloaded to install a
  * package.
  * @param newpkg the new package to upgrade to
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ef8faedf..32df6e04 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -543,6 +543,10 @@ static int process_group(alpm_list_t *dbs, const char 
*group, int error)
int count = alpm_list_count(pkgs);
 
if(!count) {
+   if(alpm_group_exists(dbs, group)) {
+   return 0;
+   }
+
pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), group);
return 1;
}
-- 
2.19.1


[pacman-dev] [PATCH v2] libalpm: process needed before group selection

2018-10-17 Thread morganamilo
When --needed is used, up to date packages are now filtered out
before showing the group select.

Fixes FS#22870.

Signed-off-by: morganamilo 
---
v2: Changed per Andrew's feedback.

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index b6ae7b72..05f58fad 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -277,10 +277,21 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t 
*dbs,
 
for(j = grp->packages; j; j = j->next) {
alpm_pkg_t *pkg = j->data;
+   alpm_trans_t *trans = db->handle->trans;
 
if(alpm_pkg_find(ignorelist, pkg->name)) {
continue;
}
+   if(trans != NULL && trans->flags & 
ALPM_TRANS_FLAG_NEEDED) {
+   alpm_pkg_t *local = 
_alpm_db_get_pkgfromcache(db->handle->db_local, pkg->name);
+   if(local && _alpm_pkg_compare_versions(pkg, 
local) == 0) {
+   /* with the NEEDED flag, packages up to 
date are not reinstalled */
+   _alpm_log(db->handle, ALPM_LOG_WARNING, 
_("%s-%s is up to date -- skipping\n"),
+   local->name, 
local->version);
+   ignorelist = alpm_list_add(ignorelist, 
pkg);
+   continue;
+   }
+   }
if(alpm_pkg_should_ignore(db->handle, pkg)) {
alpm_question_install_ignorepkg_t question = {
.type = ALPM_QUESTION_INSTALL_IGNOREPKG,
-- 
2.19.1


[pacman-dev] [PATCH] libmakepkg: fix linting arrays of empty strings

2018-10-16 Thread morganamilo
[[ ${array[@]} ]] will resolve to false if array only contains empty
strings. This means that values such as "depends=('')" can be inserted
into a pkgbuild and bypass the linting.

This causes makepkg to successfully build the package while pacman
refuses to install it because of the unmet dependency on ''.

Instead check the length of the array.

Signed-off-by: morganamilo 

diff --git a/scripts/libmakepkg/util/pkgbuild.sh.in 
b/scripts/libmakepkg/util/pkgbuild.sh.in
index c6f8a82d..b29229a3 100644
--- a/scripts/libmakepkg/util/pkgbuild.sh.in
+++ b/scripts/libmakepkg/util/pkgbuild.sh.in
@@ -60,7 +60,7 @@ extract_global_variable() {
 
if (( isarray )); then
array_build ref "$attr"
-   [[ ${ref[@]} ]] && array_build "$outputvar" "$attr"
+   (( ${#ref[@]} )) && array_build "$outputvar" "$attr"
else
[[ ${!attr} ]] && printf -v "$outputvar" %s "${!attr}"
fi
@@ -144,7 +144,7 @@ get_pkgbuild_all_split_attributes() {
done
done
 
-   [[ ${all_list[@]} ]] && array_build "$outputvar" all_list
+   (( ${#all_list[@]} )) && array_build "$outputvar" all_list
 }
 
 ##
-- 
2.19.1


[pacman-dev] [PATCH v2] libalpm: parse {check, make}depends when reading database

2018-10-08 Thread morganamilo
Commit 0994893b0e6b627d45a63884ac01af7d0967eff2 added the
alpm_pkg_get_{make,check}depends functions but forgot to include
logic for parsing these fields from the database. As a result these
functions will always return an empty list.

This commit adds the parsing logic.

Signed-off-by: morganamilo 
---

Only after making this patch do I see FS#60347. V2 addes the extra lazy
loading code pointed out in the comments.

As a result this patch is basically identical to Alexandre Garnier's patch.
But as they have not submitted their patch to the mailing list I'll submit mine.

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 7c2f96b8..12b13a12 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -153,6 +153,18 @@ static alpm_list_t *_cache_get_optdepends(alpm_pkg_t *pkg)
return pkg->optdepends;
 }
 
+static alpm_list_t *_cache_get_makedepends(alpm_pkg_t *pkg)
+{
+   LAZY_LOAD(INFRQ_DESC);
+   return pkg->makedepends;
+}
+
+static alpm_list_t *_cache_get_checkdepends(alpm_pkg_t *pkg)
+{
+   LAZY_LOAD(INFRQ_DESC);
+   return pkg->checkdepends;
+}
+
 static alpm_list_t *_cache_get_conflicts(alpm_pkg_t *pkg)
 {
LAZY_LOAD(INFRQ_DESC);
@@ -303,36 +315,38 @@ static int _cache_force_load(alpm_pkg_t *pkg)
  * logic.
  */
 static struct pkg_operations local_pkg_ops = {
-   .get_base= _cache_get_base,
-   .get_desc= _cache_get_desc,
-   .get_url = _cache_get_url,
-   .get_builddate   = _cache_get_builddate,
-   .get_installdate = _cache_get_installdate,
-   .get_packager= _cache_get_packager,
-   .get_arch= _cache_get_arch,
-   .get_isize   = _cache_get_isize,
-   .get_reason  = _cache_get_reason,
-   .get_validation  = _cache_get_validation,
-   .has_scriptlet   = _cache_has_scriptlet,
-   .get_licenses= _cache_get_licenses,
-   .get_groups  = _cache_get_groups,
-   .get_depends = _cache_get_depends,
-   .get_optdepends  = _cache_get_optdepends,
-   .get_conflicts   = _cache_get_conflicts,
-   .get_provides= _cache_get_provides,
-   .get_replaces= _cache_get_replaces,
-   .get_files   = _cache_get_files,
-   .get_backup  = _cache_get_backup,
-
-   .changelog_open  = _cache_changelog_open,
-   .changelog_read  = _cache_changelog_read,
-   .changelog_close = _cache_changelog_close,
-
-   .mtree_open  = _cache_mtree_open,
-   .mtree_next  = _cache_mtree_next,
-   .mtree_close = _cache_mtree_close,
-
-   .force_load  = _cache_force_load,
+   .get_base = _cache_get_base,
+   .get_desc = _cache_get_desc,
+   .get_url  = _cache_get_url,
+   .get_builddate= _cache_get_builddate,
+   .get_installdate  = _cache_get_installdate,
+   .get_packager = _cache_get_packager,
+   .get_arch = _cache_get_arch,
+   .get_isize= _cache_get_isize,
+   .get_reason   = _cache_get_reason,
+   .get_validation   = _cache_get_validation,
+   .has_scriptlet= _cache_has_scriptlet,
+   .get_licenses = _cache_get_licenses,
+   .get_groups   = _cache_get_groups,
+   .get_depends  = _cache_get_depends,
+   .get_optdepends   = _cache_get_optdepends,
+   .get_makedepends  = _cache_get_makedepends,
+   .get_checkdepends = _cache_get_checkdepends,
+   .get_conflicts= _cache_get_conflicts,
+   .get_provides = _cache_get_provides,
+   .get_replaces = _cache_get_replaces,
+   .get_files= _cache_get_files,
+   .get_backup   = _cache_get_backup,
+
+   .changelog_open   = _cache_changelog_open,
+   .changelog_read   = _cache_changelog_read,
+   .changelog_close  = _cache_changelog_close,
+
+   .mtree_open   = _cache_mtree_open,
+   .mtree_next   = _cache_mtree_next,
+   .mtree_close  = _cache_mtree_close,
+
+   .force_load   = _cache_force_load,
 };
 
 static int checkdbdir(alpm_db_t *db)
@@ -773,6 +787,10 @@ static int local_db_read(alpm_pkg_t *info, int inforeq)
READ_AND_SPLITDEP(info->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
READ_AND_SPLITDEP(info->optdepends);
+   } else if(strcmp(line, "%MAKEDEPENDS%") == 0) {
+   READ_AND_SPLITDEP(info->makedepends);
+   } else if(strcmp(line, "%CHECKDEPENDS%") == 0) {
+   READ_AND_SPLITDEP(info->checkdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
ind

[pacman-dev] [PATCH] libalpm: parse {check, make}depends when reading database

2018-10-08 Thread morganamilo
Commit 0994893b0e6b627d45a63884ac01af7d0967eff2 added the
alpm_pkg_get_{make,check}depends functions but forgot to include
logic for parsing these fields from the database. As a result these
functions will always return an empty list.

This commit adds the parsing logic.

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 7c2f96b8..f8c3947e 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -773,6 +773,10 @@ static int local_db_read(alpm_pkg_t *info, int inforeq)
READ_AND_SPLITDEP(info->depends);
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
READ_AND_SPLITDEP(info->optdepends);
+   } else if(strcmp(line, "%MAKEDEPENDS%") == 0) {
+   READ_AND_SPLITDEP(info->makedepends);
+   } else if(strcmp(line, "%CHECKDEPENDS%") == 0) {
+   READ_AND_SPLITDEP(info->checkdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(info->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 5009a7da..af94b2d5 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -700,17 +700,9 @@ static int sync_db_read(alpm_db_t *db, struct archive 
*archive,
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
READ_AND_SPLITDEP(pkg->optdepends);
} else if(strcmp(line, "%MAKEDEPENDS%") == 0) {
-   /* currently unused */
-   while(1) {
-   READ_NEXT();
-   if(strlen(line) == 0) break;
-   }
+   READ_AND_SPLITDEP(pkg->makedepends);
} else if(strcmp(line, "%CHECKDEPENDS%") == 0) {
-   /* currently unused */
-   while(1) {
-   READ_NEXT();
-   if(strlen(line) == 0) break;
-   }
+   READ_AND_SPLITDEP(pkg->checkdepends);
} else if(strcmp(line, "%CONFLICTS%") == 0) {
READ_AND_SPLITDEP(pkg->conflicts);
} else if(strcmp(line, "%PROVIDES%") == 0) {
-- 
2.19.1


[pacman-dev] [PATCH v2] pacman: fix possible buffer overflow

2018-09-22 Thread morganamilo
in the function query_fileowner, if the user enters a string longer
than PATH_MAX then rpath will buffer overflow when lrealpath tries to
strcat everything together.

So make sure to bail early if the generated path is going to be bigger
than PATH_MAX.

This also fixes the compiler warning:
query.c: In function ‘query_fileowner’:
query.c:192:4: warning: ‘strncpy’ specified bound 4096 equals destination size 
[-Wstringop-truncation]
strncpy(rpath, filename, PATH_MAX);

Signed-off-by: morganamilo 

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 00c39638..c661fafb 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -102,7 +102,7 @@ static char *lrealpath(const char *path, char 
*resolved_path)
 {
const char *bname = mbasename(path);
char *rpath = NULL, *dname = NULL;
-   int success = 0;
+   int success = 0, len;
 
if(strcmp(bname, ".") == 0 || strcmp(bname, "..") == 0) {
/* the entire path needs to be resolved */
@@ -115,8 +115,14 @@ static char *lrealpath(const char *path, char 
*resolved_path)
if(!(rpath = realpath(dname, NULL))) {
goto cleanup;
}
+
+   len = strlen(rpath) + strlen(bname) + 2;
+   if (len > PATH_MAX) {
+   errno = ENAMETOOLONG;
+   goto cleanup;
+   }
if(!resolved_path) {
-   if(!(resolved_path = malloc(strlen(rpath) + strlen(bname) + 
2))) {
+   if(!(resolved_path = malloc(len))) {
goto cleanup;
}
}
@@ -187,11 +193,16 @@ static int query_fileowner(alpm_list_t *targets)
}
}
 
+   errno = 0;
if(!lrealpath(filename, rpath)) {
+   if (errno == ENAMETOOLONG) {
+   pm_printf(ALPM_LOG_ERROR, _("path too long: 
%s/\n"), filename);
+   goto targcleanup;
+   }
/* Can't canonicalize path, try to proceed anyway */
-   strncpy(rpath, filename, PATH_MAX);
+   strncpy(rpath, filename, PATH_MAX - 1);
+   rpath[PATH_MAX - 1] = '\0';
}
-
if(strncmp(rpath, root, rootlen) != 0) {
/* file is outside root, we know nothing can own it */
pm_printf(ALPM_LOG_ERROR, _("No package owns %s\n"), 
filename);
-- 
2.19.0


[pacman-dev] [PATCH 2/2] pacman: give path too long error after strcat

2018-09-22 Thread morganamilo
The string only becomes longer than PATH_MAX once adding "/" to the end.
The error message should give this version of the path.

Signed-off-by: morganamilo 

diff --git a/src/pacman/query.c b/src/pacman/query.c
index a1197cea..ecf8d148 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -207,15 +207,15 @@ static int query_fileowner(alpm_list_t *targets)
rel_path = rpath + rootlen;
 
if((is_missing && is_dir) || (!is_missing && (is_dir = 
S_ISDIR(buf.st_mode {
-   if(rlen + 2 >= PATH_MAX) {
-   pm_printf(ALPM_LOG_ERROR, _("path too 
long: %s/\n"), rpath);
-   goto targcleanup;
-   }
if ((rpathsave = realloc(rpath, rlen + 2)) == NULL) {
goto targcleanup;
}
rpath = rpathsave;
strcat(rpath + rlen, "/");
+   if(rlen + 2 >= PATH_MAX) {
+   pm_printf(ALPM_LOG_ERROR, _("path too 
long: %s/\n"), rpath);
+   goto targcleanup;
+   }
}
 
for(i = packages; i && (!found || is_dir); i = 
alpm_list_next(i)) {
-- 
2.19.0


[pacman-dev] [PATCH 1/2] pacman: fix possible buffer overflow

2018-09-22 Thread morganamilo
in the function query_fileowner, if the user enters a string longer
than PATH_MAX then rpath will buffer overflow when lrealpath tries to
strcat everything together.

Even if we made sure filename was never longer than PATH_MAX this would
not help because lrealpath may concatenate filename with the current
directory among other things.

So simply let lrealpath calculate the size needed and allocate it for
us.

This also fixes the compiler warning;
query.c: In function ‘query_fileowner’:
query.c:192:4: warning: ‘strncpy’ specified bound 4096 equals destination size 
[-Wstringop-truncation]
strncpy(rpath, filename, PATH_MAX);

The warning could have also been Fixed by using PATH_MAX -1 and explicitly
terminating the string. However this would not fix the buffer overflow.

Signed-off-by: morganamilo 

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 00c39638..a1197cea 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -155,10 +155,10 @@ static int query_fileowner(alpm_list_t *targets)
 
for(t = targets; t; t = alpm_list_next(t)) {
char *filename = NULL;
-   char rpath[PATH_MAX], *rel_path;
+   char *rpath = NULL, *rpathsave, *rel_path;
struct stat buf;
alpm_list_t *i;
-   size_t len;
+   size_t len, rlen;
unsigned int found = 0;
int is_dir = 0, is_missing = 0;
 
@@ -187,9 +187,15 @@ static int query_fileowner(alpm_list_t *targets)
}
}
 
-   if(!lrealpath(filename, rpath)) {
+   if(!(rpath = lrealpath(filename, NULL))) {
/* Can't canonicalize path, try to proceed anyway */
-   strncpy(rpath, filename, PATH_MAX);
+   rpath = strdup(filename);
+   }
+
+   rlen = strlen(rpath);
+   if(rlen + 1 >= PATH_MAX) {
+   pm_printf(ALPM_LOG_ERROR, _("path too long: 
%s/\n"), rpath);
+   goto targcleanup;
}
 
if(strncmp(rpath, root, rootlen) != 0) {
@@ -201,11 +207,14 @@ static int query_fileowner(alpm_list_t *targets)
rel_path = rpath + rootlen;
 
if((is_missing && is_dir) || (!is_missing && (is_dir = 
S_ISDIR(buf.st_mode {
-   size_t rlen = strlen(rpath);
if(rlen + 2 >= PATH_MAX) {
pm_printf(ALPM_LOG_ERROR, _("path too 
long: %s/\n"), rpath);
goto targcleanup;
}
+   if ((rpathsave = realloc(rpath, rlen + 2)) == NULL) {
+   goto targcleanup;
+   }
+   rpath = rpathsave;
strcat(rpath + rlen, "/");
}
 
-- 
2.19.0


[pacman-dev] [PATCH] libalpm: process needed before group selection

2018-09-22 Thread morganamilo
When --needed is used, up to date packages are now filtered out
before showing the group select.

Signed-off-by: morganamilo 
---

This patch set is currently incomplete. There is a problem where if every
package in the group is already installed you end up with the eror.
"error: target not found: groupname". Instead "there is nothing to do" should
be produced instead.

I'm unsure of how to solve this so I am submitting this for discussion.
Currently my idea is to have alpm_find_group_pkgs gain a new param `int *exists`
which the front end can then check instead of the length of the return. Or
instead the needed check could just be moved to the front end. Let me know
if theres a better way.

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index b6ae7b72..f1c02417 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -270,6 +270,8 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t 
*dbs,
for(i = dbs; i; i = i->next) {
alpm_db_t *db = i->data;
alpm_group_t *grp = alpm_db_get_group(db, name);
+   alpm_handle_t *handle = db->handle;
+   alpm_trans_t *trans = handle->trans;
 
if(!grp) {
continue;
@@ -277,10 +279,26 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t 
*dbs,
 
for(j = grp->packages; j; j = j->next) {
alpm_pkg_t *pkg = j->data;
+   alpm_pkg_t *local = 
_alpm_db_get_pkgfromcache(handle->db_local, pkg->name);
 
if(alpm_pkg_find(ignorelist, pkg->name)) {
continue;
}
+   if(local) {
+   const char *localpkgname = local->name;
+   const char *localpkgver = local->version;
+   int cmp = _alpm_pkg_compare_versions(pkg, 
local);
+
+   if(cmp == 0) {
+   if(trans != NULL && trans->flags & 
ALPM_TRANS_FLAG_NEEDED) {
+   /* with the NEEDED flag, 
packages up to date are not reinstalled */
+   _alpm_log(handle, 
ALPM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"),
+   localpkgname, 
localpkgver);
+   ignorelist = 
alpm_list_add(ignorelist, pkg);
+   continue;
+   }
+   }
+   }
if(alpm_pkg_should_ignore(db->handle, pkg)) {
alpm_question_install_ignorepkg_t question = {
.type = ALPM_QUESTION_INSTALL_IGNOREPKG,
-- 
2.19.0


[pacman-dev] [PATCH] pacman-conf: add missing DisableDownloadTimeout

2018-09-10 Thread morganamilo
Signed-off-by: morganamilo 
---
 src/pacman/pacman-conf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c
index baa72d97..56196f79 100644
--- a/src/pacman/pacman-conf.c
+++ b/src/pacman/pacman-conf.c
@@ -266,6 +266,7 @@ static void dump_config(void)
show_bool("TotalDownload", config->totaldownload);
show_bool("CheckSpace", config->checkspace);
show_bool("VerbosePkgLists", config->verbosepkglists);
+   show_bool("DisableDownloadTimeout", config->disable_dl_timeout);
show_bool("ILoveCandy", config->chomp);
 
show_float("UseDelta", config->deltaratio);
@@ -376,6 +377,8 @@ static int list_directives(void)
show_bool("CheckSpace", config->checkspace);
} else if(strcasecmp(i->data, "VerbosePkgLists") == 0) {
show_bool("VerbosePkgLists", config->verbosepkglists);
+   } else if(strcasecmp(i->data, "DisableDownloadTimeout") == 0) {
+   show_bool("DisableDownloadTimeout", 
config->disable_dl_timeout);
 
} else if(strcasecmp(i->data, "UseDelta") == 0) {
show_float("UseDelta", config->deltaratio);
-- 
2.18.0


[pacman-dev] [PATCH v4 2/2] Show group status during file search

2018-09-04 Thread morganamilo
When doing "pacman -Fs", show the "(groupname)"
message just like "pacman -Ss".

And refactor group printing to its own function.

Signed-off-by: morganamilo 
---
Fix style

 src/pacman/files.c   |  1 +
 src/pacman/package.c | 34 +++---
 src/pacman/package.h |  1 +
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 58cf8d3d..fa4170bd 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -162,6 +162,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
colstr->title, 
alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
+   print_groups(pkg);
print_installed(db_local, pkg);
printf("\n");
 
diff --git a/src/pacman/package.c b/src/pacman/package.c
index e80c5953..639b1247 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -494,6 +494,25 @@ void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg)
}
 }
 
+void print_groups(alpm_pkg_t *pkg)
+{
+   alpm_list_t *grp;
+   if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
+   const colstr_t *colstr = >colstr;
+   alpm_list_t *k;
+   printf(" %s(", colstr->groups);
+   for(k = grp; k; k = alpm_list_next(k)) {
+   const char *group = k->data;
+   fputs(group, stdout);
+   if(alpm_list_next(k)) {
+   /* only print a spacer if there are more groups 
*/
+   putchar(' ');
+   }
+   }
+   printf(")%s", colstr->nocolor);
+   }
+}
+
 /**
  * Display the details of a search.
  * @param db the database we're searching
@@ -526,7 +545,6 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, 
int show_status)
 
cols = getcols();
for(i = searchlist; i; i = alpm_list_next(i)) {
-   alpm_list_t *grp;
alpm_pkg_t *pkg = i->data;
 
if(config->quiet) {
@@ -536,20 +554,7 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, 
int show_status)
colstr->title, alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
-   if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
-   alpm_list_t *k;
-   printf(" %s(", colstr->groups);
-   for(k = grp; k; k = alpm_list_next(k)) {
-   const char *group = k->data;
-   fputs(group, stdout);
-   if(alpm_list_next(k)) {
-   /* only print a spacer if there 
are more groups */
-   putchar(' ');
-   }
-   }
-   printf(")%s", colstr->nocolor);
-   }
-
+   print_groups(pkg);
if(show_status) {
print_installed(db_local, pkg);
}
diff --git a/src/pacman/package.h b/src/pacman/package.h
index 68c2a630..03e1afa0 100644
--- a/src/pacman/package.h
+++ b/src/pacman/package.h
@@ -29,6 +29,7 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet);
 void dump_pkg_changelog(alpm_pkg_t *pkg);
 
 void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg);
+void print_groups(alpm_pkg_t *pkg);
 int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status);
 
 #endif /* PM_PACKAGE_H */
-- 
2.18.0


[pacman-dev] [PATCH v3 2/2] Show group status during file search

2018-09-03 Thread morganamilo
When doing "pacman -Fs", show the "(groupname)"
message just like "pacman -Ss".

And refactor group printing to its own function.

Signed-off-by: morganamilo 
---
 src/pacman/files.c   |  1 +
 src/pacman/package.c | 34 +++---
 src/pacman/package.h |  1 +
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index 58cf8d3d..fa4170bd 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -162,6 +162,7 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
colstr->title, 
alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
+   print_groups(pkg);
print_installed(db_local, pkg);
printf("\n");
 
diff --git a/src/pacman/package.c b/src/pacman/package.c
index e80c5953..386b4260 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -494,6 +494,24 @@ void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg)
}
 }
 
+void print_groups(alpm_pkg_t *pkg) {
+   alpm_list_t *grp;
+   if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
+   const colstr_t *colstr = >colstr;
+   alpm_list_t *k;
+   printf(" %s(", colstr->groups);
+   for(k = grp; k; k = alpm_list_next(k)) {
+   const char *group = k->data;
+   fputs(group, stdout);
+   if(alpm_list_next(k)) {
+   /* only print a spacer if there are more groups 
*/
+   putchar(' ');
+   }
+   }
+   printf(")%s", colstr->nocolor);
+   }
+}
+
 /**
  * Display the details of a search.
  * @param db the database we're searching
@@ -526,7 +544,6 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, 
int show_status)
 
cols = getcols();
for(i = searchlist; i; i = alpm_list_next(i)) {
-   alpm_list_t *grp;
alpm_pkg_t *pkg = i->data;
 
if(config->quiet) {
@@ -536,20 +553,7 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, 
int show_status)
colstr->title, alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
-   if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
-   alpm_list_t *k;
-   printf(" %s(", colstr->groups);
-   for(k = grp; k; k = alpm_list_next(k)) {
-   const char *group = k->data;
-   fputs(group, stdout);
-   if(alpm_list_next(k)) {
-   /* only print a spacer if there 
are more groups */
-   putchar(' ');
-   }
-   }
-   printf(")%s", colstr->nocolor);
-   }
-
+   print_groups(pkg);
if(show_status) {
print_installed(db_local, pkg);
}
diff --git a/src/pacman/package.h b/src/pacman/package.h
index 68c2a630..03e1afa0 100644
--- a/src/pacman/package.h
+++ b/src/pacman/package.h
@@ -29,6 +29,7 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet);
 void dump_pkg_changelog(alpm_pkg_t *pkg);
 
 void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg);
+void print_groups(alpm_pkg_t *pkg);
 int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status);
 
 #endif /* PM_PACKAGE_H */
-- 
2.18.0


[pacman-dev] [PATCH v3 1/2] Show install status during file search

2018-09-03 Thread morganamilo
When doing "pacman -Fs", show the "[installed: version]"
message just like "pacman -Ss".

Signed-off-by: morganamilo 
---
 src/pacman/files.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index d7fc5446..58cf8d3d 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -101,6 +101,7 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t 
*targets) {
 
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
+   alpm_db_t *db_local = alpm_get_localdb(config->handle);
alpm_list_t *t;
const colstr_t *colstr = >colstr;
 
@@ -157,10 +158,13 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
} else {
alpm_list_t *ml;
-   printf("%s%s/%s%s %s%s%s\n", 
colstr->repo, alpm_db_get_name(repo),
+   printf("%s%s/%s%s %s%s%s", 
colstr->repo, alpm_db_get_name(repo),
colstr->title, 
alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
+   print_installed(db_local, pkg);
+   printf("\n");
+
for(ml = match; ml; ml = 
alpm_list_next(ml)) {
c = ml->data;
printf("%s\n", c);
-- 
2.18.0


[pacman-dev] [PATCH v3 0/2] Make -Fs behave like -Ss and output group-membership and installation-state

2018-09-03 Thread morganamilo
I realized that in my previous patch[1] I totally forgot about groups. Reading
through the bugtracker I also realized there's already a task open on it 
FS#47948.

This patchset Includes the install status and the group status patches.

PS. I'm not too sure on what to do when adding a patch to an existing one.
Should I have resent the first? Should this be v3 or v1? If anyone can clear
that up I'd appreciate it.

[1] https://lists.archlinux.org/pipermail/pacman-dev/2018-August/022769.html

morganamilo (2):
  Show install status during file search
  Show group status during file search

 src/pacman/files.c   |  7 ++-
 src/pacman/package.c | 34 +++---
 src/pacman/package.h |  1 +
 3 files changed, 26 insertions(+), 16 deletions(-)

-- 
2.18.0


[pacman-dev] [PATCH] during -Qu add [ignored] for repos without Usage = Upgrade

2018-08-31 Thread morganamilo
Fixes FS#59854

Signed-off-by: morganamilo 
---
 src/pacman/query.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/pacman/query.c b/src/pacman/query.c
index 00c39638..faa06e60 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -325,10 +325,14 @@ static int display(alpm_pkg_t *pkg)
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
if(config->op_q_upgrade) {
+   int usage;
alpm_pkg_t *newpkg = alpm_sync_newversion(pkg, 
alpm_get_syncdbs(config->handle));
+   alpm_db_t *db = alpm_pkg_get_db(newpkg);
+   alpm_db_get_usage(db, );
+
printf(" -> %s%s%s", colstr->version, 
alpm_pkg_get_version(newpkg), colstr->nocolor);
 
-   if(alpm_pkg_should_ignore(config->handle, pkg)) 
{
+   if(alpm_pkg_should_ignore(config->handle, pkg) 
|| !(usage & ALPM_DB_USAGE_UPGRADE)) {
printf(" %s", _("[ignored]"));
}
}
-- 
2.18.0


[pacman-dev] [PATCH v2] Show install status during file search

2018-08-16 Thread morganamilo
When doing "pacman -Fs", show the "[installed: version]"
message just like "pacman -Ss".

Signed-off-by: morganamilo 
---

Fixed extra \n's

diff --git a/src/pacman/files.c b/src/pacman/files.c
index d7fc5446..58cf8d3d 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -101,6 +101,7 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t 
*targets) {
 
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
+   alpm_db_t *db_local = alpm_get_localdb(config->handle);
alpm_list_t *t;
const colstr_t *colstr = >colstr;
 
@@ -157,10 +158,13 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
} else {
alpm_list_t *ml;
-   printf("%s%s/%s%s %s%s%s\n", 
colstr->repo, alpm_db_get_name(repo),
+   printf("%s%s/%s%s %s%s%s", 
colstr->repo, alpm_db_get_name(repo),
colstr->title, 
alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
+   print_installed(db_local, pkg);
+   printf("\n");
+
for(ml = match; ml; ml = 
alpm_list_next(ml)) {
c = ml->data;
printf("%s\n", c);
-- 
2.18.0


[pacman-dev] [PATCH] libalpm/sync.c: restrict alpm_sync_newversion by USAGE_UPGRADE

2018-07-24 Thread morganamilo
Commit 106d0fc54 Added the usage option for databases and
alpm_sync_newversion was restricted by USAGE_SEARCH instead of
USAGE_UPGRADE.

USAGE_UPGRADE should be used instead. This means packages only show up
in commands such as `pacman -Qu` if the database Has the Upgrade option.

Signed-off-by: morganamilo 

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 696a5131..23b0ccfa 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -61,7 +61,7 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, 
alpm_list_t *dbs_syn
 
for(i = dbs_sync; !spkg && i; i = i->next) {
alpm_db_t *db = i->data;
-   if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
+   if(!(db->usage & ALPM_DB_USAGE_UPGRADE)) {
continue;
}
 
-- 
2.18.0


[pacman-dev] [PATCH 7/7] libmakepkg: disallow using 'any' with other arches

2018-06-12 Thread morganamilo
Error if the arch array contains any and any other values. This also
fixes a bug where the check for `$arch == 'any'` which only evaluated
the first value in the array, meaning the rest of the values would not
be linted.

Signed-off-by: morganamilo 
---
 scripts/libmakepkg/lint_pkgbuild/arch.sh.in | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
index f2c80c73..f3dd8ee6 100644
--- a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
@@ -38,11 +38,16 @@ lint_arch() {
return 1
fi
 
-   if [[ $arch == 'any' ]]; then
+   if [[ $arch == 'any' ]] && (( ${#arch[@]} == 1 )); then
return 0
fi
 
for a in "${arch[@]}"; do
+   if [[ $a == 'any' ]]; then
+   error "$(gettext "any can not be used with other 
architectures")"
+   ret=1
+   fi
+
if [[ $a = *[![:alnum:]_]* ]]; then
error "$(gettext "%s contains invalid characters: 
'%s'")" \
'arch' "${a//[[:alnum:]_]}"
-- 
2.17.1


[pacman-dev] [PATCH 7/7] libmakepkg: disallow using 'any' with other arches

2018-06-11 Thread morganamilo
Error if the arch array contains any and any other values. This also
fixes a bug where the check for `$arch == 'any'` which only evaluated
the first value in the array, meaning the rest of the values would not
be linted.

Signed-off-by: morganamilo 
---
 scripts/libmakepkg/lint_pkgbuild/arch.sh.in | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in 
b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
index f2c80c73..8a1d2c11 100644
--- a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
@@ -38,11 +38,16 @@ lint_arch() {
return 1
fi
 
-   if [[ $arch == 'any' ]]; then
+   if [[ $arch == 'any' && ${#arch[@]} == 1 ]]; then
return 0
fi
 
for a in "${arch[@]}"; do
+   if [[ $a == 'any' ]]; then
+   error "$(gettext "any can not be used with other 
architectures")"
+   ret=1
+   fi
+
if [[ $a = *[![:alnum:]_]* ]]; then
error "$(gettext "%s contains invalid characters: 
'%s'")" \
'arch' "${a//[[:alnum:]_]}"
-- 
2.17.1


[pacman-dev] [PATCH] Show install status during file search

2018-06-11 Thread morganamilo
When doing "pacman -Fs", show the "[installed: version]"
message just like "pacman -Ss".

Signed-off-by: morganamilo 
---
 src/pacman/files.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/pacman/files.c b/src/pacman/files.c
index d7fc5446..65e6ad26 100644
--- a/src/pacman/files.c
+++ b/src/pacman/files.c
@@ -101,6 +101,7 @@ static int files_fileowner(alpm_list_t *syncs, alpm_list_t 
*targets) {
 
 static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) {
int ret = 0;
+   alpm_db_t *db_local = alpm_get_localdb(config->handle);
alpm_list_t *t;
const colstr_t *colstr = >colstr;
 
@@ -157,13 +158,15 @@ static int files_search(alpm_list_t *syncs, alpm_list_t 
*targets, int regex) {
printf("%s/%s\n", 
alpm_db_get_name(repo), alpm_pkg_get_name(pkg));
} else {
alpm_list_t *ml;
-   printf("%s%s/%s%s %s%s%s\n", 
colstr->repo, alpm_db_get_name(repo),
+   printf("%s%s/%s%s %s%s%s", 
colstr->repo, alpm_db_get_name(repo),
colstr->title, 
alpm_pkg_get_name(pkg),
colstr->version, 
alpm_pkg_get_version(pkg), colstr->nocolor);
 
+   print_installed(db_local, pkg);
+
for(ml = match; ml; ml = 
alpm_list_next(ml)) {
c = ml->data;
-   printf("%s\n", c);
+   printf("\n%s\n", c);
}
}
alpm_list_free(match);
-- 
2.17.1


  1   2   >