Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/backup.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/backup.c')
-rw-r--r--lib/libalpm/backup.c95
1 files changed, 40 insertions, 55 deletions
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index ca955ca4..728c1d05 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -32,82 +32,67 @@
#include "log.h"
#include "util.h"
-/* split a backup string "file\thash" into two strings : file and hash */
-static int backup_split(const char *string, char **file, char **hash)
+/* split a backup string "file\thash" into the relevant components */
+int _alpm_split_backup(const char *string, alpm_backup_t **backup)
{
- char *str = strdup(string);
- char *ptr;
+ char *str, *ptr;
+
+ STRDUP(str, string, return -1);
/* tab delimiter */
- ptr = strchr(str, '\t');
+ ptr = str ? strchr(str, '\t') : NULL;
if(ptr == NULL) {
- if(file) {
- *file = str;
- } else {
- /* don't need our dup as the fname wasn't requested, so free it */
- FREE(str);
- }
- return(0);
+ (*backup)->name = str;
+ (*backup)->hash = NULL;
+ return 0;
}
*ptr = '\0';
ptr++;
/* now str points to the filename and ptr points to the hash */
- if(file) {
- *file = strdup(str);
- }
- if(hash) {
- *hash = strdup(ptr);
- }
+ STRDUP((*backup)->name, str, return -1);
+ STRDUP((*backup)->hash, ptr, return -1);
FREE(str);
- return(1);
-}
-
-char *_alpm_backup_file(const char *string)
-{
- char *file = NULL;
- backup_split(string, &file, NULL);
- return(file);
-}
-
-char *_alpm_backup_hash(const char *string)
-{
- char *hash = NULL;
- backup_split(string, NULL, &hash);
- return(hash);
+ return 0;
}
-/* Look for a filename in a pmpkg_t.backup list. If we find it,
- * then we return the md5 hash (parsed from the same line)
+/* Look for a filename in a alpm_pkg_t.backup list. If we find it,
+ * then we return the full backup entry.
*/
-char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
+alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg)
{
const alpm_list_t *lp;
- ALPM_LOG_FUNC;
-
- if(file == NULL || backup == NULL) {
- return(NULL);
+ if(file == NULL || pkg == NULL) {
+ return NULL;
}
- /* run through the backup list and parse out the hash for our file */
- for(lp = backup; lp; lp = lp->next) {
- char *filename = NULL;
- char *hash = NULL;
+ for(lp = alpm_pkg_get_backup(pkg); lp; lp = lp->next) {
+ alpm_backup_t *backup = lp->data;
- /* no hash found */
- if(!backup_split((char *)lp->data, &filename, &hash)) {
- FREE(filename);
- continue;
- }
- if(strcmp(file, filename) == 0) {
- FREE(filename);
- return(hash);
+ if(strcmp(file, backup->name) == 0) {
+ return backup;
}
- FREE(filename);
- FREE(hash);
}
- return(NULL);
+ return NULL;
+}
+
+void _alpm_backup_free(alpm_backup_t *backup)
+{
+ free(backup->name);
+ free(backup->hash);
+ free(backup);
+}
+
+alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup)
+{
+ alpm_backup_t *newbackup;
+ CALLOC(newbackup, 1, sizeof(alpm_backup_t), return NULL);
+
+ STRDUP(newbackup->name, backup->name, return NULL);
+ STRDUP(newbackup->hash, backup->hash, return NULL);
+
+ return newbackup;
}
/* vim: set ts=2 sw=2 noet: */