A few final changes for the 3.0.6 release
[pacman.git] / lib / libalpm / backup.c
blobaeb0dea7bb8f156b2b9e81ccb4586e837edebcd6
1 /*
2 * backup.c
3 *
4 * Copyright (c) 2005 by Judd Vinet <jvinet@zeroflux.org>
5 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
6 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
7 * Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 * USA.
25 #include "config.h"
27 #include <stdlib.h>
28 #include <string.h>
30 /* libalpm */
31 #include "backup.h"
32 #include "alpm_list.h"
33 #include "log.h"
34 #include "util.h"
36 /* Look for a filename in a pmpkg_t.backup list. If we find it,
37 * then we return the md5 or sha1 hash (parsed from the same line)
39 char *_alpm_needbackup(const char *file, alpm_list_t *backup)
41 alpm_list_t *lp;
43 ALPM_LOG_FUNC;
45 if(file == NULL || backup == NULL) {
46 return(NULL);
49 /* run through the backup list and parse out the md5 or sha1 hash for our file */
50 for(lp = backup; lp; lp = lp->next) {
51 char *str = strdup(lp->data);
52 char *ptr;
54 /* tab delimiter */
55 ptr = strchr(str, '\t');
56 if(ptr == NULL) {
57 FREE(str);
58 continue;
60 *ptr = '\0';
61 ptr++;
62 /* now str points to the filename and ptr points to the md5 or sha1 hash */
63 if(strcmp(file, str) == 0) {
64 char *hash = strdup(ptr);
65 FREE(str);
66 return(hash);
68 FREE(str);
71 return(NULL);
74 /* vim: set ts=2 sw=2 noet: */