feat: added functioning flag, error and removal check

This commit is contained in:
jg 2025-02-04 23:39:55 +01:00 committed by jgomez
parent 79053b7dae
commit df51933091
91 changed files with 19 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -307,6 +307,8 @@ typedef enum _alpm_errno_t {
ALPM_ERR_CONFLICTING_DEPS, ALPM_ERR_CONFLICTING_DEPS,
/** Files conflict */ /** Files conflict */
ALPM_ERR_FILE_CONFLICTS, ALPM_ERR_FILE_CONFLICTS,
/** Removing optdepends of another dependency*/
ALPM_ERR_REMOVING_OPTDEPENDS_DEPS,
/* Misc */ /* Misc */
/** Download failed */ /** Download failed */
ALPM_ERR_RETRIEVE, ALPM_ERR_RETRIEVE,
@ -2817,7 +2819,7 @@ typedef enum _alpm_transflag_t {
/** Ignore dependency conflicts. */ /** Ignore dependency conflicts. */
ALPM_TRANS_FLAG_NOCONFLICTS = (1 << 11), ALPM_TRANS_FLAG_NOCONFLICTS = (1 << 11),
/** Cancel removal of package if it's optdepends of another package. */ /** Cancel removal of package if it's optdepends of another package. */
ALPM_TRANS_KEEP_OPTIONALS = (1 << 12), ALPM_TRANS_FLAG_KEEPOPTIONALS = (1 << 12),
/** Do not install a package if it is already installed and up to date. */ /** Do not install a package if it is already installed and up to date. */
ALPM_TRANS_FLAG_NEEDED = (1 << 13), ALPM_TRANS_FLAG_NEEDED = (1 << 13),
/** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */ /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */

View file

@ -137,6 +137,8 @@ const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
return _("conflicting dependencies"); return _("conflicting dependencies");
case ALPM_ERR_FILE_CONFLICTS: case ALPM_ERR_FILE_CONFLICTS:
return _("conflicting files"); return _("conflicting files");
case ALPM_ERR_REMOVING_OPTDEPENDS_DEPS:
return _("removing optdepends of another dependency");
/* Miscellaenous */ /* Miscellaenous */
case ALPM_ERR_RETRIEVE: case ALPM_ERR_RETRIEVE:
return _("failed to retrieve some files"); return _("failed to retrieve some files");

View file

@ -160,9 +160,12 @@ static void remove_prepare_keep_needed(alpm_handle_t *handle, alpm_list_t *lp)
* *
* @param handle the context handle * @param handle the context handle
* @param lp list of packages to be removed * @param lp list of packages to be removed
*
* @return 0 when no optdepends of other packages are going to be removed, 1 in case it will remove optdepends of other packages
*/ */
static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *lp) static int remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *lp)
{ {
int result = 0;
alpm_list_t *i; alpm_list_t *i;
for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = alpm_list_next(i)) { for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = alpm_list_next(i)) {
@ -180,12 +183,15 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *
.pkg = pkg, .pkg = pkg,
.optdep = optdep .optdep = optdep
}; };
result = 1;
EVENT(handle, &event); EVENT(handle, &event);
} }
free(optstring); free(optstring);
} }
} }
} }
return result;
} }
/** /**
@ -206,6 +212,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
alpm_trans_t *trans = handle->trans; alpm_trans_t *trans = handle->trans;
alpm_db_t *db = handle->db_local; alpm_db_t *db = handle->db_local;
alpm_event_t event; alpm_event_t event;
int removing_optdepends;
if((trans->flags & ALPM_TRANS_FLAG_RECURSE) if((trans->flags & ALPM_TRANS_FLAG_RECURSE)
&& !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) { && !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) {
@ -257,8 +264,11 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
/* Note packages being removed that are optdepends for installed packages */ /* Note packages being removed that are optdepends for installed packages */
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
/*DEV_COMMENT: This is where the check is done, use this logic to check flag ALPM_TRANS_KEEP_OPTIONALS and abort transaction if flag set */ removing_optdepends = remove_notify_needed_optdepends(handle, trans->remove);
remove_notify_needed_optdepends(handle, trans->remove); }
if (trans->flags & ALPM_TRANS_FLAG_KEEPOPTIONALS && removing_optdepends == 1) {
RET_ERR(handle, ALPM_ERR_REMOVING_OPTDEPENDS_DEPS, -1);
} }
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {

View file

@ -731,7 +731,7 @@ static int parsearg_remove(int opt)
break; break;
case 'k': case 'k':
if (config->flags & ALPM_TRANS_FLAG_RECURSE || config->flags & ALPM_TRANS_FLAG_RECURSEALL) { if (config->flags & ALPM_TRANS_FLAG_RECURSE || config->flags & ALPM_TRANS_FLAG_RECURSEALL) {
config->flags |= ALPM_TRANS_KEEP_OPTIONALS; config->flags |= ALPM_TRANS_FLAG_KEEPOPTIONALS;
} }
break; break;
default: default: