update: redesigning ctx functions and structure
This commit is contained in:
@ -34,13 +34,11 @@ bool lm_database_files_foreach(lm_database_t *db, lm_pkg_t *pkg, lm_database_fil
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(getline(&line, 0, files) > 0){
|
||||
line_len = strlen(line);
|
||||
char path[line_len+1];
|
||||
|
||||
while((line_len = getline(&line, 0, files)) > 0){
|
||||
if(HASH_LEN >= line_len)
|
||||
continue;
|
||||
|
||||
char path[line_len+1];
|
||||
memcpy(path, line+HASH_LEN+1, line_len-HASH_LEN);
|
||||
memcpy(hash, line, HASH_LEN+1);
|
||||
hash[HASH_LEN] = 0;
|
||||
@ -102,13 +100,13 @@ end:
|
||||
}
|
||||
|
||||
bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash){
|
||||
if(NULL == db || NULL == pkg || NULL == path || NULL == hash){
|
||||
if(NULL == db || NULL == pkg || NULL == path){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
// zero out the hash
|
||||
bzero(hash, HASH_LEN+1);
|
||||
if(NULL != hash)
|
||||
bzero(hash, HASH_LEN+1); // zero out the hash
|
||||
|
||||
char files_list[strlen(db->dir)+strlen(pkg->name)+10];
|
||||
join_multiple(files_list, db->dir, pkg->name, "files");
|
||||
@ -119,8 +117,8 @@ bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *h
|
||||
}
|
||||
|
||||
FILE *files = fopen(files_list, "r");
|
||||
char *line = NULL;
|
||||
size_t line_len = 0;
|
||||
char *line = NULL;
|
||||
bool ret = false;
|
||||
|
||||
if(NULL == files){
|
||||
@ -128,18 +126,18 @@ bool lm_database_files_get(lm_database_t *db, lm_pkg_t *pkg, char *path, char *h
|
||||
goto end;
|
||||
}
|
||||
|
||||
while(getline(&line, 0, files) > 0){
|
||||
line_len = strlen(line);
|
||||
char lpath[line_len+1];
|
||||
|
||||
while((line_len = getline(&line, 0, files)) > 0){
|
||||
if(HASH_LEN >= line_len)
|
||||
continue;
|
||||
|
||||
char lpath[line_len+1];
|
||||
memcpy(lpath, line+HASH_LEN+1, line_len-HASH_LEN);
|
||||
|
||||
if(eq(lpath, path)){
|
||||
memcpy(hash, line, HASH_LEN+1);
|
||||
hash[HASH_LEN] = 0;
|
||||
if(NULL != hash){
|
||||
memcpy(hash, line, HASH_LEN+1);
|
||||
hash[HASH_LEN] = 0;
|
||||
}
|
||||
ret = true;
|
||||
goto end;
|
||||
}
|
||||
|
Reference in New Issue
Block a user