pacman: list all unknown targets on removal operation
[pacman-ng.git] / lib / libalpm / backup.c
blob728c1d05d89a635aea75694a5229d43efdf17d2c
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, alpm_backup_t **backup)
38 char *str, *ptr;
40 STRDUP(str, string, return -1);
42 /* tab delimiter */
43 ptr = str ? strchr(str, '\t') : NULL;
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 alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg)
63 const alpm_list_t *lp;
65 if(file == NULL || pkg == NULL) {
66 return NULL;
69 for(lp = alpm_pkg_get_backup(pkg); lp; lp = lp->next) {
70 alpm_backup_t *backup = lp->data;
72 if(strcmp(file, backup->name) == 0) {
73 return backup;
77 return NULL;
80 void _alpm_backup_free(alpm_backup_t *backup)
82 free(backup->name);
83 free(backup->hash);
84 free(backup);
87 alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup)
89 alpm_backup_t *newbackup;
90 CALLOC(newbackup, 1, sizeof(alpm_backup_t), return NULL);
92 STRDUP(newbackup->name, backup->name, return NULL);
93 STRDUP(newbackup->hash, backup->hash, return NULL);
95 return newbackup;
98 /* vim: set ts=2 sw=2 noet: */