Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOlivier Brunel <jjk@jjacky.com>2014-02-12 16:32:30 +0100
committerAllan McRae <allan@archlinux.org>2014-03-03 11:25:55 +1000
commitcfaff6e0c14d29f07246386695bce0188ce6f44b (patch)
tree18e660b42b884b09b01238d200fb9c432a552700 /lib
parent894773eb5bb054ba9750d9be269814c7e6672766 (diff)
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/add.c43
-rw-r--r--lib/libalpm/alpm.h41
-rw-r--r--lib/libalpm/remove.c7
3 files changed, 81 insertions, 10 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 45e16847..4f557a47 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -370,8 +370,14 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
if(try_rename(handle, checkfile, newpath)) {
errors++;
} else {
- _alpm_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"),
- filename, newpath);
+ alpm_event_pacnew_created_t event = {
+ .type = ALPM_EVENT_PACNEW_CREATED,
+ .from_noupgrade = 0,
+ .oldpkg = oldpkg,
+ .newpkg = newpkg,
+ .file = filename
+ };
+ EVENT(handle, &event);
alpm_logaction(handle, ALPM_CALLER_PREFIX,
"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)) {
errors++;
} else {
- _alpm_log(handle, ALPM_LOG_WARNING,
- _("%s saved as %s\n"), filename, newpath);
+ alpm_event_pacorig_created_t event = {
+ .type = ALPM_EVENT_PACORIG_CREATED,
+ .newpkg = newpkg,
+ .file = filename
+ };
+ EVENT(handle, &event);
alpm_logaction(handle, ALPM_CALLER_PREFIX,
"warning: %s saved as %s\n", filename, newpath);
}
@@ -414,14 +424,14 @@ needbackup_cleanup:
free(hash_local);
free(hash_pkg);
} else {
+ size_t len;
/* we didn't need a backup */
if(notouch) {
/* 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_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename);
- alpm_logaction(handle, ALPM_CALLER_PREFIX,
- "warning: extracting %s as %s.pacnew\n", filename, filename);
- strncat(filename, ".pacnew", PATH_MAX - strlen(filename));
+ /* remember len so we can get the old filename back for the event */
+ len = strlen(filename);
+ strncat(filename, ".pacnew", PATH_MAX - len);
} else {
_alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename);
}
@@ -440,6 +450,23 @@ needbackup_cleanup:
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 */
alpm_list_t *i;
for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 5fc9c0d2..b0adb95d 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -350,7 +350,15 @@ typedef enum _alpm_event_type_t {
/** Key downloading is finished. */
ALPM_EVENT_KEY_DOWNLOAD_DONE,
/** 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;
/** Events.
@@ -442,6 +450,37 @@ typedef struct _alpm_event_pkgdownload_t {
const char *file;
} 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. */
typedef void (*alpm_cb_event)(alpm_event_t *);
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 132b30c6..5cbeeb96 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -522,6 +522,11 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
int cmp = filehash ? strcmp(filehash, backup->hash) : 0;
FREE(filehash);
if(cmp != 0) {
+ alpm_event_pacsave_created_t event = {
+ .type = ALPM_EVENT_PACSAVE_CREATED,
+ .oldpkg = oldpkg,
+ .file = file
+ };
char *newpath;
size_t len = strlen(file) + 8 + 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);
return -1;
}
- _alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
+ EVENT(handle, &event);
alpm_logaction(handle, ALPM_CALLER_PREFIX,
"warning: %s saved as %s\n", file, newpath);
free(newpath);