new: custom pool dirs and remove ctx path functions
This commit is contained in:
@ -9,8 +9,8 @@
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
|
||||
bool lm_pool_list_load(lm_pool_t *pool){
|
||||
if(NULL == pool){
|
||||
bool lm_pool_list_load(lm_pool_t *pool, char *dir){
|
||||
if(NULL == pool || NULL == dir){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
}
|
||||
@ -27,27 +27,27 @@ bool lm_pool_list_load(lm_pool_t *pool){
|
||||
return false;
|
||||
}
|
||||
|
||||
pdebug(__func__, "(%s) extracting pool to %s", pool->name, pool->list_dir);
|
||||
pdebug(__func__, "(%s) extracting pool to %s", pool->name, dir);
|
||||
|
||||
if(!mkdir_ifnot(pool->dir)){
|
||||
lm_error_set(LM_ERR_PoolBadDir);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!mkdir_ifnot(pool->list_dir)){
|
||||
lm_error_set(LM_ERR_PoolBadPaths);
|
||||
if(!mkdir_ifnot(dir)){
|
||||
lm_error_set(LM_ERR_PoolListBadDir);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t ent_len = 0, list_dir_len = strlen(pool->list_dir);
|
||||
size_t ent_len = 0, list_dir_len = strlen(dir);
|
||||
struct dirent *ent = NULL;
|
||||
DIR *dirfd = NULL;
|
||||
bool ret = false;
|
||||
|
||||
if(!extract_archive(pool->list_dir, pool->list_file))
|
||||
if(!extract_archive(dir, pool->list_file))
|
||||
goto end;
|
||||
|
||||
if((dirfd = opendir(pool->list_dir)) == NULL){
|
||||
if((dirfd = opendir(dir)) == NULL){
|
||||
lm_error_set(LM_ERR_PoolListDirFail);
|
||||
goto end;
|
||||
}
|
||||
@ -58,7 +58,7 @@ bool lm_pool_list_load(lm_pool_t *pool){
|
||||
|
||||
ent_len = strlen(ent->d_name);
|
||||
char datap[ent_len+list_dir_len+10];
|
||||
join_multiple(datap, pool->list_dir, ent->d_name, "DATA");
|
||||
join_multiple(datap, dir, ent->d_name, "DATA");
|
||||
|
||||
lm_pkg_t *pkg = lm_package_new();
|
||||
|
||||
@ -85,8 +85,8 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback, void *data) {
|
||||
if(NULL == pool){
|
||||
bool lm_pool_list_download(lm_pool_t *pool, char *dir, lm_mptp_transfer_callback_t callback, void *data) {
|
||||
if(NULL == pool || NULL == dir){
|
||||
lm_error_set(LM_ERR_ArgNULL);
|
||||
return false;
|
||||
}
|
||||
@ -106,11 +106,6 @@ bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!mkdir_ifnot(pool->list_dir)){
|
||||
lm_error_set(LM_ERR_PoolBadPaths);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(NULL == pool->url.path || NULL == pool->url.host){
|
||||
lm_error_set(LM_ERR_PoolUrlEmpty);
|
||||
return false;
|
||||
@ -137,7 +132,7 @@ bool lm_pool_list_download(lm_pool_t *pool, lm_mptp_transfer_callback_t callback
|
||||
end:
|
||||
lm_mptp_close(sock);
|
||||
if(ret)
|
||||
ret = lm_pool_list_load(pool);
|
||||
ret = lm_pool_list_load(pool, dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,10 @@
|
||||
|
||||
bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
||||
free(pool->dir);
|
||||
free(pool->list_dir);
|
||||
free(pool->info_file);
|
||||
free(pool->list_file);
|
||||
|
||||
pool->dir = NULL;
|
||||
pool->list_dir = NULL;
|
||||
pool->info_file = NULL;
|
||||
pool->list_file = NULL;
|
||||
|
||||
@ -27,7 +25,6 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
||||
pool->dir = strdup(dir);
|
||||
pool->info_file = join_alloc(dir, "INFO");
|
||||
pool->list_file = join_alloc(dir, "LIST");
|
||||
pool->list_dir = join_alloc(dir, "LIST_extracted");
|
||||
|
||||
if(exists(pool->info_file) && (!is_file(pool->info_file) || !can_read(pool->info_file) || !can_write(pool->info_file))){
|
||||
lm_error_set(LM_ERR_PoolBadPaths);
|
||||
@ -38,11 +35,6 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
||||
lm_error_set(LM_ERR_PoolBadPaths);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(exists(pool->list_dir) && (is_file(pool->list_dir) || !can_read(pool->list_dir) || !can_write(pool->list_dir))){
|
||||
lm_error_set(LM_ERR_PoolBadPaths);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -50,6 +42,5 @@ bool lm_pool_path_set_dir(lm_pool_t *pool, char *dir){
|
||||
bool lm_pool_path_is_empty(lm_pool_t *pool){
|
||||
return NULL == pool->info_file ||
|
||||
NULL == pool->list_file ||
|
||||
NULL == pool->list_dir ||
|
||||
NULL == pool->dir;
|
||||
}
|
||||
|
@ -66,11 +66,12 @@ end:
|
||||
|
||||
void lm_pool_free(lm_pool_t *pool) {
|
||||
free(pool->dir);
|
||||
free(pool->list_dir);
|
||||
free(pool->info_file);
|
||||
free(pool->list_file);
|
||||
|
||||
lm_url_free(&pool->url);
|
||||
lm_pool_info_free(pool);
|
||||
lm_pool_list_free(pool);
|
||||
|
||||
free(pool);
|
||||
}
|
||||
|
Reference in New Issue
Block a user