summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2007-12-05 00:28:36 +0100
committerDan McGee <dan@archlinux.org>2007-12-04 17:59:45 -0600
commit87d95f14f70cc133642db3041a2b3e78b5a74516 (patch)
treec098ac0eec6f24126970aca9cff0f0b2a1f7a844 /lib/libalpm
parentafdf3724d9d5672c07adcf474d2850630e605167 (diff)
downloadpacman-87d95f14f70cc133642db3041a2b3e78b5a74516.tar.xz
libalpm/backup.c : simple refactoring.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/backup.c65
-rw-r--r--lib/libalpm/backup.h2
2 files changed, 53 insertions, 14 deletions
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index 731a59e6..6aa59acb 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -33,6 +33,47 @@
#include "log.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,
* 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);
}
- /* 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) {
- char *str = strdup(lp->data);
- char *ptr;
+ char *filename = NULL;
+ char *hash = NULL;
- /* tab delimiter */
- ptr = strchr(str, '\t');
- if(ptr == NULL) {
- FREE(str);
+ /* no hash found */
+ if(!_alpm_backup_split((char *)lp->data, &filename, &hash)) {
+ FREE(filename);
continue;
}
- *ptr = '\0';
- ptr++;
- /* now str points to the filename and ptr points to the md5 hash */
- if(strcmp(file, str) == 0) {
- char *hash = strdup(ptr);
- FREE(str);
+ if(strcmp(file, filename) == 0) {
+ FREE(filename);
return(hash);
}
- FREE(str);
+ FREE(filename);
+ FREE(hash);
}
return(NULL);
diff --git a/lib/libalpm/backup.h b/lib/libalpm/backup.h
index 8723abaf..04b7b9a3 100644
--- a/lib/libalpm/backup.h
+++ b/lib/libalpm/backup.h
@@ -23,6 +23,8 @@
#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);
#endif /* _ALPM_BACKUP_H */