summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/backup.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-16 20:15:11 +0200
committerDan McGee <dan@archlinux.org>2011-06-22 19:31:12 +0200
commit54ef162a1a9e27e362732d873f0739bc0a2cf1bf (patch)
treee4ec6ba0ab94965c754a40d52a680f9fd69c4e37 /lib/libalpm/backup.c
parent886a31ef205923fd5b29012ee75932a2e2dec4bd (diff)
downloadpacman-54ef162a1a9e27e362732d873f0739bc0a2cf1bf.tar.gz
pacman-54ef162a1a9e27e362732d873f0739bc0a2cf1bf.tar.xz
Convert backup list to new pmbackup_t type
This allows us to separate the name and hash elements in one place and not scatter different parsing code all over the place, including both the frontend and backend. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/backup.c')
-rw-r--r--lib/libalpm/backup.c80
1 files changed, 34 insertions, 46 deletions
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index 6431b286..20fb8a80 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -32,54 +32,33 @@
#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);
- }
+ (*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;
@@ -89,23 +68,32 @@ char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
/* 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, backup->name) == 0) {
+ return backup;
}
- if(strcmp(file, filename) == 0) {
- FREE(filename);
- return hash;
- }
- FREE(filename);
- FREE(hash);
}
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: */