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.c88
1 files changed, 37 insertions, 51 deletions
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index ca955ca4..20fb8a80 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -32,82 +32,68 @@
#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, pmbackup_t **backup)
{
- char *str = strdup(string);
- char *ptr;
+ char *str, *ptr;
+
+ STRDUP(str, string, return -1);
/* tab delimiter */
ptr = strchr(str, '\t');
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 pmpkg_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)
+pmbackup_t *_alpm_needbackup(const char *file, const alpm_list_t *backup)
{
const alpm_list_t *lp;
- ALPM_LOG_FUNC;
-
if(file == NULL || backup == NULL) {
- return(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;
+ pmbackup_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(pmbackup_t *backup)
+{
+ free(backup->name);
+ free(backup->hash);
+ free(backup);
+}
+
+pmbackup_t *_alpm_backup_dup(const pmbackup_t *backup)
+{
+ pmbackup_t *newbackup;
+ CALLOC(newbackup, 1, sizeof(pmbackup_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: */