libalpm
Arch Linux Package Manager Library
|
00001 /* 00002 * backup.c 00003 * 00004 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> 00005 * Copyright (c) 2005 by Judd Vinet <jvinet@zeroflux.org> 00006 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com> 00007 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu> 00008 * Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org> 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 #include <stdlib.h> 00025 #include <string.h> 00026 00027 /* libalpm */ 00028 #include "backup.h" 00029 #include "alpm_list.h" 00030 #include "log.h" 00031 #include "util.h" 00032 00033 /* split a backup string "file\thash" into the relevant components */ 00034 int _alpm_split_backup(const char *string, alpm_backup_t **backup) 00035 { 00036 char *str, *ptr; 00037 00038 STRDUP(str, string, return -1); 00039 00040 /* tab delimiter */ 00041 ptr = str ? strchr(str, '\t') : NULL; 00042 if(ptr == NULL) { 00043 (*backup)->name = str; 00044 (*backup)->hash = NULL; 00045 return 0; 00046 } 00047 *ptr = '\0'; 00048 ptr++; 00049 /* now str points to the filename and ptr points to the hash */ 00050 STRDUP((*backup)->name, str, return -1); 00051 STRDUP((*backup)->hash, ptr, return -1); 00052 FREE(str); 00053 return 0; 00054 } 00055 00056 /* Look for a filename in a alpm_pkg_t.backup list. If we find it, 00057 * then we return the full backup entry. 00058 */ 00059 alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg) 00060 { 00061 const alpm_list_t *lp; 00062 00063 if(file == NULL || pkg == NULL) { 00064 return NULL; 00065 } 00066 00067 for(lp = alpm_pkg_get_backup(pkg); lp; lp = lp->next) { 00068 alpm_backup_t *backup = lp->data; 00069 00070 if(strcmp(file, backup->name) == 0) { 00071 return backup; 00072 } 00073 } 00074 00075 return NULL; 00076 } 00077 00078 void _alpm_backup_free(alpm_backup_t *backup) 00079 { 00080 free(backup->name); 00081 free(backup->hash); 00082 free(backup); 00083 } 00084 00085 alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup) 00086 { 00087 alpm_backup_t *newbackup; 00088 CALLOC(newbackup, 1, sizeof(alpm_backup_t), return NULL); 00089 00090 STRDUP(newbackup->name, backup->name, return NULL); 00091 STRDUP(newbackup->hash, backup->hash, return NULL); 00092 00093 return newbackup; 00094 } 00095 00096 /* vim: set ts=2 sw=2 noet: */