Rename pmconflict_t to alpm_conflict_t
[pacman-ng.git] / lib / libalpm / backup.c
blob408c0e17ffdd25c08eb1d1b16f0600dae356ddaa
1 /*
2 * backup.c
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2005 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
8 * Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "config.h"
26 #include <stdlib.h>
27 #include <string.h>
29 /* libalpm */
30 #include "backup.h"
31 #include "alpm_list.h"
32 #include "log.h"
33 #include "util.h"
35 /* split a backup string "file\thash" into the relevant components */
36 int _alpm_split_backup(const char *string, pmbackup_t **backup)
38 char *str, *ptr;
40 STRDUP(str, string, return -1);
42 /* tab delimiter */
43 ptr = strchr(str, '\t');
44 if(ptr == NULL) {
45 (*backup)->name = str;
46 (*backup)->hash = NULL;
47 return 0;
49 *ptr = '\0';
50 ptr++;
51 /* now str points to the filename and ptr points to the hash */
52 STRDUP((*backup)->name, str, return -1);
53 STRDUP((*backup)->hash, ptr, return -1);
54 FREE(str);
55 return 0;
58 /* Look for a filename in a alpm_pkg_t.backup list. If we find it,
59 * then we return the full backup entry.
61 pmbackup_t *_alpm_needbackup(const char *file, const alpm_list_t *backup_list)
63 const alpm_list_t *lp;
65 if(file == NULL || backup_list == NULL) {
66 return NULL;
69 /* run through the backup list and parse out the hash for our file */
70 for(lp = backup_list; lp; lp = lp->next) {
71 pmbackup_t *backup = lp->data;
73 if(strcmp(file, backup->name) == 0) {
74 return backup;
78 return NULL;
81 void _alpm_backup_free(pmbackup_t *backup)
83 free(backup->name);
84 free(backup->hash);
85 free(backup);
88 pmbackup_t *_alpm_backup_dup(const pmbackup_t *backup)
90 pmbackup_t *newbackup;
91 CALLOC(newbackup, 1, sizeof(pmbackup_t), return NULL);
93 STRDUP(newbackup->name, backup->name, return NULL);
94 STRDUP(newbackup->hash, backup->hash, return NULL);
96 return newbackup;
99 /* vim: set ts=2 sw=2 noet: */