mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Add events on pacnew/pacsave/pacorig file creation
ALPM still adds a warning to the log, but doesn't emit an event about said warning, instead using a specific event to let the frontend what happened/how to inform the user. Note that there are 2 cases for installing a .pacnew file, to not overwrite user changes and because file is in NoUpgrade. In the later case the warning was a bit different: it happened before and said "extracting" instead of "installed." Now both happen after and are phrased the same. Signed-off-by: Olivier Brunel <jjk@jjacky.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
894773eb5b
commit
cfaff6e0c1
@ -370,8 +370,14 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
|
|||||||
if(try_rename(handle, checkfile, newpath)) {
|
if(try_rename(handle, checkfile, newpath)) {
|
||||||
errors++;
|
errors++;
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"),
|
alpm_event_pacnew_created_t event = {
|
||||||
filename, newpath);
|
.type = ALPM_EVENT_PACNEW_CREATED,
|
||||||
|
.from_noupgrade = 0,
|
||||||
|
.oldpkg = oldpkg,
|
||||||
|
.newpkg = newpkg,
|
||||||
|
.file = filename
|
||||||
|
};
|
||||||
|
EVENT(handle, &event);
|
||||||
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
||||||
"warning: %s installed as %s\n", filename, newpath);
|
"warning: %s installed as %s\n", filename, newpath);
|
||||||
}
|
}
|
||||||
@ -398,8 +404,12 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
|
|||||||
if(try_rename(handle, checkfile, filename)) {
|
if(try_rename(handle, checkfile, filename)) {
|
||||||
errors++;
|
errors++;
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING,
|
alpm_event_pacorig_created_t event = {
|
||||||
_("%s saved as %s\n"), filename, newpath);
|
.type = ALPM_EVENT_PACORIG_CREATED,
|
||||||
|
.newpkg = newpkg,
|
||||||
|
.file = filename
|
||||||
|
};
|
||||||
|
EVENT(handle, &event);
|
||||||
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
||||||
"warning: %s saved as %s\n", filename, newpath);
|
"warning: %s saved as %s\n", filename, newpath);
|
||||||
}
|
}
|
||||||
@ -414,14 +424,14 @@ needbackup_cleanup:
|
|||||||
free(hash_local);
|
free(hash_local);
|
||||||
free(hash_pkg);
|
free(hash_pkg);
|
||||||
} else {
|
} else {
|
||||||
|
size_t len;
|
||||||
/* we didn't need a backup */
|
/* we didn't need a backup */
|
||||||
if(notouch) {
|
if(notouch) {
|
||||||
/* change the path to a .pacnew extension */
|
/* change the path to a .pacnew extension */
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename);
|
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename);
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename);
|
/* remember len so we can get the old filename back for the event */
|
||||||
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
len = strlen(filename);
|
||||||
"warning: extracting %s as %s.pacnew\n", filename, filename);
|
strncat(filename, ".pacnew", PATH_MAX - len);
|
||||||
strncat(filename, ".pacnew", PATH_MAX - strlen(filename));
|
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename);
|
_alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename);
|
||||||
}
|
}
|
||||||
@ -440,6 +450,23 @@ needbackup_cleanup:
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(notouch) {
|
||||||
|
alpm_event_pacnew_created_t event = {
|
||||||
|
.type = ALPM_EVENT_PACNEW_CREATED,
|
||||||
|
.from_noupgrade = 1,
|
||||||
|
.oldpkg = oldpkg,
|
||||||
|
.newpkg = newpkg,
|
||||||
|
.file = filename
|
||||||
|
};
|
||||||
|
/* "remove" the .pacnew suffix */
|
||||||
|
filename[len] = '\0';
|
||||||
|
EVENT(handle, &event);
|
||||||
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
||||||
|
"warning: %s installed as %s.pacnew\n", filename, filename);
|
||||||
|
/* restore */
|
||||||
|
filename[len] = '.';
|
||||||
|
}
|
||||||
|
|
||||||
/* calculate an hash if this is in newpkg's backup */
|
/* calculate an hash if this is in newpkg's backup */
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
|
for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
|
||||||
|
@ -350,7 +350,15 @@ typedef enum _alpm_event_type_t {
|
|||||||
/** Key downloading is finished. */
|
/** Key downloading is finished. */
|
||||||
ALPM_EVENT_KEY_DOWNLOAD_DONE,
|
ALPM_EVENT_KEY_DOWNLOAD_DONE,
|
||||||
/** A log message was emitted; See alpm_event_log_t for arguments. */
|
/** A log message was emitted; See alpm_event_log_t for arguments. */
|
||||||
ALPM_EVENT_LOG
|
ALPM_EVENT_LOG,
|
||||||
|
/** 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 */
|
||||||
|
ALPM_EVENT_PACSAVE_CREATED,
|
||||||
|
/** A .pacorig file was created; See alpm_event_pacorig_created_t for
|
||||||
|
* arguments */
|
||||||
|
ALPM_EVENT_PACORIG_CREATED
|
||||||
} alpm_event_type_t;
|
} alpm_event_type_t;
|
||||||
|
|
||||||
/** Events.
|
/** Events.
|
||||||
@ -442,6 +450,37 @@ typedef struct _alpm_event_pkgdownload_t {
|
|||||||
const char *file;
|
const char *file;
|
||||||
} alpm_event_pkgdownload_t;
|
} alpm_event_pkgdownload_t;
|
||||||
|
|
||||||
|
typedef struct _alpm_event_pacnew_created_t {
|
||||||
|
/** Type of event. */
|
||||||
|
alpm_event_type_t type;
|
||||||
|
/** Whether the creation was result of a NoUpgrade or not */
|
||||||
|
int from_noupgrade;
|
||||||
|
/** Old package. */
|
||||||
|
alpm_pkg_t *oldpkg;
|
||||||
|
/** New Package. */
|
||||||
|
alpm_pkg_t *newpkg;
|
||||||
|
/** Filename of the file without the .pacnew suffix */
|
||||||
|
const char *file;
|
||||||
|
} alpm_event_pacnew_created_t;
|
||||||
|
|
||||||
|
typedef struct _alpm_event_pacsave_created_t {
|
||||||
|
/** Type of event. */
|
||||||
|
alpm_event_type_t type;
|
||||||
|
/** Old package. */
|
||||||
|
alpm_pkg_t *oldpkg;
|
||||||
|
/** Filename of the file without the .pacsave suffix. */
|
||||||
|
const char *file;
|
||||||
|
} alpm_event_pacsave_created_t;
|
||||||
|
|
||||||
|
typedef struct _alpm_event_pacorig_created_t {
|
||||||
|
/** Type of event. */
|
||||||
|
alpm_event_type_t type;
|
||||||
|
/** New package. */
|
||||||
|
alpm_pkg_t *newpkg;
|
||||||
|
/** Filename of the file without the .pacorig suffix. */
|
||||||
|
const char *file;
|
||||||
|
} alpm_event_pacorig_created_t;
|
||||||
|
|
||||||
/** Event callback. */
|
/** Event callback. */
|
||||||
typedef void (*alpm_cb_event)(alpm_event_t *);
|
typedef void (*alpm_cb_event)(alpm_event_t *);
|
||||||
|
|
||||||
|
@ -522,6 +522,11 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
|
|||||||
int cmp = filehash ? strcmp(filehash, backup->hash) : 0;
|
int cmp = filehash ? strcmp(filehash, backup->hash) : 0;
|
||||||
FREE(filehash);
|
FREE(filehash);
|
||||||
if(cmp != 0) {
|
if(cmp != 0) {
|
||||||
|
alpm_event_pacsave_created_t event = {
|
||||||
|
.type = ALPM_EVENT_PACSAVE_CREATED,
|
||||||
|
.oldpkg = oldpkg,
|
||||||
|
.file = file
|
||||||
|
};
|
||||||
char *newpath;
|
char *newpath;
|
||||||
size_t len = strlen(file) + 8 + 1;
|
size_t len = strlen(file) + 8 + 1;
|
||||||
MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
MALLOC(newpath, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
||||||
@ -536,7 +541,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
|
|||||||
free(newpath);
|
free(newpath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
|
EVENT(handle, &event);
|
||||||
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
alpm_logaction(handle, ALPM_CALLER_PREFIX,
|
||||||
"warning: %s saved as %s\n", file, newpath);
|
"warning: %s saved as %s\n", file, newpath);
|
||||||
free(newpath);
|
free(newpath);
|
||||||
|
@ -288,6 +288,54 @@ void cb_event(alpm_event_t *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ALPM_EVENT_PACNEW_CREATED:
|
||||||
|
{
|
||||||
|
alpm_event_pacnew_created_t *e = (alpm_event_pacnew_created_t *) event;
|
||||||
|
if(on_progress) {
|
||||||
|
char *string = NULL;
|
||||||
|
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"),
|
||||||
|
e->file, e->file);
|
||||||
|
if(string != NULL) {
|
||||||
|
output = alpm_list_add(output, string);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pm_printf(ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"),
|
||||||
|
e->file, e->file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ALPM_EVENT_PACSAVE_CREATED:
|
||||||
|
{
|
||||||
|
alpm_event_pacsave_created_t *e = (alpm_event_pacsave_created_t *) event;
|
||||||
|
if(on_progress) {
|
||||||
|
char *string = NULL;
|
||||||
|
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"),
|
||||||
|
e->file, e->file);
|
||||||
|
if(string != NULL) {
|
||||||
|
output = alpm_list_add(output, string);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"),
|
||||||
|
e->file, e->file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ALPM_EVENT_PACORIG_CREATED:
|
||||||
|
{
|
||||||
|
alpm_event_pacorig_created_t *e = (alpm_event_pacorig_created_t *) event;
|
||||||
|
if(on_progress) {
|
||||||
|
char *string = NULL;
|
||||||
|
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
|
||||||
|
e->file, e->file);
|
||||||
|
if(string != NULL) {
|
||||||
|
output = alpm_list_add(output, string);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
|
||||||
|
e->file, e->file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
/* all the simple done events, with fallthrough for each */
|
/* all the simple done events, with fallthrough for each */
|
||||||
case ALPM_EVENT_FILECONFLICTS_DONE:
|
case ALPM_EVENT_FILECONFLICTS_DONE:
|
||||||
case ALPM_EVENT_CHECKDEPS_DONE:
|
case ALPM_EVENT_CHECKDEPS_DONE:
|
||||||
|
@ -1579,6 +1579,19 @@ int pm_asprintf(char **string, const char *format, ...)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
/* print the message using va_arg list */
|
||||||
|
va_start(args, format);
|
||||||
|
ret = pm_vasprintf(string, level, format, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args)
|
int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -78,6 +78,7 @@ int noyes(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
|||||||
int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
|
int pm_printf(alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
|
||||||
int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3)));
|
int pm_asprintf(char **string, const char *format, ...) __attribute__((format(printf,2,3)));
|
||||||
int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
|
int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
|
||||||
|
int pm_sprintf(char **string, alpm_loglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
|
||||||
int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
|
int pm_vasprintf(char **string, alpm_loglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
|
||||||
|
|
||||||
#endif /* _PM_UTIL_H */
|
#endif /* _PM_UTIL_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user