mirror of
https://github.com/moparisthebest/pacman
synced 2024-11-13 21:05:05 -05:00
libalpm/backup.c : simple refactoring.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
This commit is contained in:
parent
afdf3724d9
commit
87d95f14f7
@ -33,6 +33,47 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
/* split a backup string "file\thash" into two strings : file and hash */
|
||||||
|
int _alpm_backup_split(const char *string, char **file, char **hash)
|
||||||
|
{
|
||||||
|
char *str = strdup(string);
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
/* tab delimiter */
|
||||||
|
ptr = strchr(str, '\t');
|
||||||
|
if(ptr == NULL) {
|
||||||
|
if(file) {
|
||||||
|
*file = str;
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
*ptr = '\0';
|
||||||
|
ptr++;
|
||||||
|
/* now str points to the filename and ptr points to the hash */
|
||||||
|
if(file) {
|
||||||
|
*file = strdup(str);
|
||||||
|
}
|
||||||
|
if(hash) {
|
||||||
|
*hash = strdup(ptr);
|
||||||
|
}
|
||||||
|
FREE(str);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *_alpm_backup_file(const char *string)
|
||||||
|
{
|
||||||
|
char *file = NULL;
|
||||||
|
_alpm_backup_split(string, &file, NULL);
|
||||||
|
return(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *_alpm_backup_hash(const char *string)
|
||||||
|
{
|
||||||
|
char *hash = NULL;
|
||||||
|
_alpm_backup_split(string, NULL, &hash);
|
||||||
|
return(hash);
|
||||||
|
}
|
||||||
|
|
||||||
/* Look for a filename in a pmpkg_t.backup list. If we find it,
|
/* Look for a filename in a pmpkg_t.backup list. If we find it,
|
||||||
* then we return the md5 hash (parsed from the same line)
|
* then we return the md5 hash (parsed from the same line)
|
||||||
*/
|
*/
|
||||||
@ -46,26 +87,22 @@ char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* run through the backup list and parse out the md5 hash for our file */
|
/* run through the backup list and parse out the hash for our file */
|
||||||
for(lp = backup; lp; lp = lp->next) {
|
for(lp = backup; lp; lp = lp->next) {
|
||||||
char *str = strdup(lp->data);
|
char *filename = NULL;
|
||||||
char *ptr;
|
char *hash = NULL;
|
||||||
|
|
||||||
/* tab delimiter */
|
/* no hash found */
|
||||||
ptr = strchr(str, '\t');
|
if(!_alpm_backup_split((char *)lp->data, &filename, &hash)) {
|
||||||
if(ptr == NULL) {
|
FREE(filename);
|
||||||
FREE(str);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*ptr = '\0';
|
if(strcmp(file, filename) == 0) {
|
||||||
ptr++;
|
FREE(filename);
|
||||||
/* now str points to the filename and ptr points to the md5 hash */
|
|
||||||
if(strcmp(file, str) == 0) {
|
|
||||||
char *hash = strdup(ptr);
|
|
||||||
FREE(str);
|
|
||||||
return(hash);
|
return(hash);
|
||||||
}
|
}
|
||||||
FREE(str);
|
FREE(filename);
|
||||||
|
FREE(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "alpm_list.h"
|
#include "alpm_list.h"
|
||||||
|
|
||||||
|
char *_alpm_backup_file(const char *string);
|
||||||
|
char *_alpm_backup_hash(const char *string);
|
||||||
char *_alpm_needbackup(const char *file, const alpm_list_t *backup);
|
char *_alpm_needbackup(const char *file, const alpm_list_t *backup);
|
||||||
|
|
||||||
#endif /* _ALPM_BACKUP_H */
|
#endif /* _ALPM_BACKUP_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user