00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024
00025 #include <stdlib.h>
00026 #include <string.h>
00027
00028
00029 #include "backup.h"
00030 #include "alpm_list.h"
00031 #include "log.h"
00032 #include "util.h"
00033
00034
00035 int _alpm_backup_split(const char *string, char **file, char **hash)
00036 {
00037 char *str = strdup(string);
00038 char *ptr;
00039
00040
00041 ptr = strchr(str, '\t');
00042 if(ptr == NULL) {
00043 if(file) {
00044 *file = str;
00045 }
00046 return(0);
00047 }
00048 *ptr = '\0';
00049 ptr++;
00050
00051 if(file) {
00052 *file = strdup(str);
00053 }
00054 if(hash) {
00055 *hash = strdup(ptr);
00056 }
00057 FREE(str);
00058 return(1);
00059 }
00060
00061 char *_alpm_backup_file(const char *string)
00062 {
00063 char *file = NULL;
00064 _alpm_backup_split(string, &file, NULL);
00065 return(file);
00066 }
00067
00068 char *_alpm_backup_hash(const char *string)
00069 {
00070 char *hash = NULL;
00071 _alpm_backup_split(string, NULL, &hash);
00072 return(hash);
00073 }
00074
00075
00076
00077
00078 char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
00079 {
00080 const alpm_list_t *lp;
00081
00082 ALPM_LOG_FUNC;
00083
00084 if(file == NULL || backup == NULL) {
00085 return(NULL);
00086 }
00087
00088
00089 for(lp = backup; lp; lp = lp->next) {
00090 char *filename = NULL;
00091 char *hash = NULL;
00092
00093
00094 if(!_alpm_backup_split((char *)lp->data, &filename, &hash)) {
00095 FREE(filename);
00096 continue;
00097 }
00098 if(strcmp(file, filename) == 0) {
00099 FREE(filename);
00100 return(hash);
00101 }
00102 FREE(filename);
00103 FREE(hash);
00104 }
00105
00106 return(NULL);
00107 }
00108
00109